Skip to content

Commit

Permalink
template-contents-fix/FS-3845-send-application-reminder-script-automa…
Browse files Browse the repository at this point in the history
…tion (#184)

* automation of script send_deadline_reminder: - dynamically pass the fund name, deadline date, contact help email to the Notification service

* fixed test for send deadline reminder

* removed test that are relying on api call to Notify service
  • Loading branch information
ramsharma-prog authored Jan 9, 2024
1 parent daa364e commit 16d28dd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 50 deletions.
32 changes: 23 additions & 9 deletions app/notification/application_reminder/map_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ApplicationReminder(_NotificationContents):
round_name: str
reference: str
deadline_date: str
contact_help_email: str
reply_to_email_id: str

@classmethod
def format_deadline_date(cls, date):
Expand All @@ -43,13 +45,25 @@ def from_notification(cls, notification: Notification):
current_app.logger.info(
f"Mapping contents for {notification.template_type}"
)
application_data = notification.content["application"]
return cls(
contact_info=notification.contact_info,
deadline_date=cls.format_deadline_date(
try:
application_data = notification.content["application"]
deadline_date = cls.format_deadline_date(
application_data.get("deadline_date")
),
fund_name=Config.FUND_NAME,
round_name=application_data.get("round_name"),
reference=application_data.get("reference"),
)
)
return cls(
contact_info=notification.contact_info,
deadline_date=deadline_date,
fund_name=application_data.get("fund_name"),
round_name=application_data.get("round_name"),
reference=application_data.get("reference"),
contact_help_email=application_data.get("contact_help_email"),
reply_to_email_id=Config.REPLY_TO_EMAILS_WITH_NOTIFY_ID[
application_data["contact_help_email"]
],
)

except Exception as e:
current_app.logger.error(
"Could not map the contents for"
f" {notification.template_type} {e}"
)
1 change: 1 addition & 0 deletions app/notification/model/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def send_application_reminder(
response = notifications_client.send_email_notification(
email_address=contents.contact_info,
template_id=Config.APPLICATION_DEADLINE_REMINDER_TEMPLATE_ID,
email_reply_to_id=contents.reply_to_email_id,
personalisation={
"name of fund": contents.fund_name,
"application reference": contents.reference,
Expand Down
1 change: 1 addition & 0 deletions examplar_data/application_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"round_name": "WINDOW 2 ROUND 2",
"reference": "WUHJFDWJ",
"deadline_date": "2022-05-20T14:47:12",
"contact_help_email": "[email protected]",
}
},
}
Expand Down
23 changes: 2 additions & 21 deletions tests/test_application/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def test_application_reminder_contents(app_context):
expected_json = expected_application_reminder_json
data = Notification.from_json(expected_json)
application_class_object = ApplicationReminder.from_notification(data)
fund_deadline = application_class_object.deadline_date
deadline_date = application_class_object.deadline_date

assert "20 May 2022 at 02:47pm" == fund_deadline
assert "20 May 2022 at 02:47pm" == deadline_date


def test_format_submission_date(mock_application_class_data):
Expand Down Expand Up @@ -156,22 +156,3 @@ def test_send_incomplete_application(
)

assert code == 200


@pytest.mark.parametrize(
"mock_notifications_api_client",
[2],
indirect=True,
)
def test_send_application_reminder(
app_context,
mock_notifier_api_client,
mock_notifications_api_client,
):
_, code = Notifier.send_application_reminder(
notification_class_data_for_application(
date_submitted=False, deadline_date=True
)
)

assert code == 200
20 changes: 0 additions & 20 deletions tests/test_magic_link/test_magic_link.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import pytest
from app.notification.model.notifier import Notifier
from examplar_data.magic_link_data import (
expected_magic_link_unknown_help_email,
)
from examplar_data.magic_link_data import incorrect_content_body_key
from examplar_data.magic_link_data import (
notification_class_data_for_magic_link,
Expand All @@ -26,23 +23,6 @@ def test_magic_link_contents_with_incorrect_content_key(flask_test_client):
assert response.status_code == 400


@pytest.mark.usefixtures("live_server")
def test_magic_link_contents_with_unknown_contact_email(flask_test_client):
"""
GIVEN: our service running on flask test client.
WHEN: we post unexpected magic_link_data key to the endpoint "/send".
THEN: we check if it returns status code 400.
"""

response = flask_test_client.post(
"/send",
json=expected_magic_link_unknown_help_email,
follow_redirects=True,
)

assert response.status_code == 400


@pytest.mark.usefixtures("live_server")
def test_magic_link_contents_with_none_contents(flask_test_client):
"""
Expand Down

0 comments on commit 16d28dd

Please sign in to comment.