Skip to content

Commit

Permalink
# This is a combination of 4 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

[IMP] Add tests

# This is the commit message #2:

[IMP] Add tests

# This is the commit message #3:

[FIX] Tests

# This is the commit message #4:

[FIX] Tests

[ADD] Tests

[FIX] Tests

[FIX] Tests

[ADD] Tests

[ADD] Tests

[FIX] Tests

[ADD] Tests

[ADD] Tests

[REM] Tests

[ADD] Tests

[ADD] Tests

[ADD] Tests
  • Loading branch information
edescalona committed Dec 24, 2024
1 parent 34ab7a1 commit e07469c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
4 changes: 2 additions & 2 deletions 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 All @@ -78,7 +78,7 @@ def web_auth_signup(self, *args, **kw):
qcontext = self.get_auth_signup_qcontext()

Check warning on line 78 in website_recaptcha_v2_form/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_recaptcha_v2_form/controllers/main.py#L78

Added line #L78 was not covered by tests
if request.httprequest.method == "POST":
valid = self.verify_recaptcha_v2(

Check warning on line 80 in website_recaptcha_v2_form/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_recaptcha_v2_form/controllers/main.py#L80

Added line #L80 was not covered by tests
kw=kw, template="auth_signup.signup", values=qcontext, args=args
template="auth_signup.signup", values=qcontext
)
if not isinstance(valid, bool):
return valid
Expand Down
50 changes: 46 additions & 4 deletions website_recaptcha_v2_form/tests/test_controller_form.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
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):
def test_url_open(self, data=None, url="/website/form/res.partner"):
Expand Down Expand Up @@ -31,22 +43,52 @@ def test_recaptcha_enabled_form(self):
)
self.assertEqual(response_recaptcha_not_enable.status_code, 200)

response_recaptcha_not_enable = self.test_url_open(data={})
self.assertEqual(response_recaptcha_not_enable.status_code, 200)

def test_recaptcha_enabled_reset_password_login_signup(self):
new_test_user(self.env, login="test_user", password="Password!1")
self.authenticate("test_user", "Password!1")
new_test_user(self.env, login="test_user_form", password="Password!1")
self.authenticate("test_user_form", "Password!1")
data = {
"csrf_token": http.Request.csrf_token(self),
"g-recaptcha-response": "recaptcha_invalid",
}

response_reset = self.test_url_open(url="/web/reset_password", data=data)
self.assertEqual(response_reset.status_code, 200)

data.update(
{
"login": "test_user",
"login": "test_user_form",
"password": "Password!1",
}
)
response = self.test_url_open(url="/web/login", data=data)
self.assertEqual(response.status_code, 200)

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")
2 changes: 2 additions & 0 deletions website_recaptcha_v2_form/tests/test_recaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def test_valid_recaptcha_v2_site_key(self):
"test-site",
msg="The website key for recaptcha is empty.",
)
recaptcha_v2_site_key = self.website.get_recaptcha_v2_site_key()
self.assertNotEqual(recaptcha_v2_site_key, "")

def test_valid_recaptcha_v2_recaptcha_v2_secret_key(self):
recaptcha_v2_secret_key = self.website.recaptcha_v2_secret_key
Expand Down

0 comments on commit e07469c

Please sign in to comment.