mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Merge pull request #120 from alphagov/template-personalisation-fix
Fix bug where sending messages failed
This commit is contained in:
@@ -69,7 +69,8 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
|
|||||||
template = Template(
|
template = Template(
|
||||||
dao_get_template_by_id(notification['template']).__dict__,
|
dao_get_template_by_id(notification['template']).__dict__,
|
||||||
values=notification.get('personalisation', {}),
|
values=notification.get('personalisation', {}),
|
||||||
prefix=service.name
|
prefix=service.name,
|
||||||
|
drop_values={first_column_heading['sms']}
|
||||||
)
|
)
|
||||||
|
|
||||||
client = firetext_client
|
client = firetext_client
|
||||||
@@ -111,7 +112,8 @@ def send_email(service_id, notification_id, subject, from_address, encrypted_not
|
|||||||
notification = encryption.decrypt(encrypted_notification)
|
notification = encryption.decrypt(encrypted_notification)
|
||||||
template = Template(
|
template = Template(
|
||||||
dao_get_template_by_id(notification['template']).__dict__,
|
dao_get_template_by_id(notification['template']).__dict__,
|
||||||
values=notification.get('personalisation', {})
|
values=notification.get('personalisation', {}),
|
||||||
|
drop_values={first_column_heading['email']}
|
||||||
)
|
)
|
||||||
|
|
||||||
client = aws_ses_client
|
client = aws_ses_client
|
||||||
|
|||||||
@@ -118,6 +118,27 @@ def test_should_send_template_to_correct_sms_provider_and_persist(sample_templat
|
|||||||
assert not persisted_notification.job_id
|
assert not persisted_notification.job_id
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_send_sms_without_personalisation(sample_template, mocker):
|
||||||
|
notification = {
|
||||||
|
"template": sample_template.id,
|
||||||
|
"to": "+441234123123"
|
||||||
|
}
|
||||||
|
mocker.patch('app.encryption.decrypt', return_value=notification)
|
||||||
|
mocker.patch('app.firetext_client.send_sms')
|
||||||
|
mocker.patch('app.firetext_client.get_name', return_value="firetext")
|
||||||
|
|
||||||
|
notification_id = uuid.uuid4()
|
||||||
|
now = datetime.utcnow()
|
||||||
|
send_sms(
|
||||||
|
sample_template.service_id,
|
||||||
|
notification_id,
|
||||||
|
"encrypted-in-reality",
|
||||||
|
now
|
||||||
|
)
|
||||||
|
|
||||||
|
firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: This is a template")
|
||||||
|
|
||||||
|
|
||||||
def test_should_send_template_to_correct_sms_provider_and_persist_with_job_id(sample_job, mocker):
|
def test_should_send_template_to_correct_sms_provider_and_persist_with_job_id(sample_job, mocker):
|
||||||
notification = {
|
notification = {
|
||||||
"template": sample_job.template.id,
|
"template": sample_job.template.id,
|
||||||
@@ -186,6 +207,34 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh
|
|||||||
assert persisted_notification.sent_by == 'ses'
|
assert persisted_notification.sent_by == 'ses'
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_use_email_template_and_persist_without_personalisation(
|
||||||
|
sample_email_template, mocker
|
||||||
|
):
|
||||||
|
mocker.patch('app.encryption.decrypt', return_value={
|
||||||
|
"template": sample_email_template.id,
|
||||||
|
"to": "my_email@my_email.com",
|
||||||
|
})
|
||||||
|
mocker.patch('app.aws_ses_client.send_email')
|
||||||
|
mocker.patch('app.aws_ses_client.get_name', return_value='ses')
|
||||||
|
|
||||||
|
notification_id = uuid.uuid4()
|
||||||
|
now = datetime.utcnow()
|
||||||
|
send_email(
|
||||||
|
sample_email_template.service_id,
|
||||||
|
notification_id,
|
||||||
|
'subject',
|
||||||
|
'email_from',
|
||||||
|
"encrypted-in-reality",
|
||||||
|
now)
|
||||||
|
|
||||||
|
aws_ses_client.send_email.assert_called_once_with(
|
||||||
|
"email_from",
|
||||||
|
"my_email@my_email.com",
|
||||||
|
"subject",
|
||||||
|
"This is a template"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_should_persist_notification_as_failed_if_sms_client_fails(sample_template, mocker):
|
def test_should_persist_notification_as_failed_if_sms_client_fails(sample_template, mocker):
|
||||||
notification = {
|
notification = {
|
||||||
"template": sample_template.id,
|
"template": sample_template.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user