-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add additional class for recaptcha and add teardown
- Loading branch information
Showing
2 changed files
with
17 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import datetime | ||
|
||
import ckan.plugins.toolkit as tk | ||
import mock | ||
from ckan import model | ||
from ckan.plugins.toolkit import ValidationError | ||
|
@@ -223,7 +224,16 @@ def test_dataset_and_group_at_same_time(self, send_request_email): | |
|
||
assert not send_request_email.called | ||
|
||
# The reCAPTCHA tests | ||
|
||
# The reCAPTCHA tests | ||
class TestRecaptchaOfSubscribeSignup(object): | ||
def setup(self): | ||
helpers.reset_db() | ||
tk.config["ckanext.subscribe.apply_recaptcha"] = "true" | ||
|
||
def teardown(self): | ||
tk.config["ckanext.subscribe.apply_recaptcha"] = "false" | ||
|
||
# mock the _verify_recaptcha function and test both | ||
# successful and unsuccessful reCAPTCHA verification scenarios | ||
@mock.patch("requests.post") | ||
|
@@ -268,12 +278,9 @@ def test_verify_recaptcha_success( | |
) | ||
assert subscription_obj | ||
|
||
@mock.patch("requests.post") | ||
@mock.patch("ckanext.subscribe.email_verification.send_request_email") | ||
@mock.patch("ckanext.subscribe.action._verify_recaptcha") | ||
def test_verify_recaptcha_failure( | ||
self, mock_verify_recaptcha, send_request_email, mock_post | ||
): | ||
def test_verify_recaptcha_failure(self, mock_verify_recaptcha, send_request_email): | ||
# Mocking the reCAPTCHA verification to return False | ||
mock_verify_recaptcha.return_value = False | ||
|
||
|
@@ -286,16 +293,11 @@ def test_verify_recaptcha_failure( | |
{}, | ||
email="[email protected]", | ||
dataset_id=dataset["id"], | ||
g_recaptcha_response="invalid-recaptcha-response", | ||
) | ||
except ValidationError as cm: | ||
# Asserting that the error is raised due to invalid reCAPTCHA | ||
assert_in( | ||
'Invalid reCAPTCHA response: "g_recaptcha_response"', | ||
str(cm.exception.error_dict), | ||
g_recaptcha_response="wrong_recaptcha", | ||
) | ||
|
||
assert not send_request_email.called | ||
except ValidationError as e: | ||
# Asserting that the error is raised with the correct message | ||
assert "Invalid reCAPTCHA. Please try again." in str(e.error_dict) | ||
|
||
# Ensuring the email is not sent due to invalid reCAPTCHA | ||
assert not send_request_email.called | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters