From 3423c0c44df24783b2efc89fcbd53d3de4d92a8e Mon Sep 17 00:00:00 2001 From: Adam Shimali Date: Thu, 23 Jun 2016 15:21:03 +0100 Subject: [PATCH] Added subject for email templates --- app/schemas.py | 2 ++ tests/app/notifications/test_rest.py | 37 +++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/schemas.py b/app/schemas.py index ca1e2fb13..bd45dca22 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -274,6 +274,8 @@ class NotificationStatusSchema(BaseSchema): in_data.pop('personalisation', None) else: in_data['body'] = in_data['template']['content'] + if in_data['template']['template_type'] == 'email': + in_data['subject'] = in_data['template']['subject'] in_data['template'].pop('content', None) in_data['template'].pop('subject', None) return in_data diff --git a/tests/app/notifications/test_rest.py b/tests/app/notifications/test_rest.py index 41694789d..3890da134 100644 --- a/tests/app/notifications/test_rest.py +++ b/tests/app/notifications/test_rest.py @@ -13,7 +13,7 @@ from tests.app.conftest import sample_job as create_sample_job from tests.app.conftest import sample_service as create_sample_service -def test_get_notification_by_id(notify_api, sample_notification): +def test_get_sms_notification_by_id(notify_api, sample_notification): with notify_api.test_request_context(): with notify_api.test_client() as client: auth_header = create_authorization_header(service_id=sample_notification.service_id) @@ -36,6 +36,41 @@ def test_get_notification_by_id(notify_api, sample_notification): assert notification['service'] == str(sample_notification.service_id) assert response.status_code == 200 assert notification['body'] == "This is a template" # sample_template.content + assert not notification.get('subject') + + +def test_get_email_notification_by_id(notify_api, notify_db, notify_db_session, sample_email_template): + + email_notification = create_sample_notification(notify_db, + notify_db_session, + service=sample_email_template.service, + template=sample_email_template) + + with notify_api.test_request_context(): + with notify_api.test_client() as client: + auth_header = create_authorization_header(service_id=email_notification.service_id) + + response = client.get( + '/notifications/{}'.format(email_notification.id), + headers=[auth_header]) + + notification = json.loads(response.get_data(as_text=True))['data']['notification'] + + assert notification['status'] == 'sending' + assert notification['template'] == { + 'id': str(email_notification.template.id), + 'name': email_notification.template.name, + 'template_type': email_notification.template.template_type} + assert notification['job'] == { + 'id': str(email_notification.job.id), + 'original_file_name': email_notification.job.original_file_name + } + + assert notification['to'] == '+447700900855' + assert notification['service'] == str(email_notification.service_id) + assert response.status_code == 200 + assert notification['body'] == sample_email_template.content + assert notification['subject'] == sample_email_template.subject def test_get_notifications_empty_result(notify_api, sample_api_key):