From cb17ab554dbfbf17db86aa3244a1c89f011f63a4 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Sat, 21 Oct 2023 13:51:35 +0300 Subject: [PATCH] Remove donations app --- donations/__init__.py | 0 donations/apps.py | 5 - donations/forms.py | 22 -- donations/migrations/0001_initial.py | 218 --------------- ...r_donatepage_suggested_donation_amounts.py | 224 --------------- ...r_donatepage_suggested_donation_amounts.py | 51 ---- .../0003_alter_donoraddress_country.py | 17 -- .../migrations/0004_donation_comments.py | 19 -- donations/migrations/__init__.py | 0 donations/models.py | 208 -------------- .../templates/donations/donate_page.html | 258 ------------------ donations/tests.py | 171 ------------ donations/wagtail_hooks.py | 55 ---- 13 files changed, 1248 deletions(-) delete mode 100644 donations/__init__.py delete mode 100644 donations/apps.py delete mode 100644 donations/forms.py delete mode 100644 donations/migrations/0001_initial.py delete mode 100644 donations/migrations/0001_squashed_0002_alter_donatepage_suggested_donation_amounts.py delete mode 100644 donations/migrations/0002_alter_donatepage_suggested_donation_amounts.py delete mode 100644 donations/migrations/0003_alter_donoraddress_country.py delete mode 100644 donations/migrations/0004_donation_comments.py delete mode 100644 donations/migrations/__init__.py delete mode 100644 donations/models.py delete mode 100644 donations/templates/donations/donate_page.html delete mode 100644 donations/tests.py delete mode 100644 donations/wagtail_hooks.py diff --git a/donations/__init__.py b/donations/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/donations/apps.py b/donations/apps.py deleted file mode 100644 index 1183d0036..000000000 --- a/donations/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class DonationsConfig(AppConfig): - name = "donations" diff --git a/donations/forms.py b/donations/forms.py deleted file mode 100644 index a1ad80d57..000000000 --- a/donations/forms.py +++ /dev/null @@ -1,22 +0,0 @@ -from django import forms - -from .models import Donation, DonorAddress - - -class DonationForm(forms.ModelForm): - class Meta: - model = Donation - fields = [ - "amount", - "donor_given_name", - "donor_family_name", - "donor_email", - "recurrence", - "comments", - ] - - -class DonorAddressForm(forms.ModelForm): - class Meta: - model = DonorAddress - exclude = ["address_type", "latitude", "longitude", "po_box_number"] diff --git a/donations/migrations/0001_initial.py b/donations/migrations/0001_initial.py deleted file mode 100644 index baf93d134..000000000 --- a/donations/migrations/0001_initial.py +++ /dev/null @@ -1,218 +0,0 @@ -# Generated by Django 3.2.12 on 2022-03-21 08:46 - -import django.db.models.deletion -import wagtail.blocks -import wagtail.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - initial = True - - dependencies = [ - ("wagtailcore", "0066_collection_management_permissions"), - ] - - operations = [ - migrations.CreateModel( - name="DonatePage", - fields=[ - ( - "page_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to="wagtailcore.page", - ), - ), - ("intro", wagtail.fields.RichTextField(blank=True)), - ( - "suggested_donation_amounts", - wagtail.fields.StreamField( - [ - ( - "suggested_donation_amounts", - wagtail.blocks.StructBlock( - [ - ( - "once", - wagtail.blocks.ListBlock( - wagtail.blocks.IntegerBlock( - label="Amount", - ), - ), - ), - ( - "monthly", - wagtail.blocks.ListBlock( - wagtail.blocks.IntegerBlock( - label="Amount", - ), - ), - ), - ( - "yearly", - wagtail.blocks.ListBlock( - wagtail.blocks.IntegerBlock( - label="Amount", - ), - ), - ), - ], - max_num=1, - ), - ), - ], - blank=True, - null=True, - ), - ), - ], - options={ - "abstract": False, - }, - bases=("wagtailcore.page",), - ), - migrations.CreateModel( - name="DonorAddress", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "street_address", - models.CharField(blank=True, default="", max_length=255), - ), - ( - "extended_address", - models.CharField(blank=True, default="", max_length=255), - ), - ( - "po_box_number", - models.CharField( - blank=True, - default="", - help_text="P.O. Box, if relevant", - max_length=32, - ), - ), - ( - "locality", - models.CharField( - blank=True, - help_text="Locality or city", - max_length=255, - null=True, - ), - ), - ( - "region", - models.CharField( - blank=True, - default="", - help_text="State or region", - max_length=255, - ), - ), - ( - "postal_code", - models.CharField( - blank=True, - help_text="Postal code (or zipcode)", - max_length=16, - null=True, - ), - ), - ( - "country", - models.CharField( - blank=True, - default="United States", - max_length=255, - null=True, - ), - ), - ( - "address_type", - models.CharField( - choices=[("mailing", "Mailing"), ("worship", "Worship")], - max_length=255, - ), - ), - ("latitude", models.FloatField(blank=True, null=True)), - ("longitude", models.FloatField(blank=True, null=True)), - ], - options={ - "abstract": False, - }, - ), - migrations.CreateModel( - name="Donation", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("amount", models.IntegerField()), - ( - "recurrence", - models.CharField( - blank=True, - choices=[ - ("once", "Once"), - ("monthly", "Monthly"), - ("yearly", "Yearly"), - ], - default="once", - max_length=255, - null=True, - ), - ), - ("donor_given_name", models.CharField(max_length=255)), - ("donor_family_name", models.CharField(max_length=255)), - ( - "donor_organization", - models.CharField(blank=True, max_length=255, null=True), - ), - ( - "donor_email", - models.EmailField( - help_text="Please enter your email", - max_length=254, - ), - ), - ("paid", models.BooleanField(default=False)), - ( - "braintree_transaction_id", - models.CharField(blank=True, max_length=255, null=True), - ), - ( - "braintree_subscription_id", - models.CharField(blank=True, max_length=255, null=True), - ), - ( - "donor_address", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="donations.donoraddress", - ), - ), - ], - ), - ] diff --git a/donations/migrations/0001_squashed_0002_alter_donatepage_suggested_donation_amounts.py b/donations/migrations/0001_squashed_0002_alter_donatepage_suggested_donation_amounts.py deleted file mode 100644 index 326f0b682..000000000 --- a/donations/migrations/0001_squashed_0002_alter_donatepage_suggested_donation_amounts.py +++ /dev/null @@ -1,224 +0,0 @@ -# Generated by Django 4.2.1 on 2023-05-24 05:59 - -from django.db import migrations, models -import django.db.models.deletion -import wagtail.blocks -import wagtail.fields - - -class Migration(migrations.Migration): - replaces = [ - ("donations", "0001_initial"), - ("donations", "0002_alter_donatepage_suggested_donation_amounts"), - ] - - initial = True - - dependencies = [ - ("wagtailcore", "0066_collection_management_permissions"), - ] - - operations = [ - migrations.CreateModel( - name="DonorAddress", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "street_address", - models.CharField(blank=True, default="", max_length=255), - ), - ( - "extended_address", - models.CharField(blank=True, default="", max_length=255), - ), - ( - "po_box_number", - models.CharField( - blank=True, - default="", - help_text="P.O. Box, if relevant", - max_length=32, - ), - ), - ( - "locality", - models.CharField( - blank=True, - help_text="Locality or city", - max_length=255, - null=True, - ), - ), - ( - "region", - models.CharField( - blank=True, - default="", - help_text="State or region", - max_length=255, - ), - ), - ( - "postal_code", - models.CharField( - blank=True, - help_text="Postal code (or zipcode)", - max_length=16, - null=True, - ), - ), - ( - "country", - models.CharField( - blank=True, - default="United States", - max_length=255, - null=True, - ), - ), - ( - "address_type", - models.CharField( - choices=[("mailing", "Mailing"), ("worship", "Worship")], - max_length=255, - ), - ), - ("latitude", models.FloatField(blank=True, null=True)), - ("longitude", models.FloatField(blank=True, null=True)), - ], - options={ - "abstract": False, - }, - ), - migrations.CreateModel( - name="Donation", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("amount", models.IntegerField()), - ( - "recurrence", - models.CharField( - blank=True, - choices=[ - ("once", "Once"), - ("monthly", "Monthly"), - ("yearly", "Yearly"), - ], - default="once", - max_length=255, - null=True, - ), - ), - ("donor_given_name", models.CharField(max_length=255)), - ("donor_family_name", models.CharField(max_length=255)), - ( - "donor_organization", - models.CharField(blank=True, max_length=255, null=True), - ), - ( - "donor_email", - models.EmailField( - help_text="Please enter your email", - max_length=254, - ), - ), - ("paid", models.BooleanField(default=False)), - ( - "braintree_transaction_id", - models.CharField(blank=True, max_length=255, null=True), - ), - ( - "braintree_subscription_id", - models.CharField(blank=True, max_length=255, null=True), - ), - ( - "donor_address", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="donations.donoraddress", - ), - ), - ], - ), - migrations.CreateModel( - name="DonatePage", - fields=[ - ( - "page_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to="wagtailcore.page", - ), - ), - ("intro", wagtail.fields.RichTextField(blank=True)), - ( - "suggested_donation_amounts", - wagtail.fields.StreamField( - [ - ( - "suggested_donation_amounts", - wagtail.blocks.StructBlock( - [ - ( - "once", - wagtail.blocks.ListBlock( - wagtail.blocks.IntegerBlock( - label="Amount", - ), - ), - ), - ( - "monthly", - wagtail.blocks.ListBlock( - wagtail.blocks.IntegerBlock( - label="Amount", - ), - ), - ), - ( - "yearly", - wagtail.blocks.ListBlock( - wagtail.blocks.IntegerBlock( - label="Amount", - ), - ), - ), - ], - max_num=1, - ), - ), - ], - blank=True, - null=True, - use_json_field=True, - ), - ), - ], - options={ - "abstract": False, - }, - bases=("wagtailcore.page",), - ), - ] diff --git a/donations/migrations/0002_alter_donatepage_suggested_donation_amounts.py b/donations/migrations/0002_alter_donatepage_suggested_donation_amounts.py deleted file mode 100644 index 5a56bfa54..000000000 --- a/donations/migrations/0002_alter_donatepage_suggested_donation_amounts.py +++ /dev/null @@ -1,51 +0,0 @@ -# Generated by Django 4.1.1 on 2022-10-05 15:53 - -import wagtail.blocks -import wagtail.fields -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - ("donations", "0001_initial"), - ] - - operations = [ - migrations.AlterField( - model_name="donatepage", - name="suggested_donation_amounts", - field=wagtail.fields.StreamField( - [ - ( - "suggested_donation_amounts", - wagtail.blocks.StructBlock( - [ - ( - "once", - wagtail.blocks.ListBlock( - wagtail.blocks.IntegerBlock(label="Amount"), - ), - ), - ( - "monthly", - wagtail.blocks.ListBlock( - wagtail.blocks.IntegerBlock(label="Amount"), - ), - ), - ( - "yearly", - wagtail.blocks.ListBlock( - wagtail.blocks.IntegerBlock(label="Amount"), - ), - ), - ], - max_num=1, - ), - ), - ], - blank=True, - null=True, - use_json_field=True, - ), - ), - ] diff --git a/donations/migrations/0003_alter_donoraddress_country.py b/donations/migrations/0003_alter_donoraddress_country.py deleted file mode 100644 index c6b46a789..000000000 --- a/donations/migrations/0003_alter_donoraddress_country.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 4.2.1 on 2023-06-21 10:33 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("donations", "0001_squashed_0002_alter_donatepage_suggested_donation_amounts"), - ] - - operations = [ - migrations.AlterField( - model_name="donoraddress", - name="country", - field=models.CharField(blank=True, max_length=255, null=True), - ), - ] diff --git a/donations/migrations/0004_donation_comments.py b/donations/migrations/0004_donation_comments.py deleted file mode 100644 index a706312a7..000000000 --- a/donations/migrations/0004_donation_comments.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 4.2.4 on 2023-08-05 11:27 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("donations", "0003_alter_donoraddress_country"), - ] - - operations = [ - migrations.AddField( - model_name="donation", - name="comments", - field=models.TextField( - blank=True, help_text="Comments or instructions about your payment." - ), - ), - ] diff --git a/donations/migrations/__init__.py b/donations/migrations/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/donations/models.py b/donations/models.py deleted file mode 100644 index 545d2ea82..000000000 --- a/donations/models.py +++ /dev/null @@ -1,208 +0,0 @@ -from typing import TYPE_CHECKING -from django.db import models -from django.http import HttpRequest, HttpResponse -from django.shortcuts import redirect -from django.template.response import TemplateResponse -from django.urls import reverse -from wagtail.admin.panels import FieldPanel -from wagtail.blocks import IntegerBlock, ListBlock, StreamBlock, StructBlock -from wagtail.fields import RichTextField, StreamField -from wagtail.models import Page - -from addresses.models import Address - -if TYPE_CHECKING: - from .forms import DonationForm, DonorAddressForm # pragma: no cover - - -def process_donation_forms( - donation_form: "DonationForm", - donor_address_form: "DonorAddressForm", -) -> HttpResponse: - """Process a donation form and redirect to payment.""" - # Create a temporary donation object to modify it's fields - donation = donation_form.save(commit=False) - - # Check if user submitted any address information - if donor_address_form.is_valid(): - # Create donor address instance and associate it with donation - donor_address = donor_address_form.save() - - donation.donor_address = donor_address - - # Save donation with associated address - donation.save() - - # redirect for payment - return redirect( - reverse( - "payment:process_donation_payment", - kwargs={ - "donation_id": donation.id, - }, - ), - ) - - -class SuggestedDonationAmountsBlock(StructBlock): - once = ListBlock(IntegerBlock(label="Amount")) - monthly = ListBlock(IntegerBlock(label="Amount")) - yearly = ListBlock(IntegerBlock(label="Amount")) - - -class DonatePage(Page): - intro = RichTextField(blank=True) - suggested_donation_amounts = StreamField( - StreamBlock( - [ - ( - "suggested_donation_amounts", - SuggestedDonationAmountsBlock(max_num=1), - ), - ], - max_num=1, - ), - null=True, - blank=True, - use_json_field=True, - ) - - max_count = 1 - - content_panels = Page.content_panels + [ - FieldPanel("intro"), - FieldPanel("suggested_donation_amounts"), - ] - - parent_page_types = ["home.HomePage"] - subpage_types: list[str] = [] - - def serve( - self, - request: HttpRequest, - *args: tuple, - **kwargs: dict, - ) -> HttpResponse: - # Avoid circular dependency - from .forms import DonationForm, DonorAddressForm - - donor_address_form = DonorAddressForm(request.POST) - donation_form = DonationForm(request.POST) - - if request.method == "POST" and donation_form.is_valid(): - return process_donation_forms( - donation_form, - donor_address_form, - ) - - # Send donor address form to client - # Note, we manually create the donation form in the template - context = self.get_context( - request, - *args, - **kwargs, - ) - context["donor_address_form"] = donor_address_form - - return TemplateResponse( - request, - self.get_template( - request, - *args, - **kwargs, - ), - context, - ) - - -class DonorAddress(Address): - pass - - -class Donation(models.Model): - class DonationRecurrenceChoices(models.TextChoices): - ONCE = ("once", "Once") - MONTHLY = ("monthly", "Monthly") - YEARLY = ("yearly", "Yearly") - - amount = models.IntegerField() - recurrence = models.CharField( - max_length=255, - null=True, - blank=True, - choices=DonationRecurrenceChoices.choices, - default=DonationRecurrenceChoices.ONCE, - ) - donor_given_name = models.CharField( - max_length=255, - ) - donor_family_name = models.CharField( - max_length=255, - ) - donor_organization = models.CharField( - max_length=255, - null=True, - blank=True, - ) - donor_email = models.EmailField( - help_text="Please enter your email", - ) - donor_address = models.ForeignKey( - to=DonorAddress, - null=True, - blank=True, - on_delete=models.SET_NULL, - ) - comments = models.TextField( - help_text="Comments or instructions about your payment.", - blank=True, - ) - paid = models.BooleanField(default=False) - braintree_transaction_id = models.CharField( - max_length=255, - null=True, - blank=True, - ) - braintree_subscription_id = models.CharField( - max_length=255, - null=True, - blank=True, - ) - # TODO: add date fields for created, payment_completed, updated - - def get_total_cost(self) -> int: - # Add get_total_cost method to conform to payment page - return self.amount - - @property - def recurring(self) -> bool: - """Determine whether Donation is recurring. - - Return True if Donation recurrence is "monthly" or "yearly", - otherwise False - """ - - return self.recurrence in ( - self.DonationRecurrenceChoices.MONTHLY, - self.DonationRecurrenceChoices.YEARLY, - ) - - panels = [ - FieldPanel("amount"), - FieldPanel("recurrence"), - FieldPanel("donor_given_name"), - FieldPanel("donor_family_name"), - FieldPanel("donor_organization"), - FieldPanel("donor_email"), - FieldPanel("donor_address"), - FieldPanel("comments"), - FieldPanel("paid"), - FieldPanel( - "braintree_transaction_id", - read_only=True, - ), - FieldPanel( - "braintree_subscription_id", - read_only=True, - ), - ] diff --git a/donations/templates/donations/donate_page.html b/donations/templates/donations/donate_page.html deleted file mode 100644 index 81395db56..000000000 --- a/donations/templates/donations/donate_page.html +++ /dev/null @@ -1,258 +0,0 @@ -{% extends "base.html" %} - -{% load crispy_forms_tags %} -{% load wagtailcore_tags %} - -{% block body_class %}template-donatepage{% endblock %} - -{% block content %} -

