Skip to content

Commit

Permalink
Merge pull request #101 from communitiesuk/bau/direct-govuk-notify-ca…
Browse files Browse the repository at this point in the history
…lls-4

Send "application deadline reminder" email synchronously
  • Loading branch information
samuelhwilliams authored Jan 6, 2025
2 parents ad92dcf + de933ff commit 4b90500
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 166 deletions.
70 changes: 0 additions & 70 deletions application_store/external_services/models/notification.py

This file was deleted.

25 changes: 15 additions & 10 deletions application_store/scripts/send_application_reminder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
import sys

from services.notify import get_notification_service

sys.path.insert(1, ".")

from datetime import datetime # noqa: E402
Expand All @@ -14,9 +16,6 @@
from application_store.external_services.exceptions import (
NotificationError, # noqa: E402
)
from application_store.external_services.models.notification import (
Notification, # noqa: E402
)
from config import Config # noqa: E402


Expand All @@ -39,7 +38,7 @@ def application_deadline_reminder(flask_app): # noqa:C901 from before ruff
if not reminder_date_str:
current_app.logger.info(
"No reminder is set for the round {round_title}",
extra=round.get("title"),
extra=dict(round_title=round.get("title")),
)
continue

Expand Down Expand Up @@ -92,14 +91,20 @@ def application_deadline_reminder(flask_app): # noqa:C901 from before ruff
)

try:
message_id = Notification.send(
template_type=Config.NOTIFY_TEMPLATE_APPLICATION_DEADLINE_REMINDER, # noqa: E501
to_email=email.get("email"),
content=application,
notification = get_notification_service().send_application_deadline_reminder_email(
email.get("email"),
fund_name=application["application"]["fund_name"],
application_reference=application["application"]["reference"],
round_name=application["application"]["round_name"],
deadline=application["application"]["deadline_date"],
contact_help_email=application["application"]["contact_help_email"],
)
current_app.logger.info(
"Message added to the queue msg_id: [{message_id}]",
extra=dict(message_id=message_id),
"Sent notification {notification_id} for application {application_reference}",
extra=dict(
notification_id=notification.id,
application_reference=application["application"]["reference"],
),
)
if len(unique_application_email_addresses) == count:
try:
Expand Down
23 changes: 23 additions & 0 deletions services/notify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,29 @@ def send_incomplete_application_email(
email_reply_to_id=self.REPLY_TO_EMAILS_WITH_NOTIFY_ID.get(contact_help_email),
)

def send_application_deadline_reminder_email(
self,
email_address: str,
fund_name: str,
application_reference: str,
round_name: str,
deadline: str,
contact_help_email: str,
govuk_notify_reference: str | None = None,
) -> Notification:
return self._send_email(
email_address,
self.APPLICATION_DEADLINE_REMINDER_TEMPLATE_ID,
personalisation={
"name of fund": fund_name,
"application reference": application_reference,
"round name": round_name,
"application deadline": deadline,
},
govuk_notify_reference=govuk_notify_reference,
email_reply_to_id=self.REPLY_TO_EMAILS_WITH_NOTIFY_ID.get(contact_help_email),
)


def get_notification_service() -> NotificationService:
return current_app.extensions["notification_service"]
86 changes: 0 additions & 86 deletions tests/application_store_tests/test_notification.py

This file was deleted.

35 changes: 35 additions & 0 deletions tests/test_services/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,38 @@ def test_send_submit_application_email(self, app):
)
assert resp == Notification(id=uuid.UUID("00000000-0000-0000-0000-000000000003"))
assert request_matcher.call_count == 1

@responses.activate
def test_send_application_deadline_reminder_email(self, app):
request_matcher = responses.post(
url="https://api.notifications.service.gov.uk/v2/notifications/email",
status=201,
match=[
matchers.json_params_matcher(
{
"email_address": "[email protected]",
"template_id": "e41cc73d-6947-4cbb-aedd-4ab2f470a2d2",
"personalisation": {
"name of fund": "test fund",
"application reference": "app-123",
"round name": "test round",
"application deadline": "2025-01-01T10:00:00",
},
"reference": "abc123",
}
)
],
json={"id": "00000000-0000-0000-0000-000000000005"}, # partial GOV.UK Notify response
)

resp = get_notification_service().send_application_deadline_reminder_email(
"[email protected]",
fund_name="test fund",
application_reference="app-123",
round_name="test round",
deadline="2025-01-01T10:00:00",
contact_help_email="[email protected]",
govuk_notify_reference="abc123",
)
assert resp == Notification(id=uuid.UUID("00000000-0000-0000-0000-000000000005"))
assert request_matcher.call_count == 1

0 comments on commit 4b90500

Please sign in to comment.