diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 1af2b1967..d7cb2da23 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -2,6 +2,7 @@ from app import create_uuid from app import notify_celery, encryption, firetext_client, aws_ses_client from app.clients.email.aws_ses import AwsSesClientException from app.clients.sms.firetext import FiretextClientException +from app.dao.services_dao import dao_fetch_service_by_id from app.dao.templates_dao import dao_get_template_by_id from app.dao.notifications_dao import dao_create_notification, dao_update_notification from app.dao.jobs_dao import dao_update_job, dao_get_job_by_id @@ -64,9 +65,11 @@ def process_job(job_id): @notify_celery.task(name="send-sms") def send_sms(service_id, notification_id, encrypted_notification, created_at): notification = encryption.decrypt(encrypted_notification) + service = dao_fetch_service_by_id(service_id) template = Template( - dao_get_template_by_id(notification['template']), - values=notification.get('personalisation', {}) + dao_get_template_by_id(notification['template']).__dict__, + values=notification.get('personalisation', {}), + prefix=service.name ) client = firetext_client @@ -107,7 +110,7 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at): def send_email(service_id, notification_id, subject, from_address, encrypted_notification, created_at): notification = encryption.decrypt(encrypted_notification) template = Template( - dao_get_template_by_id(notification['template']), + dao_get_template_by_id(notification['template']).__dict__, values=notification.get('personalisation', {}) ) diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py index 565d8a8ae..661c09f78 100644 --- a/tests/app/celery/test_tasks.py +++ b/tests/app/celery/test_tasks.py @@ -104,7 +104,7 @@ def test_should_send_template_to_correct_sms_provider_and_persist(sample_templat now ) - firetext_client.send_sms.assert_called_once_with("+441234123123", "Hello Jo") + firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: Hello Jo") persisted_notification = notifications_dao.get_notification( sample_template_with_placeholders.service_id, notification_id ) @@ -136,7 +136,7 @@ def test_should_send_template_to_correct_sms_provider_and_persist_with_job_id(sa "encrypted-in-reality", now) - firetext_client.send_sms.assert_called_once_with("+441234123123", sample_job.template.content) + firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: This is a template") persisted_notification = notifications_dao.get_notification(sample_job.template.service_id, notification_id) assert persisted_notification.id == notification_id assert persisted_notification.to == '+441234123123' @@ -174,7 +174,9 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh "subject", "Hello Jo" ) - persisted_notification = notifications_dao.get_notification(sample_email_template_with_placeholders.service_id, notification_id) + persisted_notification = notifications_dao.get_notification( + sample_email_template_with_placeholders.service_id, notification_id + ) assert persisted_notification.id == notification_id assert persisted_notification.to == 'my_email@my_email.com' assert persisted_notification.template_id == sample_email_template_with_placeholders.id @@ -202,7 +204,7 @@ def test_should_persist_notification_as_failed_if_sms_client_fails(sample_templa "encrypted-in-reality", now) - firetext_client.send_sms.assert_called_once_with("+441234123123", sample_template.content) + firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: This is a template") persisted_notification = notifications_dao.get_notification(sample_template.service_id, notification_id) assert persisted_notification.id == notification_id assert persisted_notification.to == '+441234123123' diff --git a/tests/app/notifications/test_rest.py b/tests/app/notifications/test_rest.py index 66fb9ce3c..650cd85ec 100644 --- a/tests/app/notifications/test_rest.py +++ b/tests/app/notifications/test_rest.py @@ -328,6 +328,7 @@ def test_send_notification_invalid_template_id(notify_api, sample_template, mock test_string = 'Template {} not found for service {}'.format(9999, sample_template.service.id) assert test_string in json_resp['message']['template'] + @freeze_time("2016-01-01 11:09:00.061258") def test_send_notification_with_placeholders_replaced(notify_api, sample_template_with_placeholders, mocker): with notify_api.test_request_context():