From c9f1eb65a74e2703a2d0ba61b58e6c05dfd439f1 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 13 Jun 2016 14:09:03 +0100 Subject: [PATCH] Build the from address in the task instead of the rest call. --- app/celery/tasks.py | 3 +++ app/notifications/rest.py | 2 +- tests/app/notifications/test_rest.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index d3ccbdfc4..ceaf7c240 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -343,6 +343,9 @@ def send_email(service_id, notification_id, from_address, encrypted_notification (provider.get_name(), str(reference), notification['to']), queue='research-mode' ) else: + # First step setting the from_address here rather than the method creating the task + from_address = '"{}" <{}@{}>'.format(service.name, service.email_from, current_app.config[ + 'NOTIFY_EMAIL_DOMAIN']) if from_address == "" else from_address reference = provider.send_email( from_address, notification['to'], diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 3b7541354..a98cff336 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -387,7 +387,7 @@ def send_notification(notification_type): send_email.apply_async(( service_id, notification_id, - '"{}" <{}@{}>'.format(service.name, service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN']), + '', encryption.encrypt(notification), datetime.utcnow().strftime(DATETIME_FORMAT) ), queue='email') diff --git a/tests/app/notifications/test_rest.py b/tests/app/notifications/test_rest.py index 7c12f6e17..0853e66f5 100644 --- a/tests/app/notifications/test_rest.py +++ b/tests/app/notifications/test_rest.py @@ -946,7 +946,7 @@ def test_should_allow_valid_email_notification(notify_api, sample_email_template app.celery.tasks.send_email.apply_async.assert_called_once_with( (str(sample_email_template.service_id), notification_id, - "\"Sample service\" ", + "", "something_encrypted", "2016-01-01T11:09:00.061258"), queue="email"