Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grants email voucher copy update #3717

Merged
merged 21 commits into from
Feb 14, 2024
Merged
17 changes: 16 additions & 1 deletion backend/api/cms/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
StreamFieldFactory,
SiteFactory,
)
from wagtail.models import Site
import factory
from decimal import Decimal
from pytest_factoryboy import register
from wagtail.rich_text import RichText


register(SiteFactory)
register(PageFactory)


Expand Down Expand Up @@ -92,3 +92,18 @@ class GenericPageFactory(PageFactory):

class Meta:
model = GenericPage


@register
class SiteFactory(SiteFactory):
"""
Overrides wagtail_factories.SiteFactory to use "testserver" as hostname
to make sure it works with Wagtail's ALLOWED_HOSTS in test environments.
"""

hostname = "testserver"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave this anyway as this fixture is more specifc aka links the GenericPage as root_pag and use testserver as hostname that is the allowed hosts configured by wagtail in the tests I discovered.

root_page = factory.SubFactory(GenericPageFactory)
is_default_site = True

class Meta:
model = Site
1 change: 0 additions & 1 deletion backend/api/conferences/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ class Conference:
map: Optional[Map] = strawberry.field(resolver=resolve_map)

pretix_event_url: str
visa_application_form_link: str

@strawberry.field
def voucher(self, info, code: str) -> Optional[Voucher]:
Expand Down
1 change: 0 additions & 1 deletion backend/conferences/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class ConferenceAdmin(OrderedInlineModelAdminMixin, admin.ModelAdmin):
"topics",
"audience_levels",
"languages",
"visa_application_form_link",
)
},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.7 on 2024-02-13 13:46

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("conferences", "0040_conference_visa_application_form_link"),
]

operations = [
migrations.RemoveField(
model_name="conference",
name="visa_application_form_link",
),
]
4 changes: 0 additions & 4 deletions backend/conferences/models/conference.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ class Conference(GeoLocalizedModel, TimeFramedModel, TimeStampedModel):
default=None,
)

visa_application_form_link = models.URLField(
_("Visa application form link"), blank=True, default=""
)

