|
|
|
|
@@ -109,7 +109,7 @@ def test_should_process_sms_job(sample_job, mocker):
|
|
|
|
|
mocker.patch('app.celery.tasks.s3.get_job_and_metadata_from_s3',
|
|
|
|
|
return_value=(load_example_csv('sms'), {'sender_id': None}))
|
|
|
|
|
mocker.patch('app.celery.tasks.save_sms.apply_async')
|
|
|
|
|
mocker.patch('app.encryption.sign', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.celery.tasks.create_uuid', return_value="uuid")
|
|
|
|
|
|
|
|
|
|
process_job(sample_job.id)
|
|
|
|
|
@@ -117,11 +117,11 @@ def test_should_process_sms_job(sample_job, mocker):
|
|
|
|
|
service_id=str(sample_job.service.id),
|
|
|
|
|
job_id=str(sample_job.id)
|
|
|
|
|
)
|
|
|
|
|
assert encryption.sign.call_args[0][0]['to'] == '+441234123123'
|
|
|
|
|
assert encryption.sign.call_args[0][0]['template'] == str(sample_job.template.id)
|
|
|
|
|
assert encryption.sign.call_args[0][0]['template_version'] == sample_job.template.version
|
|
|
|
|
assert encryption.sign.call_args[0][0]['personalisation'] == {'phonenumber': '+441234123123'}
|
|
|
|
|
assert encryption.sign.call_args[0][0]['row_number'] == 0
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['to'] == '+441234123123'
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['template'] == str(sample_job.template.id)
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['template_version'] == sample_job.template.version
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['personalisation'] == {'phonenumber': '+441234123123'}
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['row_number'] == 0
|
|
|
|
|
tasks.save_sms.apply_async.assert_called_once_with(
|
|
|
|
|
(str(sample_job.service_id),
|
|
|
|
|
"uuid",
|
|
|
|
|
@@ -137,7 +137,7 @@ def test_should_process_sms_job_with_sender_id(sample_job, mocker, fake_uuid):
|
|
|
|
|
mocker.patch('app.celery.tasks.s3.get_job_and_metadata_from_s3',
|
|
|
|
|
return_value=(load_example_csv('sms'), {'sender_id': fake_uuid}))
|
|
|
|
|
mocker.patch('app.celery.tasks.save_sms.apply_async')
|
|
|
|
|
mocker.patch('app.encryption.sign', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.celery.tasks.create_uuid', return_value="uuid")
|
|
|
|
|
|
|
|
|
|
process_job(sample_job.id, sender_id=fake_uuid)
|
|
|
|
|
@@ -211,7 +211,7 @@ def test_should_process_job_if_send_limits_are_not_exceeded(
|
|
|
|
|
mocker.patch('app.celery.tasks.s3.get_job_and_metadata_from_s3',
|
|
|
|
|
return_value=(load_example_csv('multiple_email'), {"sender_id": None}))
|
|
|
|
|
mocker.patch('app.celery.tasks.save_email.apply_async')
|
|
|
|
|
mocker.patch('app.encryption.sign', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.celery.tasks.create_uuid', return_value="uuid")
|
|
|
|
|
mocker.patch('app.celery.tasks.check_service_over_daily_message_limit', return_value=0)
|
|
|
|
|
process_job(job.id)
|
|
|
|
|
@@ -255,7 +255,7 @@ def test_should_process_email_job(email_job_with_placeholders, mocker):
|
|
|
|
|
"""
|
|
|
|
|
mocker.patch('app.celery.tasks.s3.get_job_and_metadata_from_s3', return_value=(email_csv, {"sender_id": None}))
|
|
|
|
|
mocker.patch('app.celery.tasks.save_email.apply_async')
|
|
|
|
|
mocker.patch('app.encryption.sign', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.celery.tasks.create_uuid', return_value="uuid")
|
|
|
|
|
|
|
|
|
|
process_job(email_job_with_placeholders.id)
|
|
|
|
|
@@ -264,10 +264,10 @@ def test_should_process_email_job(email_job_with_placeholders, mocker):
|
|
|
|
|
service_id=str(email_job_with_placeholders.service.id),
|
|
|
|
|
job_id=str(email_job_with_placeholders.id)
|
|
|
|
|
)
|
|
|
|
|
assert encryption.sign.call_args[0][0]['to'] == 'test@test.com'
|
|
|
|
|
assert encryption.sign.call_args[0][0]['template'] == str(email_job_with_placeholders.template.id)
|
|
|
|
|
assert encryption.sign.call_args[0][0]['template_version'] == email_job_with_placeholders.template.version
|
|
|
|
|
assert encryption.sign.call_args[0][0]['personalisation'] == {'emailaddress': 'test@test.com', 'name': 'foo'}
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['to'] == 'test@test.com'
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['template'] == str(email_job_with_placeholders.template.id)
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['template_version'] == email_job_with_placeholders.template.version
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['personalisation'] == {'emailaddress': 'test@test.com', 'name': 'foo'}
|
|
|
|
|
tasks.save_email.apply_async.assert_called_once_with(
|
|
|
|
|
(
|
|
|
|
|
str(email_job_with_placeholders.service_id),
|
|
|
|
|
@@ -287,7 +287,7 @@ def test_should_process_email_job_with_sender_id(email_job_with_placeholders, mo
|
|
|
|
|
"""
|
|
|
|
|
mocker.patch('app.celery.tasks.s3.get_job_and_metadata_from_s3', return_value=(email_csv, {"sender_id": fake_uuid}))
|
|
|
|
|
mocker.patch('app.celery.tasks.save_email.apply_async')
|
|
|
|
|
mocker.patch('app.encryption.sign', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.celery.tasks.create_uuid', return_value="uuid")
|
|
|
|
|
|
|
|
|
|
process_job(email_job_with_placeholders.id, sender_id=fake_uuid)
|
|
|
|
|
@@ -341,7 +341,7 @@ def test_should_process_all_sms_job(sample_job_with_placeholdered_template,
|
|
|
|
|
mocker.patch('app.celery.tasks.s3.get_job_and_metadata_from_s3',
|
|
|
|
|
return_value=(load_example_csv('multiple_sms'), {"sender_id": None}))
|
|
|
|
|
mocker.patch('app.celery.tasks.save_sms.apply_async')
|
|
|
|
|
mocker.patch('app.encryption.sign', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
|
|
|
|
mocker.patch('app.celery.tasks.create_uuid', return_value="uuid")
|
|
|
|
|
|
|
|
|
|
process_job(sample_job_with_placeholdered_template.id)
|
|
|
|
|
@@ -350,11 +350,11 @@ def test_should_process_all_sms_job(sample_job_with_placeholdered_template,
|
|
|
|
|
service_id=str(sample_job_with_placeholdered_template.service.id),
|
|
|
|
|
job_id=str(sample_job_with_placeholdered_template.id)
|
|
|
|
|
)
|
|
|
|
|
assert encryption.sign.call_args[0][0]['to'] == '+441234123120'
|
|
|
|
|
assert encryption.sign.call_args[0][0]['template'] == str(sample_job_with_placeholdered_template.template.id)
|
|
|
|
|
assert encryption.sign.call_args[0][0][
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['to'] == '+441234123120'
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['template'] == str(sample_job_with_placeholdered_template.template.id)
|
|
|
|
|
assert encryption.encrypt.call_args[0][0][
|
|
|
|
|
'template_version'] == sample_job_with_placeholdered_template.template.version # noqa
|
|
|
|
|
assert encryption.sign.call_args[0][0]['personalisation'] == {'phonenumber': '+441234123120', 'name': 'chris'}
|
|
|
|
|
assert encryption.encrypt.call_args[0][0]['personalisation'] == {'phonenumber': '+441234123120', 'name': 'chris'}
|
|
|
|
|
assert tasks.save_sms.apply_async.call_count == 10
|
|
|
|
|
job = jobs_dao.dao_get_job_by_id(sample_job_with_placeholdered_template.id)
|
|
|
|
|
assert job.job_status == 'finished'
|
|
|
|
|
@@ -374,7 +374,7 @@ def test_should_process_all_sms_job(sample_job_with_placeholdered_template,
|
|
|
|
|
def test_process_row_sends_letter_task(template_type, research_mode, expected_function, expected_queue, mocker):
|
|
|
|
|
mocker.patch('app.celery.tasks.create_uuid', return_value='noti_uuid')
|
|
|
|
|
task_mock = mocker.patch('app.celery.tasks.{}.apply_async'.format(expected_function))
|
|
|
|
|
encrypt_mock = mocker.patch('app.celery.tasks.encryption.sign')
|
|
|
|
|
encrypt_mock = mocker.patch('app.celery.tasks.encryption.encrypt')
|
|
|
|
|
template = Mock(id='template_id', template_type=template_type)
|
|
|
|
|
job = Mock(id='job_id', template_version='temp_vers')
|
|
|
|
|
service = Mock(id='service_id', research_mode=research_mode)
|
|
|
|
|
@@ -417,7 +417,7 @@ def test_process_row_sends_letter_task(template_type, research_mode, expected_fu
|
|
|
|
|
def test_process_row_when_sender_id_is_provided(mocker, fake_uuid):
|
|
|
|
|
mocker.patch('app.celery.tasks.create_uuid', return_value='noti_uuid')
|
|
|
|
|
task_mock = mocker.patch('app.celery.tasks.save_sms.apply_async')
|
|
|
|
|
encrypt_mock = mocker.patch('app.celery.tasks.encryption.sign')
|
|
|
|
|
encrypt_mock = mocker.patch('app.celery.tasks.encryption.encrypt')
|
|
|
|
|
template = Mock(id='template_id', template_type=SMS_TYPE)
|
|
|
|
|
job = Mock(id='job_id', template_version='temp_vers')
|
|
|
|
|
service = Mock(id='service_id', research_mode=False)
|
|
|
|
|
@@ -460,7 +460,7 @@ def test_should_send_template_to_correct_sms_task_and_persist(sample_template_wi
|
|
|
|
|
save_sms(
|
|
|
|
|
sample_template_with_placeholders.service_id,
|
|
|
|
|
uuid.uuid4(),
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
@@ -473,7 +473,6 @@ def test_should_send_template_to_correct_sms_task_and_persist(sample_template_wi
|
|
|
|
|
assert not persisted_notification.sent_by
|
|
|
|
|
assert not persisted_notification.job_id
|
|
|
|
|
assert persisted_notification.personalisation == {'name': 'Jo'}
|
|
|
|
|
assert persisted_notification._personalisation == encryption.sign({"name": "Jo"})
|
|
|
|
|
assert persisted_notification.notification_type == 'sms'
|
|
|
|
|
mocked_deliver_sms.assert_called_once_with(
|
|
|
|
|
[str(persisted_notification.id)],
|
|
|
|
|
@@ -495,7 +494,7 @@ def test_should_put_save_sms_task_in_research_mode_queue_if_research_mode_servic
|
|
|
|
|
save_sms(
|
|
|
|
|
template.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
provider_tasks.deliver_sms.apply_async.assert_called_once_with(
|
|
|
|
|
@@ -514,7 +513,7 @@ def test_should_save_sms_if_restricted_service_and_valid_number(notify_db_sessio
|
|
|
|
|
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
|
|
|
|
|
|
|
|
|
notification_id = uuid.uuid4()
|
|
|
|
|
encrypt_notification = encryption.sign(notification)
|
|
|
|
|
encrypt_notification = encryption.encrypt(notification)
|
|
|
|
|
save_sms(
|
|
|
|
|
service.id,
|
|
|
|
|
notification_id,
|
|
|
|
|
@@ -550,7 +549,7 @@ def test_save_email_should_save_default_email_reply_to_text_on_notification(noti
|
|
|
|
|
save_email(
|
|
|
|
|
service.id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
@@ -568,7 +567,7 @@ def test_save_sms_should_save_default_smm_sender_notification_reply_to_text_on(n
|
|
|
|
|
save_sms(
|
|
|
|
|
service.id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
@@ -587,7 +586,7 @@ def test_should_not_save_sms_if_restricted_service_and_invalid_number(notify_db_
|
|
|
|
|
save_sms(
|
|
|
|
|
service.id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
assert provider_tasks.deliver_sms.apply_async.called is False
|
|
|
|
|
assert Notification.query.count() == 0
|
|
|
|
|
@@ -603,7 +602,7 @@ def test_should_not_save_email_if_restricted_service_and_invalid_email_address(n
|
|
|
|
|
save_email(
|
|
|
|
|
service.id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert Notification.query.count() == 0
|
|
|
|
|
@@ -625,7 +624,7 @@ def test_should_put_save_email_task_in_research_mode_queue_if_research_mode_serv
|
|
|
|
|
save_email(
|
|
|
|
|
template.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
@@ -648,7 +647,7 @@ def test_should_save_sms_template_to_and_persist_with_job_id(sample_job, mocker)
|
|
|
|
|
save_sms(
|
|
|
|
|
sample_job.service.id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
assert persisted_notification.to == '+447234123123'
|
|
|
|
|
@@ -685,7 +684,7 @@ def test_should_not_save_sms_if_team_key_and_recipient_not_in_team(notify_db_ses
|
|
|
|
|
save_sms(
|
|
|
|
|
service.id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
assert provider_tasks.deliver_sms.apply_async.called is False
|
|
|
|
|
assert Notification.query.count() == 0
|
|
|
|
|
@@ -708,7 +707,7 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh
|
|
|
|
|
save_email(
|
|
|
|
|
sample_email_template_with_placeholders.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
@@ -721,7 +720,6 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh
|
|
|
|
|
assert not persisted_notification.sent_by
|
|
|
|
|
assert persisted_notification.job_row_number == 1
|
|
|
|
|
assert persisted_notification.personalisation == {'name': 'Jo'}
|
|
|
|
|
assert persisted_notification._personalisation == encryption.sign({"name": "Jo"})
|
|
|
|
|
assert persisted_notification.api_key_id is None
|
|
|
|
|
assert persisted_notification.key_type == KEY_TYPE_NORMAL
|
|
|
|
|
assert persisted_notification.notification_type == 'email'
|
|
|
|
|
@@ -747,7 +745,7 @@ def test_save_email_should_use_template_version_from_job_not_latest(sample_email
|
|
|
|
|
save_email(
|
|
|
|
|
sample_email_template.service_id,
|
|
|
|
|
uuid.uuid4(),
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
@@ -773,7 +771,7 @@ def test_should_use_email_template_subject_placeholders(sample_email_template_wi
|
|
|
|
|
save_email(
|
|
|
|
|
sample_email_template_with_placeholders.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
assert persisted_notification.to == 'my_email@my_email.com'
|
|
|
|
|
@@ -802,7 +800,7 @@ def test_save_email_uses_the_reply_to_text_when_provided(sample_email_template,
|
|
|
|
|
save_email(
|
|
|
|
|
sample_email_template.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
sender_id=other_email_reply_to.id,
|
|
|
|
|
)
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
@@ -821,7 +819,7 @@ def test_save_email_uses_the_default_reply_to_text_if_sender_id_is_none(sample_e
|
|
|
|
|
save_email(
|
|
|
|
|
sample_email_template.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
sender_id=None,
|
|
|
|
|
)
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
@@ -839,7 +837,7 @@ def test_should_use_email_template_and_persist_without_personalisation(sample_em
|
|
|
|
|
save_email(
|
|
|
|
|
sample_email_template.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
assert persisted_notification.to == 'my_email@my_email.com'
|
|
|
|
|
@@ -870,7 +868,7 @@ def test_save_sms_should_go_to_retry_queue_if_database_errors(sample_template, m
|
|
|
|
|
save_sms(
|
|
|
|
|
sample_template.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
assert provider_tasks.deliver_sms.apply_async.called is False
|
|
|
|
|
tasks.save_sms.retry.assert_called_with(exc=expected_exception, queue="retry-tasks")
|
|
|
|
|
@@ -893,7 +891,7 @@ def test_save_email_should_go_to_retry_queue_if_database_errors(sample_email_tem
|
|
|
|
|
save_email(
|
|
|
|
|
sample_email_template.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
assert not provider_tasks.deliver_email.apply_async.called
|
|
|
|
|
tasks.save_email.retry.assert_called_with(exc=expected_exception, queue="retry-tasks")
|
|
|
|
|
@@ -911,7 +909,7 @@ def test_save_email_does_not_send_duplicate_and_does_not_put_in_retry_queue(samp
|
|
|
|
|
save_email(
|
|
|
|
|
sample_notification.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(json),
|
|
|
|
|
encryption.encrypt(json),
|
|
|
|
|
)
|
|
|
|
|
assert Notification.query.count() == 1
|
|
|
|
|
assert not deliver_email.called
|
|
|
|
|
@@ -928,7 +926,7 @@ def test_save_sms_does_not_send_duplicate_and_does_not_put_in_retry_queue(sample
|
|
|
|
|
save_sms(
|
|
|
|
|
sample_notification.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(json),
|
|
|
|
|
encryption.encrypt(json),
|
|
|
|
|
)
|
|
|
|
|
assert Notification.query.count() == 1
|
|
|
|
|
assert not deliver_sms.called
|
|
|
|
|
@@ -998,7 +996,7 @@ def test_save_letter_saves_letter_to_database(
|
|
|
|
|
save_letter(
|
|
|
|
|
job.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification_json),
|
|
|
|
|
encryption.encrypt(notification_json),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
notification_db = Notification.query.one()
|
|
|
|
|
@@ -1042,7 +1040,7 @@ def test_save_letter_saves_letter_to_database_with_correct_postage(
|
|
|
|
|
save_letter(
|
|
|
|
|
letter_job.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification_json),
|
|
|
|
|
encryption.encrypt(notification_json),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
notification_db = Notification.query.one()
|
|
|
|
|
@@ -1075,7 +1073,7 @@ def test_save_letter_saves_letter_to_database_with_correct_client_reference(
|
|
|
|
|
save_letter(
|
|
|
|
|
letter_job.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification_json),
|
|
|
|
|
encryption.encrypt(notification_json),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
notification_db = Notification.query.one()
|
|
|
|
|
@@ -1100,7 +1098,7 @@ def test_save_letter_saves_letter_to_database_with_formatted_postcode(mocker, no
|
|
|
|
|
save_letter(
|
|
|
|
|
letter_job.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification_json),
|
|
|
|
|
encryption.encrypt(notification_json),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
notification_db = Notification.query.one()
|
|
|
|
|
@@ -1139,7 +1137,7 @@ def test_save_letter_saves_letter_to_database_right_reply_to(mocker, notify_db_s
|
|
|
|
|
save_letter(
|
|
|
|
|
job.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification_json),
|
|
|
|
|
encryption.encrypt(notification_json),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
notification_db = Notification.query.one()
|
|
|
|
|
@@ -1201,7 +1199,7 @@ def test_save_letter_uses_template_reply_to_text(mocker, notify_db_session):
|
|
|
|
|
save_letter(
|
|
|
|
|
job.service_id,
|
|
|
|
|
uuid.uuid4(),
|
|
|
|
|
encryption.sign(notification_json),
|
|
|
|
|
encryption.encrypt(notification_json),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
notification_db = Notification.query.one()
|
|
|
|
|
@@ -1219,7 +1217,7 @@ def test_save_sms_uses_sms_sender_reply_to_text(mocker, notify_db_session):
|
|
|
|
|
save_sms(
|
|
|
|
|
service.id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
persisted_notification = Notification.query.one()
|
|
|
|
|
@@ -1238,7 +1236,7 @@ def test_save_sms_uses_non_default_sms_sender_reply_to_text_if_provided(mocker,
|
|
|
|
|
save_sms(
|
|
|
|
|
service.id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
sender_id=new_sender.id,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -1276,7 +1274,7 @@ def test_save_letter_sets_delivered_letters_as_pdf_permission_in_research_mode_i
|
|
|
|
|
save_letter(
|
|
|
|
|
sample_letter_job.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification_json),
|
|
|
|
|
encryption.encrypt(notification_json),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
notification = Notification.query.filter(Notification.id == notification_id).one()
|
|
|
|
|
@@ -1314,7 +1312,7 @@ def test_save_letter_calls_create_fake_response_for_letters_in_research_mode_on_
|
|
|
|
|
save_letter(
|
|
|
|
|
sample_letter_job.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification_json),
|
|
|
|
|
encryption.encrypt(notification_json),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mock_create_fake_letter_response_file.assert_called_once_with(
|
|
|
|
|
@@ -1345,7 +1343,7 @@ def test_save_letter_calls_get_pdf_for_templated_letter_task_not_in_research(
|
|
|
|
|
save_letter(
|
|
|
|
|
sample_letter_job.service_id,
|
|
|
|
|
notification_id,
|
|
|
|
|
encryption.sign(notification_json),
|
|
|
|
|
encryption.encrypt(notification_json),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert mock_create_letters_pdf.called
|
|
|
|
|
@@ -1843,7 +1841,7 @@ def test_save_api_email_or_sms(mocker, sample_service, notification_type):
|
|
|
|
|
data.update({"to": "+447700900855"})
|
|
|
|
|
expected_queue = QueueNames.SEND_SMS
|
|
|
|
|
|
|
|
|
|
encrypted = encryption.sign(
|
|
|
|
|
encrypted = encryption.encrypt(
|
|
|
|
|
data
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -1890,7 +1888,7 @@ def test_save_api_email_dont_retry_if_notification_already_exists(sample_service
|
|
|
|
|
data.update({"to": "+447700900855"})
|
|
|
|
|
expected_queue = QueueNames.SEND_SMS
|
|
|
|
|
|
|
|
|
|
encrypted = encryption.sign(
|
|
|
|
|
encrypted = encryption.encrypt(
|
|
|
|
|
data
|
|
|
|
|
)
|
|
|
|
|
assert len(Notification.query.all()) == 0
|
|
|
|
|
@@ -1953,7 +1951,7 @@ def test_save_tasks_use_cached_service_and_template(
|
|
|
|
|
task_function(
|
|
|
|
|
service.id,
|
|
|
|
|
uuid.uuid4(),
|
|
|
|
|
encryption.sign(notification),
|
|
|
|
|
encryption.encrypt(notification),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# We talk to the database once for the service and once for the
|
|
|
|
|
@@ -1995,7 +1993,7 @@ def test_save_api_tasks_use_cache(
|
|
|
|
|
api_key = create_api_key(service=template.service)
|
|
|
|
|
|
|
|
|
|
def create_encrypted_notification():
|
|
|
|
|
return encryption.sign({
|
|
|
|
|
return encryption.encrypt({
|
|
|
|
|
"to": recipient,
|
|
|
|
|
"id": str(uuid.uuid4()),
|
|
|
|
|
"template_id": str(template.id),
|
|
|
|
|
|