Prefix all SMS messages with service name

Implements https://github.com/alphagov/notifications-utils/pull/4
This commit is contained in:
Chris Hill-Scott
2016-03-01 08:48:27 +00:00
parent fa4b2e16e7
commit 0e5d72494e
3 changed files with 13 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ from app import create_uuid
from app import notify_celery, encryption, firetext_client, aws_ses_client from app import notify_celery, encryption, firetext_client, aws_ses_client
from app.clients.email.aws_ses import AwsSesClientException from app.clients.email.aws_ses import AwsSesClientException
from app.clients.sms.firetext import FiretextClientException 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.templates_dao import dao_get_template_by_id
from app.dao.notifications_dao import dao_create_notification, dao_update_notification 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 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") @notify_celery.task(name="send-sms")
def send_sms(service_id, notification_id, encrypted_notification, created_at): def send_sms(service_id, notification_id, encrypted_notification, created_at):
notification = encryption.decrypt(encrypted_notification) notification = encryption.decrypt(encrypted_notification)
service = dao_fetch_service_by_id(service_id)
template = Template( template = Template(
dao_get_template_by_id(notification['template']), dao_get_template_by_id(notification['template']).__dict__,
values=notification.get('personalisation', {}) values=notification.get('personalisation', {}),
prefix=service.name
) )
client = firetext_client 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): def send_email(service_id, notification_id, subject, from_address, encrypted_notification, created_at):
notification = encryption.decrypt(encrypted_notification) notification = encryption.decrypt(encrypted_notification)
template = Template( template = Template(
dao_get_template_by_id(notification['template']), dao_get_template_by_id(notification['template']).__dict__,
values=notification.get('personalisation', {}) values=notification.get('personalisation', {})
) )

View File

@@ -104,7 +104,7 @@ def test_should_send_template_to_correct_sms_provider_and_persist(sample_templat
now 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( persisted_notification = notifications_dao.get_notification(
sample_template_with_placeholders.service_id, notification_id 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", "encrypted-in-reality",
now) 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) persisted_notification = notifications_dao.get_notification(sample_job.template.service_id, notification_id)
assert persisted_notification.id == notification_id assert persisted_notification.id == notification_id
assert persisted_notification.to == '+441234123123' assert persisted_notification.to == '+441234123123'
@@ -174,7 +174,9 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh
"subject", "subject",
"Hello Jo" "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.id == notification_id
assert persisted_notification.to == 'my_email@my_email.com' assert persisted_notification.to == 'my_email@my_email.com'
assert persisted_notification.template_id == sample_email_template_with_placeholders.id 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", "encrypted-in-reality",
now) 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) persisted_notification = notifications_dao.get_notification(sample_template.service_id, notification_id)
assert persisted_notification.id == notification_id assert persisted_notification.id == notification_id
assert persisted_notification.to == '+441234123123' assert persisted_notification.to == '+441234123123'

View File

@@ -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) test_string = 'Template {} not found for service {}'.format(9999, sample_template.service.id)
assert test_string in json_resp['message']['template'] assert test_string in json_resp['message']['template']
@freeze_time("2016-01-01 11:09:00.061258") @freeze_time("2016-01-01 11:09:00.061258")
def test_send_notification_with_placeholders_replaced(notify_api, sample_template_with_placeholders, mocker): def test_send_notification_with_placeholders_replaced(notify_api, sample_template_with_placeholders, mocker):
with notify_api.test_request_context(): with notify_api.test_request_context():