Skip to content

Commit

Permalink
[ADD] Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edescalona committed Dec 24, 2024
1 parent 06da664 commit cf7f6d2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion website_recaptcha_v2_form/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def web_login(self, redirect=None, **kw):
return super().web_login(redirect, **kw)


class BinhexAuthSignupHome(AuthSignupHome):
class RecaptchaAuthSignupHome(AuthSignupHome):
@http.route(
"/web/reset_password", type="http", auth="public", website=True, sitemap=False
)
Expand Down
34 changes: 34 additions & 0 deletions website_recaptcha_v2_form/tests/test_controller_form.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import json
from unittest import mock

from odoo import http
from odoo.http import Response
from odoo.tests import new_test_user
from odoo.tests.common import HttpCase

from odoo.addons.web.controllers.home import SIGN_UP_REQUEST_PARAMS
from odoo.addons.website_recaptcha_v2_form.controllers.form import WebsiteRecaptchaForm
from odoo.addons.website_recaptcha_v2_form.controllers.main import (
RecaptchaAuthSignupHome,
)

addons_controller = "odoo.addons.website_recaptcha_v2_form.controllers"

patch_signup = addons_controller + ".main.RecaptchaAuthSignupHome.web_auth_signup"


class TestControllerForm(HttpCase):
Expand Down Expand Up @@ -58,3 +68,27 @@ def test_recaptcha_enabled_reset_password_login_signup(self):
SIGN_UP_REQUEST_PARAMS.add("confirm_password")
response = self.test_url_open(url="/web/login", data=data)
self.assertEqual(response.status_code, 200)

@mock.patch(
"odoo.addons.website_recaptcha_v2_form.controllers.form.WebsiteForm.website_form"
)
def test_success_form(self, mock_super_website_form):
mock_super_website_form.return_value = Response("Success")

form_controller = WebsiteRecaptchaForm()
response = form_controller.website_form(
model_name="res.partner",
recaptcha_enabled=False,
**{"test_key": "test_value"},
)
self.assertEqual(response.status_code, 200)

@mock.patch(patch_signup)
def test_recaptcha_disabled(self, mock_super_website_form):
mock_super_website_form.return_value = "Not boolean"
form_controller = RecaptchaAuthSignupHome()
response = form_controller.web_auth_signup(
*{},
**{},
)
self.assertEqual(response, "Not boolean")

0 comments on commit cf7f6d2

Please sign in to comment.