mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Add handling for data types other than list/string
Brings in: - [ ] https://github.com/alphagov/notifications-utils/pull/135 Also adds extra tests for: - the exact issue that we saw in production when #867 was deployed - what happens when `None` is passed as a placeholder value, because this should never get as far as the relevant bit of utils
This commit is contained in:
@@ -29,6 +29,6 @@ notifications-python-client>=3.1,<3.2
|
|||||||
awscli>=1.11,<1.12
|
awscli>=1.11,<1.12
|
||||||
awscli-cwlogs>=1.4,<1.5
|
awscli-cwlogs>=1.4,<1.5
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@14.0.1#egg=notifications-utils==14.0.1
|
git+https://github.com/alphagov/notifications-utils.git@14.0.2#egg=notifications-utils==14.0.2
|
||||||
|
|
||||||
git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3
|
git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3
|
||||||
|
|||||||
@@ -133,10 +133,39 @@ def test_send_notification_with_placeholders_replaced(notify_api, sample_email_t
|
|||||||
assert response_data['subject'] == 'Jo'
|
assert response_data['subject'] == 'Jo'
|
||||||
|
|
||||||
|
|
||||||
def test_send_notification_with_placeholders_replaced_with_list(
|
@pytest.mark.parametrize('personalisation, expected_body, expected_subject', [
|
||||||
|
(
|
||||||
|
['Jo', 'John', 'Josephine'],
|
||||||
|
(
|
||||||
|
'Hello \n\n'
|
||||||
|
'* Jo\n'
|
||||||
|
'* John\n'
|
||||||
|
'* Josephine\n'
|
||||||
|
'This is an email from GOV.\u200BUK'
|
||||||
|
),
|
||||||
|
'Jo, John and Josephine',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
6,
|
||||||
|
(
|
||||||
|
'Hello 6\n'
|
||||||
|
'This is an email from GOV.\u200BUK'
|
||||||
|
),
|
||||||
|
'6',
|
||||||
|
),
|
||||||
|
pytest.mark.xfail((
|
||||||
|
None,
|
||||||
|
('we consider None equivalent to missing personalisation'),
|
||||||
|
'',
|
||||||
|
)),
|
||||||
|
])
|
||||||
|
def test_send_notification_with_placeholders_replaced_with_unusual_types(
|
||||||
client,
|
client,
|
||||||
sample_email_template_with_placeholders,
|
sample_email_template_with_placeholders,
|
||||||
mocker
|
mocker,
|
||||||
|
personalisation,
|
||||||
|
expected_body,
|
||||||
|
expected_subject,
|
||||||
):
|
):
|
||||||
mocked = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
mocked = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
||||||
|
|
||||||
@@ -147,7 +176,7 @@ def test_send_notification_with_placeholders_replaced_with_list(
|
|||||||
'to': 'ok@ok.com',
|
'to': 'ok@ok.com',
|
||||||
'template': str(sample_email_template_with_placeholders.id),
|
'template': str(sample_email_template_with_placeholders.id),
|
||||||
'personalisation': {
|
'personalisation': {
|
||||||
'name': ['Jo', 'John', 'Josephine']
|
'name': personalisation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
@@ -157,16 +186,10 @@ def test_send_notification_with_placeholders_replaced_with_list(
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
response_data = json.loads(response.data)['data']
|
|
||||||
assert response.status_code == 201
|
assert response.status_code == 201
|
||||||
assert response_data['body'] == (
|
response_data = json.loads(response.data)['data']
|
||||||
'Hello \n\n'
|
assert response_data['body'] == expected_body
|
||||||
'* Jo\n'
|
assert response_data['subject'] == expected_subject
|
||||||
'* John\n'
|
|
||||||
'* Josephine\n'
|
|
||||||
'This is an email from GOV.\u200BUK'
|
|
||||||
)
|
|
||||||
assert response_data['subject'] == 'Jo, John and Josephine'
|
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_send_notification_for_archived_template(notify_api, sample_template):
|
def test_should_not_send_notification_for_archived_template(notify_api, sample_template):
|
||||||
|
|||||||
Reference in New Issue
Block a user