mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 02:41:14 -05:00
Add a test for sending email to provider
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.
This commit is contained in:
@@ -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" <sample.service@test.notify.com>',
|
||||
'jo.smith@example.com',
|
||||
'Jo',
|
||||
body='Hello Jo\nThis is an email from GOV.\u200bUK',
|
||||
html_body=ANY,
|
||||
reply_to_address=None
|
||||
)
|
||||
assert '<!DOCTYPE html' in app.aws_ses_client.send_email.call_args[1]['html_body']
|
||||
|
||||
notification = Notification.query.filter_by(id=db_notification.id).one()
|
||||
|
||||
assert notification.status == 'sending'
|
||||
assert notification.sent_at <= datetime.utcnow()
|
||||
assert notification.sent_by == 'ses'
|
||||
assert notification.personalisation == {"name": "Jo"}
|
||||
|
||||
|
||||
def test_send_sms_should_use_template_version_from_notification_not_latest(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
|
||||
@@ -223,7 +223,7 @@ def sample_email_template_with_placeholders(notify_db, notify_db_session):
|
||||
return sample_email_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
content="Hello ((name))",
|
||||
content="Hello ((name))\nThis is an email from GOV.UK",
|
||||
subject_line="((name))")
|
||||
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ def test_send_notification_with_placeholders_replaced(notify_api, sample_email_t
|
||||
)
|
||||
assert response.status_code == 201
|
||||
assert encryption.decrypt(app.celery.tasks.send_email.apply_async.call_args[0][0][2]) == data
|
||||
assert response_data['body'] == 'Hello Jo'
|
||||
assert response_data['body'] == 'Hello Jo\nThis is an email from GOV.UK'
|
||||
assert response_data['subject'] == 'Jo'
|
||||
|
||||
|
||||
|
||||
@@ -576,7 +576,7 @@ def test_get_notification_by_id_returns_merged_template_content_for_email(
|
||||
|
||||
notification = json.loads(response.get_data(as_text=True))['data']['notification']
|
||||
assert response.status_code == 200
|
||||
assert notification['body'] == 'Hello world'
|
||||
assert notification['body'] == 'Hello world\nThis is an email from GOV.UK'
|
||||
assert notification['subject'] == 'world'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user