Merge branch 'master' into refactor-send_notifications

Conflicts:
	tests/app/notifications/rest/test_send_notification.py
This commit is contained in:
Rebecca Law
2016-10-03 11:40:31 +01:00
9 changed files with 280 additions and 124 deletions

View File

@@ -33,7 +33,10 @@ def test_create_notification_should_reject_if_missing_required_fields(notify_api
sample_api_key, mocker, template_type):
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')
if template_type == 'sms':
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
else:
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
data = {}
auth_header = create_authorization_header(service_id=sample_api_key.service_id)
@@ -44,7 +47,10 @@ def test_create_notification_should_reject_if_missing_required_fields(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()
if template_type == 'sms':
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
else:
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]
@@ -54,7 +60,7 @@ def test_create_notification_should_reject_if_missing_required_fields(notify_api
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',
@@ -68,7 +74,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']
@@ -81,7 +87,10 @@ 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, template_type, to):
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')
if template_type == 'sms':
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
else:
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
data = {
'to': to,
@@ -95,8 +104,10 @@ 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()
if template_type == 'sms':
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
else:
app.celery.provider_tasks.deliver_email.apply_async.assert_not_called()
assert response.status_code == 404
test_string = 'No result found'
assert test_string in json_resp['message']
@@ -106,7 +117,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',
@@ -126,9 +137,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(
[notification_id],
queue="send-email"
)
assert response.status_code == 201
@@ -167,7 +177,10 @@ def test_should_not_send_notification_if_restricted_and_not_a_service_user(notif
to):
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')
if template_type == 'sms':
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
else:
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
template = sample_template if template_type == 'sms' else sample_email_template
template.service.restricted = True
dao_update_service(template.service)
@@ -184,7 +197,10 @@ def test_should_not_send_notification_if_restricted_and_not_a_service_user(notif
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()
if template_type == 'sms':
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
else:
app.celery.provider_tasks.deliver_email.apply_async.assert_not_called()
assert response.status_code == 400
assert [(
@@ -203,9 +219,9 @@ def test_should_send_notification_if_restricted_and_a_service_user(notify_api,
with notify_api.test_request_context():
with notify_api.test_client() as client:
if template_type == 'sms':
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
else:
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
template = sample_template if template_type == 'sms' else sample_email_template
to = template.service.created_by.mobile_number if template_type == 'sms' \
@@ -225,9 +241,9 @@ def test_should_send_notification_if_restricted_and_a_service_user(notify_api,
headers=[('Content-Type', 'application/json'), auth_header])
if template_type == 'sms':
assert app.celery.provider_tasks.send_sms_to_provider.apply_async.called
assert app.celery.provider_tasks.deliver_sms.apply_async.called
else:
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
@@ -241,9 +257,9 @@ def test_should_not_allow_template_from_another_service(notify_api,
with notify_api.test_request_context():
with notify_api.test_client() as client:
if template_type == 'sms':
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
else:
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', user=sample_user, email_from='service.1')
service_2 = service_factory.get('service 2', user=sample_user, email_from='service.2')
@@ -263,9 +279,9 @@ def test_should_not_allow_template_from_another_service(notify_api,
json_resp = json.loads(response.get_data(as_text=True))
if template_type == 'sms':
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
app.celery.provider_tasks.deliver_sms.apply_async.assert_not_called()
else:
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'
assert test_string in json_resp['message']
@@ -275,7 +291,7 @@ def test_should_not_allow_template_from_another_service(notify_api,
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 = {
@@ -293,8 +309,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
@@ -305,7 +321,7 @@ def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker
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,
@@ -319,7 +335,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'
@@ -329,7 +345,7 @@ def test_should_reject_email_notification_with_bad_email(notify_api, sample_emai
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 = {
@@ -346,8 +362,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"
)
@@ -366,7 +382,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)
@@ -399,7 +415,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)
@@ -435,7 +451,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)
@@ -461,7 +477,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 = {
@@ -481,7 +497,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),
@@ -496,7 +512,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 [
@@ -506,7 +522,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',
@@ -521,7 +537,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 [
@@ -531,7 +547,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 = {
@@ -550,9 +566,40 @@ 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),
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
@pytest.mark.parametrize('restricted', [True, False])
@pytest.mark.parametrize('limit', [0, 1])
def test_should_send_sms_to_anyone_with_test_key(
notify_api, sample_template, mocker, restricted, limit, fake_uuid
):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
data = {
'to': '07811111111',
'template': sample_template.id
}
sample_template.service.restricted = restricted
sample_template.service.message_limit = limit
api_key = ApiKey(
service=sample_template.service,
name='test_key',
created_by=sample_template.created_by,
key_type=KEY_TYPE_TEST
)
save_model_api_key(api_key)
auth_header = create_jwt_token(secret=api_key.unsigned_secret, client_id=str(api_key.service_id))
response = client.post(
path='/notifications/sms',
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))]
)
app.celery.provider_tasks.deliver_sms.apply_async.assert_called_once_with([fake_uuid], queue='research-mode')
assert response.status_code == 201
@@ -562,7 +609,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 = {
@@ -586,14 +633,13 @@ 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='research-mode')
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 = {
@@ -612,8 +658,7 @@ 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
@@ -625,9 +670,9 @@ def test_should_persist_notification(notify_api, sample_template,
fake_uuid, mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
if template_type == 'sms':
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
else:
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)
template = sample_template if template_type == 'sms' else sample_email_template
to = sample_template.service.created_by.mobile_number if template_type == 'sms' \
@@ -650,11 +695,9 @@ def test_should_persist_notification(notify_api, sample_template,
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))])
if template_type == 'sms':
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_called_once_with(
(str(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')
else:
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_called_once_with(
(str(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)
@@ -675,12 +718,12 @@ def test_should_delete_notification_and_return_error_if_sqs_fails(
with notify_api.test_request_context(), notify_api.test_client() as client:
if template_type == 'email':
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")
)
else:
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)
@@ -705,11 +748,9 @@ def test_should_delete_notification_and_return_error_if_sqs_fails(
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))])
if template_type == 'email':
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_called_once_with(
(str(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')
else:
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_called_once_with(
(str(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)
@@ -726,7 +767,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,
@@ -755,7 +796,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,
@@ -790,11 +831,11 @@ def test_should_not_send_notification_to_non_whitelist_recipient_in_trial_mode(c
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session, service=service)
if notification_type == 'sms':
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')
template = create_sample_template(notify_db, notify_db_session, service=service)
elif notification_type == 'email':
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')
template = create_sample_email_template(notify_db, notify_db_session, service=service)
assert service_whitelist.service_id == service.id
@@ -838,12 +879,12 @@ def test_should_send_notification_to_whitelist_recipient_in_trial_mode_with_live
mocker):
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=True)
if notification_type == 'sms':
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')
template = create_sample_template(notify_db, notify_db_session, service=service)
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session,
service=service, mobile_number=to)
elif notification_type == 'email':
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')
template = create_sample_email_template(notify_db, notify_db_session, service=service)
service_whitelist = create_sample_service_whitelist(notify_db, notify_db_session,
service=service, email_address=to)