mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
- 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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user