-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Initialize a dataset to be used in the tests
- Loading branch information
Showing
1 changed file
with
12 additions
and
2 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import ckan.plugins.toolkit as tk | ||
import mock | ||
from ckan import plugins as p | ||
from ckan.tests import helpers | ||
from ckanext.subscribe.email_verification import ( | ||
get_verification_email_vars, | ||
) | ||
|
@@ -21,21 +22,30 @@ | |
class TestSubscriptionEmails(OgdchFunctionalTestBase): | ||
def setup(self): | ||
tk.config["ckanext.subscribe.apply_recaptcha"] = "true" | ||
# Ensure the database is reset before each test | ||
helpers.reset_db() | ||
|
||
def teardown(self): | ||
tk.config["ckanext.subscribe.apply_recaptcha"] = "false" | ||
|
||
# Mock the _verify_recaptcha function | ||
@mock.patch("requests.post") | ||
@mock.patch("ckanext.subscribe.email_verification.send_request_email") | ||
@mock.patch("ckanext.subscribe.action._verify_recaptcha") | ||
def test_get_email_vars_with_subscription(self, mock_verify_recaptcha, mock_post): | ||
def test_get_email_vars_with_subscription( | ||
self, mock_verify_recaptcha, send_request_email, mock_post | ||
): | ||
# Mocking the reCAPTCHA verification to return True | ||
mock_verify_recaptcha.return_value = True | ||
mock_post.return_value = mock.Mock( | ||
status_code=200, json=lambda: {"success": True} | ||
) | ||
|
||
dataset = factories.Dataset() | ||
|
||
# Create a subscription with a valid reCAPTCHA response | ||
subscription = factories.Subscription( | ||
dataset_id=self.dataset['id'], | ||
dataset_id=dataset['id'], | ||
email='[email protected]', | ||
g_recaptcha_response='valid-recaptcha-response', | ||
return_object=True | ||
|