mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-27 19:29:24 -04:00
Merge branch 'master' into delete-csv-file-after-7-days
Conflicts: app/notifications/rest.py
This commit is contained in:
@@ -60,7 +60,7 @@ def test_send_sms_calls_mmg_correctly(notify_api, mocker):
|
||||
assert request_args['reqType'] == 'BULK'
|
||||
assert request_args['MSISDN'] == to
|
||||
assert request_args['msg'] == content
|
||||
assert request_args['sender'] == 'from_number'
|
||||
assert request_args['sender'] == 'testing'
|
||||
assert request_args['cid'] == reference
|
||||
assert request_args['multi'] is True
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ from app.dao.notifications_dao import (
|
||||
get_notifications_for_job,
|
||||
get_notifications_for_service,
|
||||
update_notification_status_by_id,
|
||||
update_notification_status_by_reference
|
||||
update_notification_status_by_reference,
|
||||
dao_delete_notifications_and_history_by_id
|
||||
)
|
||||
|
||||
from notifications_utils.template import get_sms_fragment_count
|
||||
@@ -55,6 +56,7 @@ def test_should_have_decorated_notifications_dao_functions():
|
||||
assert get_notifications_for_service.__wrapped__.__name__ == 'get_notifications_for_service' # noqa
|
||||
assert get_notification_by_id.__wrapped__.__name__ == 'get_notification_by_id' # noqa
|
||||
assert delete_notifications_created_more_than_a_week_ago.__wrapped__.__name__ == 'delete_notifications_created_more_than_a_week_ago' # noqa
|
||||
assert dao_delete_notifications_and_history_by_id.__wrapped__.__name__ == 'dao_delete_notifications_and_history_by_id' # noqa
|
||||
|
||||
|
||||
def test_should_be_able_to_get_template_usage_history(notify_db, notify_db_session, sample_service):
|
||||
@@ -73,7 +75,6 @@ def test_should_be_able_to_get_all_template_usage_history_order_by_notification_
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_service):
|
||||
|
||||
sms = sample_template(notify_db, notify_db_session)
|
||||
|
||||
sample_notification(notify_db, notify_db_session, service=sample_service, template=sms)
|
||||
@@ -88,7 +89,6 @@ def test_should_be_able_to_get_all_template_usage_history_order_by_notification_
|
||||
def test_should_be_able_to_get_no_template_usage_history_if_no_notifications_using_template(
|
||||
notify_db,
|
||||
notify_db_session):
|
||||
|
||||
sms = sample_template(notify_db, notify_db_session)
|
||||
|
||||
results = dao_get_last_template_usage(sms.id)
|
||||
@@ -729,6 +729,67 @@ def test_updating_notification_updates_notification_history(sample_notification)
|
||||
assert hist.status == 'sending'
|
||||
|
||||
|
||||
def test_should_delete_notification_and_notification_history_for_id(notify_db, notify_db_session, sample_template):
|
||||
data = _notification_json(sample_template)
|
||||
notification = Notification(**data)
|
||||
|
||||
dao_create_notification(notification)
|
||||
|
||||
assert Notification.query.count() == 1
|
||||
assert NotificationHistory.query.count() == 1
|
||||
|
||||
dao_delete_notifications_and_history_by_id(notification.id)
|
||||
|
||||
assert Notification.query.count() == 0
|
||||
assert NotificationHistory.query.count() == 0
|
||||
|
||||
|
||||
def test_should_delete_only_notification_and_notification_history_with_id(notify_db, notify_db_session,
|
||||
sample_template):
|
||||
id_1 = uuid.uuid4()
|
||||
id_2 = uuid.uuid4()
|
||||
data_1 = _notification_json(sample_template, id=id_1)
|
||||
data_2 = _notification_json(sample_template, id=id_2)
|
||||
|
||||
notification_1 = Notification(**data_1)
|
||||
notification_2 = Notification(**data_2)
|
||||
|
||||
dao_create_notification(notification_1)
|
||||
dao_create_notification(notification_2)
|
||||
|
||||
assert Notification.query.count() == 2
|
||||
assert NotificationHistory.query.count() == 2
|
||||
|
||||
dao_delete_notifications_and_history_by_id(notification_1.id)
|
||||
|
||||
assert Notification.query.count() == 1
|
||||
assert NotificationHistory.query.count() == 1
|
||||
assert Notification.query.first().id == notification_2.id
|
||||
assert NotificationHistory.query.first().id == notification_2.id
|
||||
|
||||
|
||||
def test_should_delete_no_notifications_or_notification_historys_if_no_matching_ids(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
id_1 = uuid.uuid4()
|
||||
id_2 = uuid.uuid4()
|
||||
data_1 = _notification_json(sample_template, id=id_1)
|
||||
|
||||
notification_1 = Notification(**data_1)
|
||||
|
||||
dao_create_notification(notification_1)
|
||||
|
||||
assert Notification.query.count() == 1
|
||||
assert NotificationHistory.query.count() == 1
|
||||
|
||||
dao_delete_notifications_and_history_by_id(id_2)
|
||||
|
||||
assert Notification.query.count() == 1
|
||||
assert NotificationHistory.query.count() == 1
|
||||
|
||||
|
||||
def _notification_json(sample_template, job_id=None, id=None, status=None):
|
||||
data = {
|
||||
'to': '+44709123456',
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
import random
|
||||
import string
|
||||
@@ -10,7 +11,8 @@ from notifications_python_client.authentication import create_jwt_token
|
||||
|
||||
import app
|
||||
from app import encryption
|
||||
from app.models import ApiKey, KEY_TYPE_TEAM, KEY_TYPE_TEST
|
||||
from app.dao import notifications_dao
|
||||
from app.models import ApiKey, KEY_TYPE_TEAM, KEY_TYPE_TEST, Notification, NotificationHistory
|
||||
from app.dao.templates_dao import dao_get_all_templates_for_service, dao_update_template
|
||||
from app.dao.services_dao import dao_update_service
|
||||
from app.dao.api_key_dao import save_model_api_key
|
||||
@@ -26,7 +28,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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
|
||||
data = {}
|
||||
auth_header = create_authorization_header(service_id=sample_api_key.service_id)
|
||||
@@ -46,7 +48,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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
|
||||
data = {
|
||||
'to': 'invalid',
|
||||
@@ -60,7 +62,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.tasks.send_sms.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_sms_to_provider.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']
|
||||
@@ -70,7 +72,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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
|
||||
data = {
|
||||
'to': '+447700900855',
|
||||
@@ -84,7 +86,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.tasks.send_sms.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 404
|
||||
test_string = 'No result found'
|
||||
@@ -95,7 +97,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.apply_async')
|
||||
mocker.patch('app.celery.tasks.send_email_to_provider.apply_async')
|
||||
|
||||
data = {
|
||||
'to': 'ok@ok.com',
|
||||
@@ -115,16 +117,12 @@ 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.tasks.send_email.apply_async.assert_called_once_with(
|
||||
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_called_once_with(
|
||||
(str(sample_email_template_with_placeholders.service.id),
|
||||
notification_id,
|
||||
ANY,
|
||||
"2016-01-01T11:09:00.061258"),
|
||||
kwargs=ANY,
|
||||
queue="db-email"
|
||||
str(notification_id)),
|
||||
queue="send-email"
|
||||
)
|
||||
assert response.status_code == 201
|
||||
assert encryption.decrypt(app.celery.tasks.send_email.apply_async.call_args[0][0][2]) == data
|
||||
assert response_data['body'] == 'Hello Jo\nThis is an email from GOV.UK'
|
||||
assert response_data['subject'] == 'Jo'
|
||||
|
||||
@@ -152,7 +150,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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
|
||||
data = {
|
||||
'to': '+447700900855',
|
||||
@@ -169,7 +167,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.tasks.send_sms.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 400
|
||||
assert 'Missing personalisation: name' in json_resp['message']['template']
|
||||
@@ -180,7 +178,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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
|
||||
data = {
|
||||
'to': '+447700900855',
|
||||
@@ -197,7 +195,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.tasks.send_sms.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 400
|
||||
assert 'Personalisation not needed for template: foo' in json_resp['message']['template']
|
||||
@@ -206,7 +204,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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
|
||||
sample_template.service.restricted = True
|
||||
dao_update_service(sample_template.service)
|
||||
@@ -224,7 +222,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.tasks.send_sms.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 400
|
||||
assert [(
|
||||
@@ -236,7 +234,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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
|
||||
sample_template.service.restricted = True
|
||||
dao_update_service(sample_template.service)
|
||||
@@ -252,14 +250,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.tasks.send_sms.apply_async.called
|
||||
assert app.celery.provider_tasks.send_sms_to_provider.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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
|
||||
sample_email_template.service.restricted = True
|
||||
dao_update_service(sample_email_template.service)
|
||||
@@ -275,14 +273,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.tasks.send_email.apply_async.called
|
||||
assert app.celery.provider_tasks.send_email_to_provider.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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.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')
|
||||
@@ -301,7 +299,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.tasks.send_sms.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 404
|
||||
test_string = 'No result found'
|
||||
@@ -325,7 +323,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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
template = create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
@@ -362,7 +360,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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
||||
|
||||
data = {
|
||||
@@ -379,18 +377,9 @@ 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']
|
||||
assert app.encryption.encrypt.call_args[0][0]['to'] == '+447700900855'
|
||||
assert app.encryption.encrypt.call_args[0][0]['template'] == str(sample_template.id)
|
||||
assert app.encryption.encrypt.call_args[0][0]['template_version'] == sample_template.version
|
||||
|
||||
app.celery.tasks.send_sms.apply_async.assert_called_once_with(
|
||||
(str(sample_template.service_id),
|
||||
notification_id,
|
||||
"something_encrypted",
|
||||
"2016-01-01T11:09:00.061258"),
|
||||
kwargs=ANY,
|
||||
queue="db-sms"
|
||||
)
|
||||
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_called_once_with(
|
||||
(str(sample_template.service_id), notification_id), queue='send-sms')
|
||||
assert response.status_code == 201
|
||||
assert notification_id
|
||||
assert 'subject' not in response_data
|
||||
@@ -401,7 +390,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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
|
||||
data = {}
|
||||
auth_header = create_authorization_header(service_id=sample_api_key.service_id)
|
||||
@@ -412,7 +401,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.tasks.send_email.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_email_to_provider.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]
|
||||
@@ -422,7 +411,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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
to_address = "bad-email"
|
||||
data = {
|
||||
'to': to_address,
|
||||
@@ -436,7 +425,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.tasks.send_email.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
|
||||
assert response.status_code == 400
|
||||
assert data['result'] == 'error'
|
||||
assert data['message']['to'][0] == 'Not a valid email address'
|
||||
@@ -446,7 +435,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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
data = {
|
||||
'to': 'ok@ok.com',
|
||||
'template': fake_uuid
|
||||
@@ -459,7 +448,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.tasks.send_email.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
|
||||
assert response.status_code == 404
|
||||
assert data['result'] == 'error'
|
||||
test_string = 'No result found'
|
||||
@@ -469,7 +458,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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
|
||||
service_1 = service_factory.get('service 1', template_type='email', user=sample_user,
|
||||
email_from='service.1')
|
||||
@@ -491,7 +480,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.tasks.send_email.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 404
|
||||
test_string = 'No result found'
|
||||
@@ -501,7 +490,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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
|
||||
sample_email_template.service.restricted = True
|
||||
dao_update_service(sample_email_template.service)
|
||||
@@ -519,7 +508,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.tasks.send_email.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 400
|
||||
assert [(
|
||||
@@ -532,7 +521,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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
||||
|
||||
data = {
|
||||
@@ -549,16 +538,9 @@ 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']
|
||||
assert app.encryption.encrypt.call_args[0][0]['to'] == 'ok@ok.com'
|
||||
assert app.encryption.encrypt.call_args[0][0]['template'] == str(sample_email_template.id)
|
||||
assert app.encryption.encrypt.call_args[0][0]['template_version'] == sample_email_template.version
|
||||
app.celery.tasks.send_email.apply_async.assert_called_once_with(
|
||||
(str(sample_email_template.service_id),
|
||||
notification_id,
|
||||
"something_encrypted",
|
||||
"2016-01-01T11:09:00.061258"),
|
||||
kwargs=ANY,
|
||||
queue="db-email"
|
||||
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_called_once_with(
|
||||
(str(sample_email_template.service_id), notification_id),
|
||||
queue="send-email"
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
@@ -568,19 +550,18 @@ def test_should_allow_valid_email_notification(notify_api, sample_email_template
|
||||
assert response_data['template_version'] == sample_email_template.version
|
||||
|
||||
|
||||
@pytest.mark.parametrize('restricted', [True, False])
|
||||
@freeze_time("2016-01-01 12:00:00.061258")
|
||||
def test_should_block_api_call_if_over_day_limit_for_restricted_and_live_service(notify_db,
|
||||
notify_db_session,
|
||||
notify_api,
|
||||
mocker,
|
||||
restricted):
|
||||
def test_should_not_block_api_call_if_over_day_limit_for_live_service(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
notify_api,
|
||||
mocker):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
mocker.patch('app.celery.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
||||
|
||||
service = create_sample_service(notify_db, notify_db_session, limit=1, restricted=restricted)
|
||||
service = create_sample_service(notify_db, notify_db_session, limit=1, restricted=False)
|
||||
email_template = create_sample_email_template(notify_db, notify_db_session, service=service)
|
||||
create_sample_notification(
|
||||
notify_db, notify_db_session, template=email_template, service=service, created_at=datetime.utcnow()
|
||||
@@ -597,56 +578,65 @@ def test_should_block_api_call_if_over_day_limit_for_restricted_and_live_service
|
||||
path='/notifications/email',
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert response.status_code == 429
|
||||
assert 'Exceeded send limits (1) for today' in json_resp['message']
|
||||
assert response.status_code == 201
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 12:00:00.061258")
|
||||
def test_should_block_api_call_if_over_day_limit_regardless_of_type(notify_db, notify_db_session, notify_api, mocker):
|
||||
def test_should_block_api_call_if_over_day_limit_for_restricted_service(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
notify_api,
|
||||
mocker):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
||||
|
||||
service = create_sample_service(notify_db, notify_db_session, limit=1, restricted=True)
|
||||
email_template = create_sample_email_template(notify_db, notify_db_session, service=service)
|
||||
sms_template = create_sample_template(notify_db, notify_db_session, service=service)
|
||||
create_sample_notification(
|
||||
notify_db, notify_db_session, template=email_template, service=service, created_at=datetime.utcnow()
|
||||
)
|
||||
|
||||
data = {
|
||||
'to': '+447234123123',
|
||||
'template': str(sms_template.id)
|
||||
'to': 'ok@ok.com',
|
||||
'template': str(email_template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
path='/notifications/email',
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert response.status_code == 429
|
||||
assert 'Exceeded send limits (1) for today' in json_resp['message']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('restricted', [True, False])
|
||||
@freeze_time("2016-01-01 12:00:00.061258")
|
||||
def test_should_allow_api_call_if_under_day_limit_regardless_of_type(notify_db, notify_db_session, notify_api, mocker):
|
||||
def test_should_allow_api_call_if_under_day_limit_regardless_of_type(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
notify_api,
|
||||
sample_user,
|
||||
mocker,
|
||||
restricted):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
||||
|
||||
service = create_sample_service(notify_db, notify_db_session, limit=2)
|
||||
service = create_sample_service(notify_db, notify_db_session, limit=2, restricted=restricted)
|
||||
email_template = create_sample_email_template(notify_db, notify_db_session, service=service)
|
||||
sms_template = create_sample_template(notify_db, notify_db_session, service=service)
|
||||
create_sample_notification(notify_db, notify_db_session, template=email_template, service=service)
|
||||
|
||||
data = {
|
||||
'to': '+447634123123',
|
||||
'to': sample_user.mobile_number,
|
||||
'template': str(sms_template.id)
|
||||
}
|
||||
|
||||
@@ -663,7 +653,7 @@ def test_should_allow_api_call_if_under_day_limit_regardless_of_type(notify_db,
|
||||
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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
email_template = create_sample_email_template(notify_db, notify_db.session, content='hello\nthere')
|
||||
|
||||
data = {
|
||||
@@ -683,7 +673,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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
|
||||
data = {
|
||||
'to': "not-someone-we-trust@email-address.com",
|
||||
@@ -701,7 +691,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.tasks.send_email.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_email_to_provider.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 400
|
||||
assert [
|
||||
@@ -711,7 +701,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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
|
||||
data = {
|
||||
'to': '07123123123',
|
||||
@@ -726,7 +716,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.tasks.send_sms.apply_async.assert_not_called()
|
||||
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 400
|
||||
assert [
|
||||
@@ -734,9 +724,10 @@ def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api,
|
||||
] == json_resp['message']['to']
|
||||
|
||||
|
||||
def test_should_send_email_if_team_api_key_and_a_service_user(notify_api, sample_email_template, mocker):
|
||||
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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
|
||||
|
||||
data = {
|
||||
'to': sample_email_template.service.created_by.email_address,
|
||||
@@ -754,23 +745,20 @@ 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.tasks.send_email.apply_async.assert_called_once_with(
|
||||
ANY,
|
||||
kwargs={
|
||||
'api_key_id': str(api_key.id),
|
||||
'key_type': api_key.key_type
|
||||
},
|
||||
queue='db-email')
|
||||
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')
|
||||
assert response.status_code == 201
|
||||
|
||||
|
||||
@pytest.mark.parametrize('restricted', [True, False])
|
||||
@pytest.mark.parametrize('limit', [0, 1])
|
||||
def test_should_send_email_to_anyone_with_test_key(
|
||||
notify_api, sample_email_template, mocker, restricted, limit
|
||||
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.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_email_to_provider.apply_async')
|
||||
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
|
||||
|
||||
data = {
|
||||
'to': 'anyone123@example.com',
|
||||
@@ -793,20 +781,15 @@ def test_should_send_email_to_anyone_with_test_key(
|
||||
headers=[('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(auth_header))]
|
||||
)
|
||||
|
||||
app.celery.tasks.send_email.apply_async.assert_called_once_with(
|
||||
ANY,
|
||||
kwargs={
|
||||
'api_key_id': str(api_key.id),
|
||||
'key_type': api_key.key_type
|
||||
},
|
||||
queue='db-email'
|
||||
)
|
||||
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')
|
||||
assert response.status_code == 201
|
||||
|
||||
|
||||
def test_should_send_sms_if_team_api_key_and_a_service_user(notify_api, sample_template, mocker):
|
||||
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.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.apply_async')
|
||||
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
|
||||
|
||||
data = {
|
||||
'to': sample_template.service.created_by.mobile_number,
|
||||
@@ -824,11 +807,140 @@ 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.tasks.send_sms.apply_async.assert_called_once_with(
|
||||
ANY,
|
||||
kwargs={
|
||||
'api_key_id': str(api_key.id),
|
||||
'key_type': api_key.key_type
|
||||
},
|
||||
queue='db-sms')
|
||||
app.celery.provider_tasks.send_sms_to_provider.apply_async.assert_called_once_with(
|
||||
(str(sample_template.service.id), 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.notifications.rest.create_uuid', return_value=fake_uuid)
|
||||
|
||||
data = {
|
||||
'to': sample_template.service.created_by.mobile_number,
|
||||
'template': sample_template.id
|
||||
}
|
||||
api_key = ApiKey(
|
||||
service=sample_template.service,
|
||||
name='team_key',
|
||||
created_by=sample_template.created_by,
|
||||
key_type=KEY_TYPE_TEAM)
|
||||
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.send_sms_to_provider.apply_async.assert_called_once_with(
|
||||
(str(sample_template.service.id), fake_uuid), queue='send-sms')
|
||||
assert response.status_code == 201
|
||||
|
||||
notification = notifications_dao.get_notification_by_id(fake_uuid)
|
||||
assert notification.to == sample_template.service.created_by.mobile_number
|
||||
assert notification.template_id == sample_template.id
|
||||
assert notification.notification_type == 'sms'
|
||||
|
||||
|
||||
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.notifications.rest.create_uuid', return_value=fake_uuid)
|
||||
|
||||
data = {
|
||||
'to': sample_email_template.service.created_by.email_address,
|
||||
'template': sample_email_template.id
|
||||
}
|
||||
api_key = ApiKey(
|
||||
service=sample_email_template.service,
|
||||
name='team_key',
|
||||
created_by=sample_email_template.created_by,
|
||||
key_type=KEY_TYPE_TEAM)
|
||||
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/email',
|
||||
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')
|
||||
assert response.status_code == 201
|
||||
|
||||
notification = notifications_dao.get_notification_by_id(fake_uuid)
|
||||
assert notification.to == sample_email_template.service.created_by.email_address
|
||||
assert notification.template_id == sample_email_template.id
|
||||
assert notification.notification_type == 'email'
|
||||
|
||||
|
||||
def test_should_delete_email_notification_and_return_error_if_sqs_fails(
|
||||
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',
|
||||
side_effect=Exception("failed to talk to SQS")
|
||||
)
|
||||
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
|
||||
|
||||
data = {
|
||||
'to': sample_email_template.service.created_by.email_address,
|
||||
'template': sample_email_template.id
|
||||
}
|
||||
api_key = ApiKey(
|
||||
service=sample_email_template.service,
|
||||
name='team_key',
|
||||
created_by=sample_email_template.created_by,
|
||||
key_type=KEY_TYPE_TEAM)
|
||||
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/email',
|
||||
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')
|
||||
|
||||
assert response.status_code == 500
|
||||
assert not notifications_dao.get_notification_by_id(fake_uuid)
|
||||
assert not NotificationHistory.query.get(fake_uuid)
|
||||
|
||||
|
||||
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',
|
||||
side_effect=Exception("failed to talk to SQS")
|
||||
)
|
||||
mocker.patch('app.notifications.rest.create_uuid', return_value=fake_uuid)
|
||||
|
||||
data = {
|
||||
'to': sample_template.service.created_by.mobile_number,
|
||||
'template': sample_template.id
|
||||
}
|
||||
api_key = ApiKey(
|
||||
service=sample_template.service,
|
||||
name='team_key',
|
||||
created_by=sample_template.created_by,
|
||||
key_type=KEY_TYPE_TEAM)
|
||||
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.send_sms_to_provider.apply_async.assert_called_once_with(
|
||||
(str(sample_template.service.id), fake_uuid), queue='send-sms')
|
||||
|
||||
assert response.status_code == 500
|
||||
assert not notifications_dao.get_notification_by_id(fake_uuid)
|
||||
assert not NotificationHistory.query.get(fake_uuid)
|
||||
|
||||
@@ -5,7 +5,7 @@ from tests import create_authorization_header
|
||||
|
||||
|
||||
def test_post_sms_contract(client, mocker, sample_template):
|
||||
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
||||
mocker.patch('app.celery.tasks.send_sms_to_provider.apply_async')
|
||||
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
||||
|
||||
data = {
|
||||
@@ -25,7 +25,7 @@ def test_post_sms_contract(client, mocker, sample_template):
|
||||
|
||||
|
||||
def test_post_email_contract(client, mocker, sample_email_template):
|
||||
mocker.patch('app.celery.tasks.send_email.apply_async')
|
||||
mocker.patch('app.celery.tasks.send_email_to_provider.apply_async')
|
||||
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
||||
|
||||
data = {
|
||||
|
||||
72
tests/app/test_model.py
Normal file
72
tests/app/test_model.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from datetime import datetime
|
||||
|
||||
from app import DATETIME_FORMAT
|
||||
from app.models import Notification
|
||||
|
||||
|
||||
def test_should_build_notification_from_minimal_set_of_api_derived_params(notify_api):
|
||||
now = datetime.utcnow()
|
||||
|
||||
notification = {
|
||||
'template': 'template',
|
||||
'template_version': '1',
|
||||
'to': 'someone',
|
||||
'personalisation': {}
|
||||
}
|
||||
notification = Notification.from_api_request(
|
||||
created_at=now.strftime(DATETIME_FORMAT),
|
||||
notification=notification,
|
||||
notification_id="notification_id",
|
||||
service_id="service_id",
|
||||
notification_type='SMS',
|
||||
api_key_id='api_key_id',
|
||||
key_type='key_type'
|
||||
)
|
||||
assert notification.created_at == now
|
||||
assert notification.id == "notification_id"
|
||||
assert notification.template_id == 'template'
|
||||
assert notification.template_version == '1'
|
||||
assert not notification.job_row_number
|
||||
assert not notification.job_id
|
||||
assert notification.to == 'someone'
|
||||
assert notification.service_id == 'service_id'
|
||||
assert notification.status == 'created'
|
||||
assert not notification.personalisation
|
||||
assert notification.notification_type == 'SMS'
|
||||
assert notification.api_key_id == 'api_key_id'
|
||||
assert notification.key_type == 'key_type'
|
||||
|
||||
|
||||
def test_should_build_notification_from_full_set_of_api_derived_params(notify_api):
|
||||
now = datetime.utcnow()
|
||||
|
||||
notification = {
|
||||
'template': 'template',
|
||||
'template_version': '1',
|
||||
'to': 'someone',
|
||||
'personalisation': {'key': 'value'},
|
||||
'job': 'job_id',
|
||||
'row_number': 100
|
||||
}
|
||||
notification = Notification.from_api_request(
|
||||
created_at=now.strftime(DATETIME_FORMAT),
|
||||
notification=notification,
|
||||
notification_id="notification_id",
|
||||
service_id="service_id",
|
||||
notification_type='SMS',
|
||||
api_key_id='api_key_id',
|
||||
key_type='key_type'
|
||||
)
|
||||
assert notification.created_at == now
|
||||
assert notification.id == "notification_id"
|
||||
assert notification.template_id == 'template'
|
||||
assert notification.template_version == '1'
|
||||
assert notification.job_row_number == 100
|
||||
assert notification.job_id == 'job_id'
|
||||
assert notification.to == 'someone'
|
||||
assert notification.service_id == 'service_id'
|
||||
assert notification.status == 'created'
|
||||
assert notification.personalisation == {'key': 'value'}
|
||||
assert notification.notification_type == 'SMS'
|
||||
assert notification.api_key_id == 'api_key_id'
|
||||
assert notification.key_type == 'key_type'
|
||||
Reference in New Issue
Block a user