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 7cc7019 commit d05d32f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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 @@ -78,7 +78,7 @@ def web_auth_signup(self, *args, **kw):
qcontext = self.get_auth_signup_qcontext()
if request.httprequest.method == "POST":
valid = self.verify_recaptcha_v2(
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
16 changes: 13 additions & 3 deletions website_recaptcha_v2_form/tests/test_controller_form.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import json
from unittest import mock

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

imp_requests = "odoo.addons.website_recaptcha_v2_form.models.website.requests"


class TestControllerForm(HttpCase):
def test_url_open(self, data=None, url="/website/form/res.partner"):
Expand All @@ -18,6 +21,10 @@ def test_url_open(self, data=None, url="/website/form/res.partner"):
)
return res

def authenticate_enable(self):
new_test_user(self.env, login="test_user", password="Password!1")
self.authenticate("test_user", "Password!1")

def test_recaptcha_enabled_form(self):
response = self.test_url_open()
response_recaptcha_invalid = json.loads(response.content.decode("utf-8"))
Expand All @@ -31,9 +38,9 @@ def test_recaptcha_enabled_form(self):
)
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")
@mock.patch(imp_requests)
def test_recaptcha_enabled_reset_password_login_signup(self, requests_mock):
self.authenticate_enable()
data = {
"csrf_token": http.Request.csrf_token(self),
"g-recaptcha-response": "recaptcha_invalid",
Expand All @@ -49,3 +56,6 @@ def test_recaptcha_enabled_reset_password_login_signup(self):
)
response = self.test_url_open(url="/web/login", data=data)
self.assertEqual(response.status_code, 200)

response_signup = self.test_url_open(url="/web/signup", data=data)
self.assertEqual(response_signup.status_code, 200)

0 comments on commit d05d32f

Please sign in to comment.