|
8 | 8 | except ImportError: |
9 | 9 | from unittest.mock import patch |
10 | 10 |
|
| 11 | +from odoo.exceptions import UserError |
11 | 12 | from odoo.tests.common import HttpCase |
12 | 13 | from odoo.tools.misc import mute_logger |
13 | 14 |
|
@@ -51,3 +52,38 @@ def test_good_email(self): |
51 | 52 | self.data["login"] = "contributors@odoo-community.org" |
52 | 53 | doc = self.html_doc(data=self.data) |
53 | 54 | self.assertTrue(doc.xpath('//p[@class="alert alert-success"]')) |
| 55 | + |
| 56 | + @mute_logger("odoo.addons.auth_signup_verify_email.controllers.main") |
| 57 | + def test_good_email_with_captcha_fields(self): |
| 58 | + """Test acceptance when captcha fields are present in POST data.""" |
| 59 | + self.data["login"] = "contributors@odoo-community.org" |
| 60 | + self.data["turnstile_captcha"] = "dummy-turnstile-token" |
| 61 | + self.data["recaptcha_token_response"] = "dummy-recaptcha-token" |
| 62 | + doc = self.html_doc(data=self.data) |
| 63 | + self.assertTrue(doc.xpath('//p[@class="alert alert-success"]')) |
| 64 | + |
| 65 | + @mute_logger("odoo.addons.auth_signup_verify_email.controllers.main") |
| 66 | + def test_captcha_verification_error(self): |
| 67 | + """Test rejection when captcha verification raises an error.""" |
| 68 | + self.data["login"] = "contributors@odoo-community.org" |
| 69 | + with patch.object( |
| 70 | + type(self.env["ir.http"]), |
| 71 | + "_verify_request_recaptcha_token", |
| 72 | + side_effect=UserError("Captcha failed"), |
| 73 | + create=True, |
| 74 | + ): |
| 75 | + doc = self.html_doc(data=self.data) |
| 76 | + self.assertTrue(doc.xpath('//p[@class="alert alert-danger"]')) |
| 77 | + |
| 78 | + @mute_logger("odoo.addons.auth_signup_verify_email.controllers.main") |
| 79 | + def test_captcha_verification_false(self): |
| 80 | + """Test rejection when captcha verification returns False.""" |
| 81 | + self.data["login"] = "contributors@odoo-community.org" |
| 82 | + with patch.object( |
| 83 | + type(self.env["ir.http"]), |
| 84 | + "_verify_request_recaptcha_token", |
| 85 | + return_value=False, |
| 86 | + create=True, |
| 87 | + ): |
| 88 | + doc = self.html_doc(data=self.data) |
| 89 | + self.assertTrue(doc.xpath('//p[@class="alert alert-danger"]')) |
0 commit comments