Skip to content

Commit

Permalink
[IMP] Add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edescalona committed Dec 6, 2024
1 parent 959c4d8 commit a566524
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions website_recaptcha_v2_form/tests/test_controller_form.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json

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

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


class TestControllerForm(HttpCase):
def open_url_form(self, data=None, url="/website/form/res.partner"):
def test_url_open(self, data=None, url="/website/form/res.partner"):
if not data:
data = {
"recaptcha_enabled": True,
Expand All @@ -19,10 +21,30 @@ def open_url_form(self, data=None, url="/website/form/res.partner"):
return res

def test_recaptcha_enabled_form(self):
res = self.open_url_form()
recaptcha_not_response = json.loads(res.content.decode("utf-8"))
response = self.test_url_open()
response_recaptcha_invalid = json.loads(response.content.decode("utf-8"))
self.assertEqual(
recaptcha_not_response.get("error"),
response_recaptcha_invalid.get("error"),
"No response given.",
msg=recaptcha_not_response.get("error"),
msg=response_recaptcha_invalid.get("error"),
)
response_recaptcha_not_enable = self.test_url_open(
data={"recaptcha_enabled": False}
)
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")
data = {
"csrf_token": http.Request.csrf_token(self),
"g-recaptcha-response": "recaptcha_invalid",
}
response = self.test_url_open(url="/web/login", data=data)
self.assertEqual(response.status_code, 200)

response_reset = self.test_url_open(url="/web/reset_password", data=data)
self.assertEqual(response_reset.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 a566524

Please sign in to comment.