From aa12c885515be7f479e678db5600f0e291a398e8 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 8 Jul 2016 11:02:19 +0100 Subject: [PATCH] Add a test for sending email to provider MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We had a test like this for sending sms, but not email. This meant that, for example, we weren’t checking that the provider was getting passed the HTML and plain text versions of the email. --- tests/app/celery/test_provider_tasks.py | 51 +++++++++++++++++-- tests/app/conftest.py | 2 +- .../rest/test_send_notification.py | 2 +- tests/app/notifications/test_rest.py | 2 +- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/tests/app/celery/test_provider_tasks.py b/tests/app/celery/test_provider_tasks.py index e3d000c17..2bf0a1902 100644 --- a/tests/app/celery/test_provider_tasks.py +++ b/tests/app/celery/test_provider_tasks.py @@ -80,10 +80,11 @@ def test_should_return_highest_priority_active_provider(notify_db, notify_db_ses def test_should_send_personalised_template_to_correct_sms_provider_and_persist( - notify_db, - notify_db_session, - sample_template_with_placeholders, - mocker): + notify_db, + notify_db_session, + sample_template_with_placeholders, + mocker +): db_notification = sample_notification(notify_db, notify_db_session, template=sample_template_with_placeholders, to_field="+447234123123", personalisation={"name": "Jo"}, status='created') @@ -114,6 +115,48 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist( assert notification.personalisation == {"name": "Jo"} +def test_should_send_personalised_template_to_correct_email_provider_and_persist( + notify_db, + notify_db_session, + sample_email_template_with_placeholders, + mocker +): + db_notification = sample_notification( + notify_db=notify_db, notify_db_session=notify_db_session, + template=sample_email_template_with_placeholders, + to_field="jo.smith@example.com", + personalisation={'name': 'Jo'} + ) + + mocker.patch('app.aws_ses_client.send_email', return_value='reference') + mocker.patch('app.aws_ses_client.get_name', return_value="ses") + mocker.patch('app.statsd_client.incr') + mocker.patch('app.statsd_client.timing_with_dates') + mocker.patch('app.statsd_client.timing') + + send_email_to_provider( + db_notification.service_id, + db_notification.id + ) + + app.aws_ses_client.send_email.assert_called_once_with( + '"Sample service" ', + 'jo.smith@example.com', + 'Jo', + body='Hello Jo\nThis is an email from GOV.\u200bUK', + html_body=ANY, + reply_to_address=None + ) + assert '