- If the task runs twice and the notification already exists ignore the primary key constraint.

- Remove prints
- Add some more tests
- Only allow the new method to run for emails
This commit is contained in:
Rebecca Law
2020-03-25 12:39:15 +00:00
parent a13bcc6697
commit db4b4d929d
7 changed files with 105 additions and 10 deletions

View File

@@ -976,4 +976,58 @@ def test_post_notifications_saves_email_to_queue(client, notify_db_session, mock
assert json_resp['id']
assert json_resp['content']['body'] == "Dear citizen, have a nice day"
assert json_resp['template']['id'] == str(template.id)
save_email_task.assert_called_once_with([mock.ANY], queue='save-api-email')
save_email_task.assert_called_once_with([mock.ANY], queue='save-api-email-tasks')
def test_post_notifications_doesnt_save_email_to_queue_for_test_emails(client, notify_db_session, mocker):
save_email_task = mocker.patch("app.celery.tasks.save_api_email.apply_async")
mocked_send_task = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
service = create_service(service_id='539d63a1-701d-400d-ab11-f3ee2319d4d4', service_name='high volume service')
# create_api_key(service=service, key_type='test')
template = create_template(service=service, content='((message))', template_type=EMAIL_TYPE)
data = {
"email_address": "joe.citizen@example.com",
"template_id": template.id,
"personalisation": {"message": "Dear citizen, have a nice day"}
}
response = client.post(
path='/v2/notifications/email',
data=json.dumps(data),
headers=[('Content-Type', 'application/json'),
create_authorization_header(service_id=service.id, key_type='test')]
)
json_resp = response.get_json()
assert response.status_code == 201
assert json_resp['id']
assert json_resp['content']['body'] == "Dear citizen, have a nice day"
assert json_resp['template']['id'] == str(template.id)
assert mocked_send_task.called
assert not save_email_task.called
def test_post_notifications_doesnt_save_email_to_queue_for_sms(client, notify_db_session, mocker):
save_email_task = mocker.patch("app.celery.tasks.save_api_email.apply_async")
mocked_send_task = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
service = create_service(service_id='539d63a1-701d-400d-ab11-f3ee2319d4d4', service_name='high volume service')
template = create_template(service=service, content='((message))', template_type=SMS_TYPE)
data = {
"phone_number": '+447700900855',
"template_id": template.id,
"personalisation": {"message": "Dear citizen, have a nice day"}
}
response = client.post(
path='/v2/notifications/sms',
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), create_authorization_header(service_id=service.id)]
)
json_resp = response.get_json()
assert response.status_code == 201
assert json_resp['id']
assert mocked_send_task.called
assert not save_email_task.called