Skip to content

Commit

Permalink
fix: Initialize a dataset to be used in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kovalch committed Jul 4, 2024
1 parent e156c8e commit 310c0ba
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ckanext/switzerland/tests/test_subscription_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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
Expand Down

0 comments on commit 310c0ba

Please sign in to comment.