Skip to content

Commit

Permalink
Merge pull request #15 from torchbox-forks/fix/tests
Browse files Browse the repository at this point in the history
Fix/tests
  • Loading branch information
katdom13 committed Nov 24, 2023
2 parents d95461e + 3ee61dc commit c23696f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from __future__ import absolute_import, unicode_literals

try:
from test.support import EnvironmentVarGuard # Python < 3.10
except ImportError:
from test.support.os_helper import EnvironmentVarGuard # Python >= 3.10
from unittest import mock

from django.test import TestCase
from home.forms import CustomCaptchaFormBuilder
Expand All @@ -21,11 +18,18 @@ class CaptchaTestingModeMixin(TestCase):
"""Allow Captcha to pass regardless of the value provided"""

def setUp(self):
self.captcha_testing_mode_env = EnvironmentVarGuard()
self.captcha_testing_mode_env.set("RECAPTCHA_TESTING", "True")
# Use unittest.mock.patch to set the environment variable
self.captcha_testing_mode_patch = mock.patch.dict(
"os.environ", {"RECAPTCHA_TESTING": "True"}
)
self.captcha_testing_mode_patch.start()

self.captcha_form_data = {"recaptcha_response_field": "PASSED"}

def tearDown(self):
# Clean up the patch after the test
self.captcha_testing_mode_patch.stop()


class TestCaptchaEmailFormPageTestCase(CaptchaTestingModeMixin, TestCase):
fixtures = ["test_data.json"]
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

INSTALLED_APPS = wagtail_apps + [
"home",
"captcha",
"django_recaptcha",
"wagtailcaptcha",
"modelcluster",
"taggit",
Expand Down

0 comments on commit c23696f

Please sign in to comment.