summaryrefslogtreecommitdiff
path: root/fundraising
diff options
context:
space:
mode:
authorBaptiste Mispelon <bmispelon@gmail.com>2024-02-20 19:07:46 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2024-02-23 06:12:39 +0100
commit317942547daa054eb1fa8095d3a8d959eb00fcec (patch)
tree0fd9edff57fab2266ef92a907ce0938b546f6ceb /fundraising
parent84781734386841ef2edbba4bf1f78efd005244e5 (diff)
Upgraded django-recaptcha to 4.0.0.
Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
Diffstat (limited to 'fundraising')
-rw-r--r--fundraising/forms.py9
-rw-r--r--fundraising/tests/test_forms.py13
-rw-r--r--fundraising/tests/test_views.py5
3 files changed, 19 insertions, 8 deletions
diff --git a/fundraising/forms.py b/fundraising/forms.py
index 915f1059..a0d72622 100644
--- a/fundraising/forms.py
+++ b/fundraising/forms.py
@@ -1,8 +1,8 @@
import stripe
-from captcha.fields import ReCaptchaField
-from captcha.widgets import ReCaptchaV3
from django import forms
from django.utils.safestring import mark_safe
+from django_recaptcha.fields import ReCaptchaField
+from django_recaptcha.widgets import ReCaptchaV3
from .models import INTERVAL_CHOICES, LEADERSHIP_LEVEL_AMOUNT, DjangoHero, Donation
@@ -134,7 +134,7 @@ class DonateForm(forms.Form):
amount = forms.ChoiceField(choices=AMOUNT_CHOICES)
interval = forms.ChoiceField(choices=INTERVAL_CHOICES)
- captcha = ReCaptchaField(widget=ReCaptchaV3)
+ captcha = ReCaptchaField(widget=ReCaptchaV3(action="form"))
class DonationForm(forms.ModelForm):
@@ -176,7 +176,8 @@ class PaymentForm(forms.Form):
`amount` can be any integer, so a ChoiceField is not appropriate.
"""
- captcha = ReCaptchaField(widget=ReCaptchaV3)
+ # NOTE: `action` needs to match the one used in stripe-donation.js
+ captcha = ReCaptchaField(widget=ReCaptchaV3(action="form"))
amount = forms.IntegerField(
required=True,
min_value=1, # Minimum payment from Stripe API
diff --git a/fundraising/tests/test_forms.py b/fundraising/tests/test_forms.py
index d2bc28a8..baa588e7 100644
--- a/fundraising/tests/test_forms.py
+++ b/fundraising/tests/test_forms.py
@@ -1,10 +1,15 @@
+from unittest.mock import patch
+
from django.test import TestCase
+from django_recaptcha.client import RecaptchaResponse
from ..forms import PaymentForm
class TestPaymentForm(TestCase):
- def test_basics(self):
+ @patch("django_recaptcha.fields.client.submit")
+ def test_basics(self, client_submit):
+ client_submit.return_value = RecaptchaResponse(is_valid=True, action="form")
form = PaymentForm(
data={
"amount": 100,
@@ -12,9 +17,11 @@ class TestPaymentForm(TestCase):
"captcha": "TESTING",
}
)
- self.assertTrue(form.is_valid())
+ self.assertTrue(form.is_valid(), form.errors)
- def test_max_value_validation(self):
+ @patch("django_recaptcha.fields.client.submit")
+ def test_max_value_validation(self, client_submit):
+ client_submit.return_value = RecaptchaResponse(is_valid=True, action="form")
"""
Reject unrealistic values greater than $1,000,000.
"""
diff --git a/fundraising/tests/test_views.py b/fundraising/tests/test_views.py
index 7ffdaab6..74a923d0 100644
--- a/fundraising/tests/test_views.py
+++ b/fundraising/tests/test_views.py
@@ -9,6 +9,7 @@ from django.test import TestCase
from django.test.utils import override_settings
from django.urls import reverse
from django_hosts.resolvers import reverse as django_hosts_reverse
+from django_recaptcha.client import RecaptchaResponse
from ..models import DjangoHero, Donation
@@ -59,8 +60,10 @@ class TestCampaign(TestCase):
self.assertFalse(content["success"])
@patch("stripe.checkout.Session.create")
- def test_submitting_donation_form_valid(self, session_create):
+ @patch("django_recaptcha.fields.client.submit")
+ def test_submitting_donation_form_valid(self, client_submit, session_create):
session_create.return_value = {"id": "TEST_ID"}
+ client_submit.return_value = RecaptchaResponse(is_valid=True, action="form")
response = self.client.post(
reverse("fundraising:donation-session"),
{