Ensures that both the CSV processing and the API both use the new deliver_email and deliver_sms tasks not the old ones with the redundant parameter.

This commit is contained in:
Martyn Inglis
2016-09-28 15:05:50 +01:00
parent 9233ffa3d4
commit c13ead77e4
5 changed files with 106 additions and 115 deletions

View File

@@ -25,7 +25,7 @@ from tests.app.conftest import (
def test_create_sms_should_reject_if_missing_required_fields(notify_api, sample_api_key, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = {}
auth_header = create_authorization_header(service_id=sample_api_key.service_id)
@@ -45,7 +45,7 @@ def test_create_sms_should_reject_if_missing_required_fields(notify_api, sample_
def test_should_reject_bad_phone_numbers(notify_api, sample_template, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = {
'to': 'invalid',
@@ -59,7 +59,7 @@ def test_should_reject_bad_phone_numbers(notify_api, sample_template, mocker):
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
assert json_resp['result'] == 'error'
assert len(json_resp['message'].keys()) == 1
assert 'Invalid phone number: Must not contain letters or symbols' in json_resp['message']['to']
@@ -69,7 +69,7 @@ def test_should_reject_bad_phone_numbers(notify_api, sample_template, mocker):
def test_send_notification_invalid_template_id(notify_api, sample_template, mocker, fake_uuid):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = {
'to': '+447700900855',
@@ -83,7 +83,7 @@ def test_send_notification_invalid_template_id(notify_api, sample_template, mock
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
assert response.status_code == 404
test_string = 'No result found'
@@ -94,7 +94,7 @@ def test_send_notification_invalid_template_id(notify_api, sample_template, mock
def test_send_notification_with_placeholders_replaced(notify_api, sample_email_template_with_placeholders, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
data = {
'to': 'ok@ok.com',
@@ -114,9 +114,8 @@ def test_send_notification_with_placeholders_replaced(notify_api, sample_email_t
notification_id = response_data['notification']['id']
data.update({"template_version": sample_email_template_with_placeholders.version})
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_called_once_with(
(str(sample_email_template_with_placeholders.service.id),
str(notification_id)),
app.celery.provider_tasks.deliver_email.apply_async.assert_called_once_with(
(str(notification_id)),
queue="send-email"
)
assert response.status_code == 201
@@ -147,7 +146,7 @@ def test_should_not_send_notification_for_archived_template(notify_api, sample_t
def test_send_notification_with_missing_personalisation(notify_api, sample_template_with_placeholders, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = {
'to': '+447700900855',
@@ -164,7 +163,7 @@ def test_send_notification_with_missing_personalisation(notify_api, sample_templ
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
assert response.status_code == 400
assert 'Missing personalisation: name' in json_resp['message']['template']
@@ -175,7 +174,7 @@ def test_send_notification_with_too_much_personalisation_data(
):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = {
'to': '+447700900855',
@@ -192,7 +191,7 @@ def test_send_notification_with_too_much_personalisation_data(
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
assert response.status_code == 400
assert 'Personalisation not needed for template: foo' in json_resp['message']['template']
@@ -201,7 +200,7 @@ def test_send_notification_with_too_much_personalisation_data(
def test_should_not_send_sms_if_restricted_and_not_a_service_user(notify_api, sample_template, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
sample_template.service.restricted = True
dao_update_service(sample_template.service)
@@ -219,7 +218,7 @@ def test_should_not_send_sms_if_restricted_and_not_a_service_user(notify_api, sa
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
assert response.status_code == 400
assert [(
@@ -231,7 +230,7 @@ def test_should_not_send_sms_if_restricted_and_not_a_service_user(notify_api, sa
def test_should_send_sms_if_restricted_and_a_service_user(notify_api, sample_template, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
sample_template.service.restricted = True
dao_update_service(sample_template.service)
@@ -247,14 +246,14 @@ def test_should_send_sms_if_restricted_and_a_service_user(notify_api, sample_tem
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header])
assert app.celery.provider_tasks.send_sms_to_provider.apply_async.called
assert app.celery.provider_tasks.deliver_sms.apply_async.called
assert response.status_code == 201
def test_should_send_email_if_restricted_and_a_service_user(notify_api, sample_email_template, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
sample_email_template.service.restricted = True
dao_update_service(sample_email_template.service)
@@ -270,14 +269,14 @@ def test_should_send_email_if_restricted_and_a_service_user(notify_api, sample_e
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header])
assert app.celery.provider_tasks.send_email_to_provider.apply_async.called
assert app.celery.provider_tasks.deliver_email.apply_async.called
assert response.status_code == 201
def test_should_not_allow_template_from_another_service(notify_api, service_factory, sample_user, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
service_1 = service_factory.get('service 1', user=sample_user, email_from='service.1')
service_2 = service_factory.get('service 2', user=sample_user, email_from='service.2')
@@ -296,7 +295,7 @@ def test_should_not_allow_template_from_another_service(notify_api, service_fact
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
assert response.status_code == 404
test_string = 'No result found'
@@ -320,7 +319,7 @@ def test_should_not_allow_template_content_too_large(
):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
template = create_sample_template(
notify_db,
notify_db_session,
@@ -357,7 +356,7 @@ def test_should_not_allow_template_content_too_large(
def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
data = {
@@ -375,8 +374,8 @@ def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker
response_data = json.loads(response.data)['data']
notification_id = response_data['notification']['id']
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_called_once_with(
(str(sample_template.service_id), notification_id), queue='send-sms')
app.celery.provider_tasks.deliver_sms.apply_async.assert_called_once_with(
(notification_id), queue='send-sms')
assert response.status_code == 201
assert notification_id
assert 'subject' not in response_data
@@ -387,7 +386,7 @@ def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker
def test_create_email_should_reject_if_missing_required_fields(notify_api, sample_api_key, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
data = {}
auth_header = create_authorization_header(service_id=sample_api_key.service_id)
@@ -398,7 +397,7 @@ def test_create_email_should_reject_if_missing_required_fields(notify_api, sampl
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_email.apply_async.assert_not_called()
assert json_resp['result'] == 'error'
assert 'Missing data for required field.' in json_resp['message']['to'][0]
assert 'Missing data for required field.' in json_resp['message']['template'][0]
@@ -408,7 +407,7 @@ def test_create_email_should_reject_if_missing_required_fields(notify_api, sampl
def test_should_reject_email_notification_with_bad_email(notify_api, sample_email_template, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
to_address = "bad-email"
data = {
'to': to_address,
@@ -422,7 +421,7 @@ def test_should_reject_email_notification_with_bad_email(notify_api, sample_emai
headers=[('Content-Type', 'application/json'), auth_header])
data = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_email.apply_async.assert_not_called()
assert response.status_code == 400
assert data['result'] == 'error'
assert data['message']['to'][0] == 'Not a valid email address'
@@ -432,7 +431,7 @@ def test_should_reject_email_notification_with_template_id_that_cant_be_found(
notify_api, sample_email_template, mocker, fake_uuid):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
data = {
'to': 'ok@ok.com',
'template': fake_uuid
@@ -445,7 +444,7 @@ def test_should_reject_email_notification_with_template_id_that_cant_be_found(
headers=[('Content-Type', 'application/json'), auth_header])
data = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_email.apply_async.assert_not_called()
assert response.status_code == 404
assert data['result'] == 'error'
test_string = 'No result found'
@@ -455,7 +454,7 @@ def test_should_reject_email_notification_with_template_id_that_cant_be_found(
def test_should_not_allow_email_template_from_another_service(notify_api, service_factory, sample_user, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
service_1 = service_factory.get('service 1', template_type='email', user=sample_user,
email_from='service.1')
@@ -477,7 +476,7 @@ def test_should_not_allow_email_template_from_another_service(notify_api, servic
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_email.apply_async.assert_not_called()
assert response.status_code == 404
test_string = 'No result found'
@@ -487,7 +486,7 @@ def test_should_not_allow_email_template_from_another_service(notify_api, servic
def test_should_not_send_email_if_restricted_and_not_a_service_user(notify_api, sample_email_template, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
sample_email_template.service.restricted = True
dao_update_service(sample_email_template.service)
@@ -505,7 +504,7 @@ def test_should_not_send_email_if_restricted_and_not_a_service_user(notify_api,
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_email.apply_async.assert_not_called()
assert response.status_code == 400
assert [(
@@ -518,7 +517,7 @@ def test_should_not_send_email_if_restricted_and_not_a_service_user(notify_api,
def test_should_allow_valid_email_notification(notify_api, sample_email_template, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
data = {
@@ -535,8 +534,8 @@ def test_should_allow_valid_email_notification(notify_api, sample_email_template
assert response.status_code == 201
response_data = json.loads(response.get_data(as_text=True))['data']
notification_id = response_data['notification']['id']
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_called_once_with(
(str(sample_email_template.service_id), notification_id),
app.celery.provider_tasks.deliver_email.apply_async.assert_called_once_with(
(notification_id),
queue="send-email"
)
@@ -555,7 +554,7 @@ def test_should_not_block_api_call_if_over_day_limit_for_live_service(
mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
service = create_sample_service(notify_db, notify_db_session, limit=1, restricted=False)
@@ -588,7 +587,7 @@ def test_should_block_api_call_if_over_day_limit_for_restricted_service(
mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
service = create_sample_service(notify_db, notify_db_session, limit=1, restricted=True)
@@ -624,7 +623,7 @@ def test_should_allow_api_call_if_under_day_limit_regardless_of_type(
restricted):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=restricted)
@@ -650,7 +649,7 @@ def test_should_allow_api_call_if_under_day_limit_regardless_of_type(
def test_should_not_return_html_in_body(notify_api, notify_db, notify_db_session, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
email_template = create_sample_email_template(notify_db, notify_db.session, content='hello\nthere')
data = {
@@ -670,7 +669,7 @@ def test_should_not_return_html_in_body(notify_api, notify_db, notify_db_session
def test_should_not_send_email_if_team_api_key_and_not_a_service_user(notify_api, sample_email_template, mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
data = {
'to': "not-someone-we-trust@email-address.com",
'template': str(sample_email_template.id),
@@ -685,7 +684,7 @@ def test_should_not_send_email_if_team_api_key_and_not_a_service_user(notify_api
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_email.apply_async.assert_not_called()
assert response.status_code == 400
assert [
@@ -695,7 +694,7 @@ def test_should_not_send_email_if_team_api_key_and_not_a_service_user(notify_api
def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api, sample_template, mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = {
'to': '07123123123',
@@ -710,7 +709,7 @@ def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api,
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
assert response.status_code == 400
assert [
@@ -720,7 +719,7 @@ def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api,
def test_should_send_email_if_team_api_key_and_a_service_user(notify_api, sample_email_template, fake_uuid, mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
data = {
@@ -739,8 +738,8 @@ def test_should_send_email_if_team_api_key_and_a_service_user(notify_api, sample
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))])
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_called_once_with(
(str(sample_email_template.service.id), fake_uuid),
app.celery.provider_tasks.deliver_email.apply_async.assert_called_once_with(
(fake_uuid),
queue='send-email')
assert response.status_code == 201
@@ -751,7 +750,7 @@ def test_should_send_email_to_anyone_with_test_key(
notify_api, sample_email_template, mocker, restricted, limit, fake_uuid
):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
data = {
@@ -775,14 +774,14 @@ def test_should_send_email_to_anyone_with_test_key(
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))]
)
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_called_once_with(
(str(sample_email_template.service.id), fake_uuid), queue='send-email')
app.celery.provider_tasks.deliver_email.apply_async.assert_called_once_with(
(fake_uuid), queue='send-email')
assert response.status_code == 201
def test_should_send_sms_if_team_api_key_and_a_service_user(notify_api, sample_template, fake_uuid, mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
data = {
@@ -801,14 +800,14 @@ def test_should_send_sms_if_team_api_key_and_a_service_user(notify_api, sample_t
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))])
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_called_once_with(
(str(sample_template.service.id), fake_uuid), queue='send-sms')
app.celery.provider_tasks.deliver_sms.apply_async.assert_called_once_with(
(fake_uuid), queue='send-sms')
assert response.status_code == 201
def test_should_persist_sms_notification(notify_api, sample_template, fake_uuid, mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
data = {
@@ -828,8 +827,8 @@ def test_should_persist_sms_notification(notify_api, sample_template, fake_uuid,
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))])
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_called_once_with(
(str(sample_template.service.id), fake_uuid), queue='send-sms')
app.celery.provider_tasks.deliver_sms.apply_async.assert_called_once_with(
(fake_uuid), queue='send-sms')
assert response.status_code == 201
notification = notifications_dao.get_notification_by_id(fake_uuid)
@@ -840,7 +839,7 @@ def test_should_persist_sms_notification(notify_api, sample_template, fake_uuid,
def test_should_persist_email_notification(notify_api, sample_email_template, fake_uuid, mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
data = {
@@ -860,8 +859,8 @@ def test_should_persist_email_notification(notify_api, sample_email_template, fa
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))])
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_called_once_with(
(str(sample_email_template.service.id), fake_uuid), queue='send-email')
app.celery.provider_tasks.deliver_email.apply_async.assert_called_once_with(
(fake_uuid), queue='send-email')
assert response.status_code == 201
notification = notifications_dao.get_notification_by_id(fake_uuid)
@@ -877,7 +876,7 @@ def test_should_delete_email_notification_and_return_error_if_sqs_fails(
mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch(
'app.celery.provider_tasks.send_email_to_provider.apply_async',
'app.celery.provider_tasks.deliver_email.apply_async',
side_effect=Exception("failed to talk to SQS")
)
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
@@ -899,8 +898,8 @@ def test_should_delete_email_notification_and_return_error_if_sqs_fails(
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))])
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_called_once_with(
(str(sample_email_template.service.id), fake_uuid), queue='send-email')
app.celery.provider_tasks.deliver_email.apply_async.assert_called_once_with(
(fake_uuid), queue='send-email')
assert response.status_code == 500
assert not notifications_dao.get_notification_by_id(fake_uuid)
@@ -910,7 +909,7 @@ def test_should_delete_email_notification_and_return_error_if_sqs_fails(
def test_should_delete_sms_notification_and_return_error_if_sqs_fails(notify_api, sample_template, fake_uuid, mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch(
'app.celery.provider_tasks.send_sms_to_provider.apply_async',
'app.celery.provider_tasks.deliver_sms.apply_async',
side_effect=Exception("failed to talk to SQS")
)
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
@@ -932,8 +931,7 @@ def test_should_delete_sms_notification_and_return_error_if_sqs_fails(notify_api
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))])
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_called_once_with(
(str(sample_template.service.id), fake_uuid), queue='send-sms')
app.celery.provider_tasks.deliver_sms.apply_async.assert_called_once_with((fake_uuid), queue='send-sms')
assert response.status_code == 500
assert not notifications_dao.get_notification_by_id(fake_uuid)
@@ -950,7 +948,7 @@ def test_should_not_persist_notification_or_send_email_if_simulated_email(
to_email,
sample_email_template,
mocker):
apply_async = mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
apply_async = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
data = {
'to': to_email,
@@ -979,7 +977,7 @@ def test_should_not_persist_notification_or_send_sms_if_simulated_number(
to_sms,
sample_template,
mocker):
apply_async = mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
apply_async = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = {
'to': to_sms,