Merge branch 'main' into stvnrlly-paperless-api

This commit is contained in:
stvnrlly
2023-02-06 12:28:10 -05:00
87 changed files with 2484 additions and 2087 deletions

View File

@@ -53,7 +53,6 @@ from tests.app.db import (
)
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_should_by_able_to_update_status_by_reference(sample_email_template, ses_provider):
data = _notification_json(sample_email_template, status='sending')
@@ -69,8 +68,7 @@ def test_should_by_able_to_update_status_by_reference(sample_email_template, ses
assert Notification.query.get(notification.id).status == 'delivered'
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_should_by_able_to_update_status_by_id(sample_template, sample_job, mmg_provider):
def test_should_by_able_to_update_status_by_id(sample_template, sample_job, sns_provider):
with freeze_time('2000-01-01 12:00:00'):
data = _notification_json(sample_template, job_id=sample_job.id, status='sending')
notification = Notification(**data)
@@ -107,7 +105,6 @@ def test_should_not_update_status_by_reference_if_not_sending_and_does_not_updat
assert sample_job == Job.query.get(notification.job_id)
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_should_update_status_by_id_if_created(sample_template, sample_notification):
assert Notification.query.get(sample_notification.id).status == 'created'
updated = update_notification_status_by_id(sample_notification.id, 'failed')
@@ -115,7 +112,6 @@ def test_should_update_status_by_id_if_created(sample_template, sample_notificat
assert updated.status == 'failed'
@pytest.mark.skip(reason="Needs updating for TTS: Remove letters")
def test_should_update_status_by_id_if_pending_virus_check(sample_letter_template):
notification = create_notification(template=sample_letter_template, status='pending-virus-check')
assert Notification.query.get(notification.id).status == 'pending-virus-check'
@@ -124,7 +120,6 @@ def test_should_update_status_by_id_if_pending_virus_check(sample_letter_templat
assert updated.status == 'cancelled'
@pytest.mark.skip(reason="Needs updating for TTS: Remove letters")
def test_should_update_status_of_international_letter_to_cancelled(sample_letter_template):
notification = create_notification(
template=sample_letter_template,
@@ -136,13 +131,12 @@ def test_should_update_status_of_international_letter_to_cancelled(sample_letter
assert Notification.query.get(notification.id).status == 'cancelled'
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_should_update_status_by_id_and_set_sent_by(sample_template):
notification = create_notification(template=sample_template, status='sending')
updated = update_notification_status_by_id(notification.id, 'delivered', sent_by='mmg')
updated = update_notification_status_by_id(notification.id, 'delivered', sent_by='sns')
assert updated.status == 'delivered'
assert updated.sent_by == 'mmg'
assert updated.sent_by == 'sns'
def test_should_not_update_status_by_reference_if_from_country_with_no_delivery_receipts(sample_template):
@@ -186,7 +180,6 @@ def test_should_not_update_status_by_id_if_sent_to_country_with_carrier_delivery
assert notification.status == NOTIFICATION_SENT
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_should_not_update_status_by_id_if_sent_to_country_with_delivery_receipts(sample_template):
notification = create_notification(
sample_template,
@@ -209,7 +202,6 @@ def test_should_not_update_status_by_reference_if_not_sending(sample_template):
assert not updated
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_should_by_able_to_update_status_by_id_from_pending_to_delivered(sample_template, sample_job):
notification = create_notification(template=sample_template, job=sample_job, status='sending')
@@ -220,7 +212,6 @@ def test_should_by_able_to_update_status_by_id_from_pending_to_delivered(sample_
assert Notification.query.get(notification.id).status == 'delivered'
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_should_by_able_to_update_status_by_id_from_pending_to_temporary_failure(sample_template, sample_job):
notification = create_notification(template=sample_template, job=sample_job, status='sending', sent_by='sns')
@@ -232,7 +223,6 @@ def test_should_by_able_to_update_status_by_id_from_pending_to_temporary_failure
assert Notification.query.get(notification.id).status == 'temporary-failure'
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_should_by_able_to_update_status_by_id_from_sending_to_permanent_failure(sample_template, sample_job):
data = _notification_json(sample_template, job_id=sample_job.id, status='sending')
notification = Notification(**data)
@@ -246,7 +236,6 @@ def test_should_by_able_to_update_status_by_id_from_sending_to_permanent_failure
assert Notification.query.get(notification.id).status == 'permanent-failure'
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_should_not_update_status_once_notification_status_is_delivered(
sample_email_template):
notification = create_notification(template=sample_email_template, status='sending')
@@ -372,7 +361,7 @@ def test_update_notification_with_research_mode_service_does_not_create_or_updat
assert NotificationHistory.query.count() == 0
def test_not_save_notification_and_not_create_stats_on_commit_error(sample_template, sample_job, mmg_provider):
def test_not_save_notification_and_not_create_stats_on_commit_error(sample_template, sample_job, sns_provider):
random_id = str(uuid.uuid4())
assert Notification.query.count() == 0
@@ -386,7 +375,7 @@ def test_not_save_notification_and_not_create_stats_on_commit_error(sample_templ
assert Job.query.get(sample_job.id).notifications_sent == 0
def test_save_notification_and_increment_job(sample_template, sample_job, mmg_provider):
def test_save_notification_and_increment_job(sample_template, sample_job, sns_provider):
assert Notification.query.count() == 0
data = _notification_json(sample_template, job_id=sample_job.id)
@@ -409,7 +398,7 @@ def test_save_notification_and_increment_job(sample_template, sample_job, mmg_pr
assert Notification.query.count() == 2
def test_save_notification_and_increment_correct_job(sample_template, mmg_provider):
def test_save_notification_and_increment_correct_job(sample_template, sns_provider):
job_1 = create_job(sample_template)
job_2 = create_job(sample_template)
@@ -432,7 +421,7 @@ def test_save_notification_and_increment_correct_job(sample_template, mmg_provid
assert job_1.id != job_2.id
def test_save_notification_with_no_job(sample_template, mmg_provider):
def test_save_notification_with_no_job(sample_template, sns_provider):
assert Notification.query.count() == 0
data = _notification_json(sample_template)
@@ -1091,16 +1080,14 @@ def test_dao_get_notifications_by_reference_escapes_special_character(
@pytest.mark.parametrize('search_term', [
'001',
'100',
'09001',
'077009001',
'07700 9001',
'(0)7700 9001',
'4477009001',
'+4477009001',
pytest.param('+44077009001', marks=pytest.mark.skip(reason='No easy way to normalise this')),
pytest.param('+44(0)77009001', marks=pytest.mark.skip(reason='No easy way to normalise this')),
'309',
'530',
'8675309',
'202867',
'202 867',
'202-867-5309',
'2028675309',
'+12028675309',
])
def test_dao_get_notifications_by_recipient_matches_partial_phone_numbers(
sample_template,
@@ -1109,13 +1096,13 @@ def test_dao_get_notifications_by_recipient_matches_partial_phone_numbers(
notification_1 = create_notification(
template=sample_template,
to_field='+447700900100',
normalised_to='447700900100',
to_field='202-867-5309',
normalised_to='+12028675309',
)
notification_2 = create_notification(
template=sample_template,
to_field='+447700900200',
normalised_to='447700900200',
to_field='202-678-5000',
normalised_to='+12026785000',
)
results = dao_get_notifications_by_recipient_or_reference(
notification_1.service_id, search_term, notification_type='sms'
@@ -1167,7 +1154,7 @@ def test_dao_get_notifications_by_recipient_ignores_spaces(sample_template):
@pytest.mark.parametrize('phone_search', (
'077', '7-7', '+44(0)7711 111111'
'202', '7-5', '+1 (202) 867-5309'
))
@pytest.mark.parametrize('email_search', (
'example', 'eXaMpLe',
@@ -1180,9 +1167,9 @@ def test_dao_get_notifications_by_recipient_searches_across_notification_types(
service = create_service()
sms_template = create_template(service=service)
email_template = create_template(service=service, template_type='email')
sms = create_notification(template=sms_template, to_field='07711111111', normalised_to='447711111111')
sms = create_notification(template=sms_template, to_field='202-867-5309', normalised_to='+12028675309')
email = create_notification(
template=email_template, to_field='077@example.com', normalised_to='077@example.com'
template=email_template, to_field='202@example.com', normalised_to='202@example.com'
)
results = dao_get_notifications_by_recipient_or_reference(
@@ -1197,7 +1184,7 @@ def test_dao_get_notifications_by_recipient_searches_across_notification_types(
assert len(results.items) == 1
assert results.items[0].id == email.id
results = dao_get_notifications_by_recipient_or_reference(service.id, '77')
results = dao_get_notifications_by_recipient_or_reference(service.id, '202')
assert len(results.items) == 2
assert results.items[0].id == email.id
assert results.items[1].id == sms.id