youtube_video_bottom_text = models.TextField(
default="",
blank=True,
Expand Down
1 change: 0 additions & 1 deletion backend/conferences/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class ConferenceFactory(DjangoModelFactory):

pretix_organizer_id = "base-pretix-organizer-id"
pretix_event_id = "base-pretix-event-id"
visa_application_form_link = factory.Faker("url")

@classmethod
def _create(cls, model_class, *args, **kwargs):
Expand Down
10 changes: 0 additions & 10 deletions backend/grants/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,6 @@ def wrapper(modeladmin, request, queryset):
@admin.action(description="Send Approved/Waiting List/Rejected reply emails")
@validate_single_conference_selection
def send_reply_emails(modeladmin, request, queryset):
conference = queryset.first().conference

if not conference.visa_application_form_link:
messages.error(
request,
"Visa Application Form Link Missing: Please ensure the link to the Visa "
"Application Form is set in the Conference admin settings.",
)
return

queryset = queryset.filter(
status__in=(
Grant.Status.approved,
Expand Down
10 changes: 3 additions & 7 deletions backend/grants/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,14 @@ def send_grant_reply_approved_email(*, grant_id, is_reminder):
"Reminder: Financial Aid Update" if is_reminder else "Financial Aid Update"
)

if not grant.conference.visa_application_form_link:
raise ValueError(
"Visa Application Form Link Missing: Please ensure the link to the Visa "
"Application Form is set in the Conference admin settings."
)

template = EmailTemplate.GRANT_APPROVED
variables = {
"replyLink": reply_url,
"startDate": f"{grant.conference.start:%-d %B}",
"endDate": f"{grant.conference.end+timedelta(days=1):%-d %B}",
"deadlineDateTime": f"{grant.applicant_reply_deadline:%-d %B %Y %H:%M %Z}",
"deadlineDate": f"{grant.applicant_reply_deadline:%-d %B %Y}",
"visaApplicationFormLink": grant.conference.visa_application_form_link,
"visaPageLink": urljoin(settings.FRONTEND_URL, "/visa"),
"hasApprovedTravel": grant.has_approved_travel(),
"hasApprovedAccommodation": grant.has_approved_accommodation(),
}
Expand Down Expand Up @@ -151,6 +145,8 @@ def send_grant_voucher_email(*, grant_id):
variables={
"firstname": get_name(user, "there"),
"voucherCode": voucher_code,
"hasApprovedAccommodation": grant.has_approved_accommodation(),
"visaPageLink": urljoin(settings.FRONTEND_URL, "/visa"),
},
reply_to=[
"grants@pycon.it",
Expand Down
11 changes: 7 additions & 4 deletions backend/grants/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
)
from grants.models import Grant


pytestmark = pytest.mark.django_db


def test_send_reply_emails_with_grants_from_multiple_conferences(
rf, grant_factory, mocker, conference_factory
rf,
grant_factory,
mocker,
conference_factory,
):
"""
Test that sending reply emails does not proceed when selected grants belong
Expand Down Expand Up @@ -79,7 +83,6 @@ def test_send_reply_emails_approved_missing_amount(rf, grant_factory, mocker):
status=Grant.Status.approved,
approved_type=Grant.ApprovedType.ticket_accommodation,
total_amount=None,
conference__visa_application_form_link="https://forms.com/visa",
)
grant.total_amount = None
grant.save()
Expand All @@ -105,7 +108,6 @@ def test_send_reply_emails_approved_set_deadline_in_fourteen_days(
status=Grant.Status.approved,
approved_type=Grant.ApprovedType.ticket_accommodation,
total_amount=800,
conference__visa_application_form_link="https://forms.com/visa",
)
request = rf.get("/")
mock_send_approved_email = mocker.patch(
Expand Down Expand Up @@ -201,9 +203,10 @@ def test_send_voucher_via_email(
pretix_voucher_id=2345,
voucher_code="GRANT-532VCT",
)
request = rf.get("/")

send_voucher_via_email(
None, rf.get("/"), queryset=Grant.objects.filter(conference=conference)
None, request, queryset=Grant.objects.filter(conference=conference)
)

mock_send_email.delay.assert_has_calls(
Expand Down
44 changes: 8 additions & 36 deletions backend/grants/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


def test_send_grant_voucher_email(settings, grant_factory):
settings.FRONTEND_URL = "https://pycon.it"
user = UserFactory(
full_name="Marco Acierno",
email="marco@placeholder.it",
Expand All @@ -33,6 +34,7 @@ def test_send_grant_voucher_email(settings, grant_factory):
grant = grant_factory(
user=user,
voucher_code="ABC123",
approved_type=Grant.ApprovedType.ticket_only,
)

with patch("grants.tasks.send_email") as email_mock:
Expand All @@ -45,6 +47,8 @@ def test_send_grant_voucher_email(settings, grant_factory):
variables={
"firstname": "Marco Acierno",
"voucherCode": "ABC123",
"hasApprovedAccommodation": False,
"visaPageLink": "https://pycon.it/visa",
},
reply_to=["grants@pycon.it"],
)
Expand Down Expand Up @@ -118,7 +122,6 @@ def test_handle_grant_reply_sent_reminder(conference_factory, grant_factory, set
conference = conference_factory(
start=datetime(2023, 5, 2, tzinfo=timezone.utc),
end=datetime(2023, 5, 5, tzinfo=timezone.utc),
visa_application_form_link="https://example.com/visa-application-form",
)
user = UserFactory(
full_name="Marco Acierno",
Expand Down Expand Up @@ -149,7 +152,7 @@ def test_handle_grant_reply_sent_reminder(conference_factory, grant_factory, set
"deadlineDateTime": "1 February 2023 23:59 UTC",
"deadlineDate": "1 February 2023",
"replyLink": "https://pycon.it/grants/reply/",
"visaApplicationFormLink": "https://example.com/visa-application-form",
"visaPageLink": "https://pycon.it/visa",
"hasApprovedTravel": False,
"hasApprovedAccommodation": False,
},
Expand All @@ -165,7 +168,6 @@ def test_handle_grant_approved_ticket_travel_accommodation_reply_sent(
conference = conference_factory(
start=datetime(2023, 5, 2, tzinfo=timezone.utc),
end=datetime(2023, 5, 5, tzinfo=timezone.utc),
visa_application_form_link="https://example.com/visa-application-form",
)
user = UserFactory(
full_name="Marco Acierno",
Expand Down Expand Up @@ -198,7 +200,7 @@ def test_handle_grant_approved_ticket_travel_accommodation_reply_sent(
"deadlineDateTime": "1 February 2023 23:59 UTC",
"deadlineDate": "1 February 2023",
"replyLink": "https://pycon.it/grants/reply/",
"visaApplicationFormLink": "https://example.com/visa-application-form",
"visaPageLink": "https://pycon.it/visa",
"hasApprovedTravel": True,
"hasApprovedAccommodation": True,
},
Expand All @@ -214,7 +216,6 @@ def test_handle_grant_approved_ticket_travel_accommodation_fails_with_no_amount(
conference = conference_factory(
start=datetime(2023, 5, 2, tzinfo=timezone.utc),
end=datetime(2023, 5, 5, tzinfo=timezone.utc),
visa_application_form_link="https://example.com/visa-application-form",
)
user = UserFactory(
full_name="Marco Acierno",
Expand All @@ -237,33 +238,6 @@ def test_handle_grant_approved_ticket_travel_accommodation_fails_with_no_amount(
send_grant_reply_approved_email(grant_id=grant.id, is_reminder=False)


def test_handle_grant_approved_ticket_fails_with_no_visa_application_form_link(
conference_factory, grant_factory, settings
):
settings.FRONTEND_URL = "https://pycon.it"

conference = conference_factory(
start=datetime(2023, 5, 2, tzinfo=timezone.utc),
end=datetime(2023, 5, 5, tzinfo=timezone.utc),
visa_application_form_link="",
)
user = UserFactory()
grant = grant_factory(
conference=conference,
approved_type=Grant.ApprovedType.ticket_travel_accommodation,
applicant_reply_deadline=datetime(2023, 2, 1, 23, 59, tzinfo=timezone.utc),
travel_amount=0,
user=user,
)

with pytest.raises(
ValueError,
match="Visa Application Form Link Missing: Please ensure the link to the Visa "
"Application Form is set in the Conference admin settings.",
):
send_grant_reply_approved_email(grant_id=grant.id, is_reminder=False)


def test_handle_grant_approved_ticket_only_reply_sent(
conference_factory, grant_factory, settings
):
Expand All @@ -272,7 +246,6 @@ def test_handle_grant_approved_ticket_only_reply_sent(
conference = conference_factory(
start=datetime(2023, 5, 2, tzinfo=timezone.utc),
end=datetime(2023, 5, 5, tzinfo=timezone.utc),
visa_application_form_link="https://example.com/visa-application-form",
)
user = UserFactory(
full_name="Marco Acierno",
Expand Down Expand Up @@ -304,7 +277,7 @@ def test_handle_grant_approved_ticket_only_reply_sent(
"deadlineDateTime": "1 February 2023 23:59 UTC",
"deadlineDate": "1 February 2023",
"replyLink": "https://pycon.it/grants/reply/",
"visaApplicationFormLink": "https://example.com/visa-application-form",
"visaPageLink": "https://pycon.it/visa",
"hasApprovedTravel": False,
"hasApprovedAccommodation": False,
},
Expand All @@ -320,7 +293,6 @@ def test_handle_grant_approved_travel_reply_sent(
conference = conference_factory(
start=datetime(2023, 5, 2, tzinfo=timezone.utc),
end=datetime(2023, 5, 5, tzinfo=timezone.utc),
visa_application_form_link="https://example.com/visa-application-form",
)
user = UserFactory(
full_name="Marco Acierno",
Expand Down Expand Up @@ -353,7 +325,7 @@ def test_handle_grant_approved_travel_reply_sent(
"deadlineDateTime": "1 February 2023 23:59 UTC",
"deadlineDate": "1 February 2023",
"replyLink": "https://pycon.it/grants/reply/",
"visaApplicationFormLink": "https://example.com/visa-application-form",
"visaPageLink": "https://pycon.it/visa",
"hasApprovedTravel": True,
"hasApprovedAccommodation": False,
"amount": "400",
Expand Down
Loading
Loading