Fix tests: mock captcha clean method

This commit is contained in:
Ludovic Stephan 2021-03-04 18:30:51 +01:00
parent 47dd078b6a
commit ac8ad15ad1

View file

@ -1,5 +1,5 @@
import json
import os
from unittest import mock
from django.contrib.auth import get_user_model
from django.test import TestCase
@ -257,18 +257,15 @@ class PetitCoursDemandeViewTestCase(ViewTestCaseMixin, TestCase):
def setUp(self):
super().setUp()
os.environ["RECAPTCHA_TESTING"] = "True"
self.subject1 = create_petitcours_subject()
self.subject2 = create_petitcours_subject()
def tearDown(self):
os.environ["RECAPTCHA_TESTING"] = "False"
def test_get(self):
resp = self.client.get(self.url)
self.assertEqual(resp.status_code, 200)
def test_post(self):
@mock.patch("hcaptcha.fields.hCaptchaField.clean")
def test_post(self, mock_clean):
data = {
"name": "Le nom",
"email": "lemail@mail.net",
@ -280,7 +277,7 @@ class PetitCoursDemandeViewTestCase(ViewTestCaseMixin, TestCase):
"agrege_requis": "1",
"niveau": "lycee",
"remarques": "no comment",
"g-recaptcha-response": "PASSED",
"h-captcha-response": 1,
}
resp = self.client.post(self.url, data)
@ -299,18 +296,15 @@ class PetitCoursDemandeRawViewTestCase(ViewTestCaseMixin, TestCase):
def setUp(self):
super().setUp()
os.environ["RECAPTCHA_TESTING"] = "True"
self.subject1 = create_petitcours_subject()
self.subject2 = create_petitcours_subject()
def tearDown(self):
os.environ["RECAPTCHA_TESTING"] = "False"
def test_get(self):
resp = self.client.get(self.url)
self.assertEqual(resp.status_code, 200)
def test_post(self):
@mock.patch("hcaptcha.fields.hCaptchaField.clean")
def test_post(self, mock_clean):
data = {
"name": "Le nom",
"email": "lemail@mail.net",
@ -322,7 +316,7 @@ class PetitCoursDemandeRawViewTestCase(ViewTestCaseMixin, TestCase):
"agrege_requis": "1",
"niveau": "lycee",
"remarques": "no comment",
"g-recaptcha-response": "PASSED",
"h-captcha-response": 1,
}
resp = self.client.post(self.url, data)