{{ page.title }}

- - {{ page.intro|richtext }} - -
-
-
-
- - Once -
-
- -
-
- - Monthly -
-
- -
-
- - Yearly -
-
- - -
- - {% if page.suggested_donation_amounts %} - - {% for suggestion in page.suggested_donation_amounts %} -
- {% for amount in suggestion.value.once %} -
-
- - ${{ amount }} -
-
- {% endfor %} -
- -
- {% for amount in suggestion.value.monthly %} -
-
- - ${{ amount }} -
-
- {% endfor %} -
- -
- {% for amount in suggestion.value.yearly %} -
-
- - ${{ amount }} -
-
- {% endfor %} -
- {% endfor %} - - -
-
- - Choose from one of the suggested donation amounts above. - -
-
- {% endif %} - -
-
-
-
- Amount $ - - -
- - - {% if page.suggested_donation_amounts %} - Optionally, enter your own donation amount. - {% else %} - Enter your donation amount. - {% endif %} - -
-
-
- - -
-
-
- Given name* - - -
- - * Required - -
- -
-
- Family name* - - -
- - * Required - -
- -
-
- - Email* - - - -
- - * Required - -
-
- -
-
- {{ donor_address_form.street_address | as_crispy_field }} -
-
- -
-
- {{ donor_address_form.extended_address | as_crispy_field }} -
-
- -
-
- {{ donor_address_form.locality | as_crispy_field }} -
-
- {{ donor_address_form.region | as_crispy_field }} -
-
- {{ donor_address_form.postal_code | as_crispy_field }} -
-
- -
-
- {{ donor_address_form.country | as_crispy_field }} -
-
- -
- - -
- - -
-
- - - - {% csrf_token %} -
-{% endblock content %} - -{% block extra_js %} - - - - -{% endblock extra_js %} diff --git a/donations/tests.py b/donations/tests.py deleted file mode 100644 index a45fa5090..000000000 --- a/donations/tests.py +++ /dev/null @@ -1,171 +0,0 @@ -from django.test import TestCase, RequestFactory -from .forms import DonationForm, DonorAddressForm -from django.urls import reverse -from .models import process_donation_forms, DonatePage, Donation -from django.http import HttpResponseRedirect -from wagtail.models import Page - - -class DonationModelTest(TestCase): - def test_donation_created(self) -> None: - # Create and save Donation object - donation = Donation(amount=100, recurrence="monthly") - donation.save() - - # Test that object attributes are equal to those set - self.assertEqual(donation.amount, 100) - self.assertEqual(donation.recurrence, "monthly") - - def test_process_donation_request_works_correctly(self) -> None: - # Create completed form objects - donation_form = DonationForm( - { - "amount": 100, - "donor_given_name": "test_given_name", - "donor_family_name": "test_family_name", - "donor_email": "test@test.com", - "recurrence": "monthly", - }, - ) - - donor_address_form = DonorAddressForm( - { - "street_address": "123 Main Street", - "extended_address": "Apartment 1A", - "locality": "Test Locality", - "region": "Test Region", - "postal_code": "12345", - "country": "Testistan", - }, - ) - - # Create response using completed form objects - response = process_donation_forms( - donation_form, - donor_address_form, - ) - - # Test that response is an HttpResponseRedirect - self.assertIsInstance(response, HttpResponseRedirect) - - # Test that the response redirects to correct URL - expected_url = reverse( - "payment:process_donation_payment", - kwargs={"donation_id": "3"}, - ) - self.assertEqual(response.url, expected_url) # type: ignore - - def test_total_cost_method(self) -> None: - # Create donation object with specified amount - donation = Donation(amount=100) - - # Test that get_total_cost returns specified amount - self.assertEqual(donation.get_total_cost(), 100) - - def test_recurring(self) -> None: - # Create donations with each recurrence possibility - donation_monthly = Donation( - amount=100, - recurrence=Donation.DonationRecurrenceChoices.MONTHLY, - ) - donation_yearly = Donation( - amount=200, - recurrence=Donation.DonationRecurrenceChoices.YEARLY, - ) - donation_once = Donation( - amount=300, - recurrence=Donation.DonationRecurrenceChoices.ONCE, - ) - - # Test that recurring() returns True for monthly and yearly donations - self.assertTrue(donation_monthly.recurring) - self.assertTrue(donation_yearly.recurring) - - # Test that recurring() returns False for once donation - self.assertFalse(donation_once.recurring) - - -class DonatePageTest(TestCase): - def setUp(self) -> None: - self.factory = RequestFactory() - self.donate_page = DonatePage( - title="Donate", - slug="donate", - path="00010001", - depth=2, - numchild=0, - ) - self.home_page = Page.objects.get(slug="home") - self.home_page.add_child(instance=self.donate_page) - - def test_serve_with_get(self) -> None: - request = self.factory.get("/donate/") - response = self.donate_page.serve(request) - - # Test that the response contains the donor_address_form in the context - self.assertIn("donor_address_form", response.context_data) - - def test_serve_with_post_with_valid_data(self) -> None: - # Create post request with DonationForm and DonorAddressForm data - request = self.factory.post( - "/donate/", - data={ - "amount": 100, - "donor_given_name": "test_given_name", - "donor_family_name": "test_family_name", - "donor_email": "test@test.com", - "recurrence": "monthly", - "street_address": "123 Main Street", - "extended_address": "Apartment 1A", - "locality": "Test Locality", - "region": "Test Region", - "postal_code": "12345", - "country": "Testistan", - }, - ) - - # Add session to the request - request.session = self.client.session - request.session.save() - - # Serve the request - response = self.donate_page.serve(request) - - # Test that the response is a redirect - self.assertEqual(response.status_code, 302) - - # Test that the redirect URL is the donate page - self.assertEqual(response.url, "/payment/process/donation/1") - - # Get donation object associated with donor address - donation = Donation.objects.get(donor_address__street_address="123 Main Street") - # Test that the retrieved donation object's donor - # address is the same as the one provided in the form - self.assertEqual(donation.donor_address.street_address, "123 Main Street") - - def test_serve_with_post_with_invalid_data(self) -> None: - # Make a POST request to the donation page with the form data - response = self.client.post( - "/donate/", - data={ - "amount": 100, - "donor_given_name": "", # Invalid donor_given_name - "donor_family_name": "test_family_name", - "donor_email": "test@test.com", - "recurrence": "monthly", - "street_address": "123 Main Street", - "extended_address": "Apartment 1A", - "locality": "Test Locality", - "region": "Test Region", - "postal_code": "12345", - "country": "Testistan", - }, - ) - - # Test that the request was successful - self.assertEqual(response.status_code, 200) - - # Try to retrieve the donation object associated with the provided donor address - # Test that it is does not exist - with self.assertRaises(Donation.DoesNotExist): - Donation.objects.get(donor_given_name="") diff --git a/donations/wagtail_hooks.py b/donations/wagtail_hooks.py deleted file mode 100644 index d2ab9d113..000000000 --- a/donations/wagtail_hooks.py +++ /dev/null @@ -1,55 +0,0 @@ -from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register - -from donations.models import Donation - - -class DonationModelAdmin(ModelAdmin): - """Donation admin.""" - - model = Donation - menu_label = "Donations" - menu_icon = "success" - menu_order = 291 - add_to_settings_menu = False - exclude_from_explorer = True - list_display = ( - "donor_given_name", - "donor_family_name", - "donor_email", - "amount", - "recurrence", - "paid", - ) - inspect_view_enabled = True - inspect_view_fields = [ - "donor_given_name", - "donor_family_name", - "donor_email", - "donor_address", - "amount", - "paid", - "braintree_transaction_id", - "braintree_subscription_id", - ] - search_fields = ( - "donor_given_name", - "donor_family_name", - "donor_email", - ) - list_filter = ( - "paid", - "recurrence", - ) - list_export = ( - "donor_given_name", - "donor_family_name", - "donor_email", - "donor_address", - "amount", - "paid", - "braintree_transaction_id", - "braintree_subscription_id", - ) - - -modeladmin_register(DonationModelAdmin)