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

View File

@@ -174,14 +174,14 @@ def test_fetch_billing_data_for_day_is_grouped_by_service(notify_db_session):
def test_fetch_billing_data_for_day_is_grouped_by_provider(notify_db_session):
service = create_service()
template = create_template(service=service)
create_notification(template=template, status='delivered', sent_by='mmg')
create_notification(template=template, status='delivered', sent_by='firetext')
create_notification(template=template, status='delivered', sent_by='sns')
create_notification(template=template, status='delivered', sent_by='sns')
today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today.date())
assert len(results) == 2
assert results[0].notifications_sent == 1
assert results[1].notifications_sent == 1
assert len(results) == 1
assert results[0].notifications_sent == 2
# assert results[1].notifications_sent == 1
def test_fetch_billing_data_for_day_is_grouped_by_rate_mulitplier(notify_db_session):

View File

@@ -23,7 +23,7 @@ from tests.conftest import set_config
@pytest.fixture(autouse=True)
def set_provider_resting_points(notify_api):
with set_config(notify_api, 'SMS_PROVIDER_RESTING_POINTS', {'mmg': 60, 'firetext': 40}):
with set_config(notify_api, 'SMS_PROVIDER_RESTING_POINTS', {'sns': 100}):
yield
@@ -69,11 +69,10 @@ def test_can_get_email_providers(notify_db_session):
assert all('email' == notification_type for notification_type in types)
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_should_not_error_if_any_provider_in_code_not_in_database(restore_provider_details):
ProviderDetails.query.filter_by(identifier='mmg').delete()
ProviderDetails.query.filter_by(identifier='sns').delete()
assert notification_provider_clients.get_sms_client('mmg')
assert notification_provider_clients.get_sms_client('sns')
@freeze_time('2000-01-01T00:00:00')
@@ -108,20 +107,22 @@ def test_update_adds_history(restore_provider_details):
def test_update_sms_provider_to_inactive_sets_inactive(restore_provider_details):
mmg = get_provider_details_by_identifier('mmg')
sns = get_provider_details_by_identifier('sns')
mmg.active = False
dao_update_provider_details(mmg)
sns.active = False
dao_update_provider_details(sns)
assert not mmg.active
assert not sns.active
@pytest.mark.parametrize('identifier, expected', [
('firetext', 'mmg'),
('mmg', 'firetext'),
('sns', 'other')
])
def test_get_alternative_sms_provider_returns_expected_provider(identifier, expected):
assert get_alternative_sms_provider(identifier) == expected
"""Currently always raises, as we only have SNS configured"""
with pytest.raises(Exception):
get_alternative_sms_provider(identifier)
# assert get_alternative_sms_provider(identifier) == expected
def test_get_alternative_sms_provider_fails_if_unrecognised():
@@ -133,38 +134,37 @@ def test_get_alternative_sms_provider_fails_if_unrecognised():
def test_adjust_provider_priority_sets_priority(
restore_provider_details,
notify_user,
mmg_provider,
sns_provider,
):
# need to update these manually to avoid triggering the `onupdate` clause of the updated_at column
ProviderDetails.query.filter(ProviderDetails.identifier == 'mmg').update({'updated_at': datetime.min})
ProviderDetails.query.filter(ProviderDetails.identifier == 'sns').update({'updated_at': datetime.min})
_adjust_provider_priority(mmg_provider, 50)
_adjust_provider_priority(sns_provider, 50)
assert mmg_provider.updated_at == datetime.utcnow()
assert mmg_provider.created_by.id == notify_user.id
assert mmg_provider.priority == 50
assert sns_provider.updated_at == datetime.utcnow()
assert sns_provider.created_by.id == notify_user.id
assert sns_provider.priority == 50
@pytest.mark.skip(reason="Needs updating for TTS: MMG removal")
@freeze_time('2016-01-01 00:30')
def test_adjust_provider_priority_adds_history(
restore_provider_details,
notify_user,
mmg_provider,
sns_provider,
):
# need to update these manually to avoid triggering the `onupdate` clause of the updated_at column
ProviderDetails.query.filter(ProviderDetails.identifier == 'mmg').update({'updated_at': datetime.min})
ProviderDetails.query.filter(ProviderDetails.identifier == 'sns').update({'updated_at': datetime.min})
old_provider_history_rows = ProviderDetailsHistory.query.filter(
ProviderDetailsHistory.id == mmg_provider.id
ProviderDetailsHistory.id == sns_provider.id
).order_by(
desc(ProviderDetailsHistory.version)
).all()
_adjust_provider_priority(mmg_provider, 50)
_adjust_provider_priority(sns_provider, 50)
updated_provider_history_rows = ProviderDetailsHistory.query.filter(
ProviderDetailsHistory.id == mmg_provider.id
ProviderDetailsHistory.id == sns_provider.id
).order_by(
desc(ProviderDetailsHistory.version)
).all()
@@ -174,42 +174,38 @@ def test_adjust_provider_priority_adds_history(
assert updated_provider_history_rows[0].priority == 50
@pytest.mark.skip(reason="Needs updating for TTS: MMG removal")
@freeze_time('2016-01-01 01:00')
def test_get_sms_providers_for_update_returns_providers(restore_provider_details):
sixty_one_minutes_ago = datetime(2015, 12, 31, 23, 59)
ProviderDetails.query.filter(ProviderDetails.identifier == 'mmg').update({'updated_at': sixty_one_minutes_ago})
ProviderDetails.query.filter(ProviderDetails.identifier == 'firetext').update({'updated_at': None})
ProviderDetails.query.filter(ProviderDetails.identifier == 'sns').update({'updated_at': None})
resp = _get_sms_providers_for_update(timedelta(hours=1))
assert {p.identifier for p in resp} == {'mmg', 'firetext'}
assert {p.identifier for p in resp} == {'sns'}
@pytest.mark.skip(reason="Needs updating for TTS: MMG removal")
@freeze_time('2016-01-01 01:00')
def test_get_sms_providers_for_update_returns_nothing_if_recent_updates(restore_provider_details):
fifty_nine_minutes_ago = datetime(2016, 1, 1, 0, 1)
ProviderDetails.query.filter(ProviderDetails.identifier == 'mmg').update({'updated_at': fifty_nine_minutes_ago})
ProviderDetails.query.filter(ProviderDetails.identifier == 'sns').update({'updated_at': fifty_nine_minutes_ago})
resp = _get_sms_providers_for_update(timedelta(hours=1))
assert not resp
@pytest.mark.skip(reason="Needs updating for TTS: MMG removal")
@pytest.mark.skip(reason="Reenable if/when we add a second SMS provider")
@pytest.mark.parametrize(['starting_priorities', 'expected_priorities'], [
({'mmg': 50, 'firetext': 50}, {'mmg': 40, 'firetext': 60}),
({'mmg': 0, 'firetext': 20}, {'mmg': 0, 'firetext': 30}), # lower bound respected
({'mmg': 50, 'firetext': 100}, {'mmg': 40, 'firetext': 100}), # upper bound respected
({'sns': 50, 'other': 50}, {'sns': 40, 'other': 60}),
({'sns': 0, 'other': 20}, {'sns': 0, 'other': 30}), # lower bound respected
({'sns': 50, 'other': 100}, {'sns': 40, 'other': 100}), # upper bound respected
# document what happens if they have unexpected values outside of the 0 - 100 range (due to manual setting from
# the admin app). the code never causes further issues, but sometimes doesn't actively reset the vaues to 0-100.
({'mmg': 150, 'firetext': 50}, {'mmg': 140, 'firetext': 60}),
({'mmg': 50, 'firetext': 150}, {'mmg': 40, 'firetext': 100}),
({'sns': 150, 'other': 50}, {'sns': 140, 'other': 60}),
({'sns': 50, 'other': 150}, {'sns': 40, 'other': 100}),
({'mmg': -100, 'firetext': 50}, {'mmg': 0, 'firetext': 60}),
({'mmg': 50, 'firetext': -100}, {'mmg': 40, 'firetext': -90}),
({'sns': -100, 'other': 50}, {'sns': 0, 'other': 60}),
({'sns': 50, 'other': -100}, {'sns': 40, 'other': -90}),
])
def test_reduce_sms_provider_priority_adjusts_provider_priorities(
mocker,
@@ -220,19 +216,19 @@ def test_reduce_sms_provider_priority_adjusts_provider_priorities(
):
mock_adjust = mocker.patch('app.dao.provider_details_dao._adjust_provider_priority')
mmg = get_provider_details_by_identifier('mmg')
firetext = get_provider_details_by_identifier('firetext')
sns = get_provider_details_by_identifier('sns')
other = get_provider_details_by_identifier('other')
mmg.priority = starting_priorities['mmg']
firetext.priority = starting_priorities['firetext']
sns.priority = starting_priorities['sns']
other.priority = starting_priorities['other']
# need to update these manually to avoid triggering the `onupdate` clause of the updated_at column
ProviderDetails.query.filter(ProviderDetails.notification_type == 'sms').update({'updated_at': datetime.min})
# switch away from mmg. currently both 50/50
dao_reduce_sms_provider_priority('mmg', time_threshold=timedelta(minutes=10))
# switch away from sns. currently both 50/50
dao_reduce_sms_provider_priority('sns', time_threshold=timedelta(minutes=10))
mock_adjust.assert_any_call(firetext, expected_priorities['firetext'])
mock_adjust.assert_any_call(mmg, expected_priorities['mmg'])
mock_adjust.assert_any_call(other, expected_priorities['other'])
mock_adjust.assert_any_call(sns, expected_priorities['sns'])
def test_reduce_sms_provider_priority_does_nothing_if_providers_have_recently_changed(
@@ -242,28 +238,25 @@ def test_reduce_sms_provider_priority_does_nothing_if_providers_have_recently_ch
mock_get_providers = mocker.patch('app.dao.provider_details_dao._get_sms_providers_for_update', return_value=[])
mock_adjust = mocker.patch('app.dao.provider_details_dao._adjust_provider_priority')
dao_reduce_sms_provider_priority('firetext', time_threshold=timedelta(minutes=5))
dao_reduce_sms_provider_priority('sns', time_threshold=timedelta(minutes=5))
mock_get_providers.assert_called_once_with(timedelta(minutes=5))
assert mock_adjust.called is False
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
def test_reduce_sms_provider_priority_does_nothing_if_there_is_only_one_active_provider(
mocker,
restore_provider_details,
):
firetext = get_provider_details_by_identifier('firetext')
firetext.active = False
mock_adjust = mocker.patch('app.dao.provider_details_dao._adjust_provider_priority')
dao_reduce_sms_provider_priority('firetext', time_threshold=timedelta(minutes=5))
dao_reduce_sms_provider_priority('sns', time_threshold=timedelta(minutes=5))
assert mock_adjust.called is False
@pytest.mark.parametrize('existing_mmg, existing_firetext, new_mmg, new_firetext', [
@pytest.mark.skip(reason="Reenable if/when we add a second SMS provider")
@pytest.mark.parametrize('existing_sns, existing_other, new_sns, new_other', [
(50, 50, 60, 40), # not just 50/50 - 60/40 specifically
(65, 35, 60, 40), # doesn't overshoot if there's less than 10 difference
(0, 100, 10, 90), # only adjusts by 10
@@ -272,39 +265,37 @@ def test_reduce_sms_provider_priority_does_nothing_if_there_is_only_one_active_p
def test_adjust_provider_priority_back_to_resting_points_updates_all_providers(
restore_provider_details,
mocker,
existing_mmg,
existing_firetext,
new_mmg,
new_firetext
existing_sns,
existing_other,
new_sns,
new_other
):
mmg = get_provider_details_by_identifier('mmg')
firetext = get_provider_details_by_identifier('firetext')
mmg.priority = existing_mmg
firetext.priority = existing_firetext
sns = get_provider_details_by_identifier('sns')
other = get_provider_details_by_identifier('other')
sns.priority = existing_sns
other.priority = existing_other
mock_adjust = mocker.patch('app.dao.provider_details_dao._adjust_provider_priority')
mock_get_providers = mocker.patch('app.dao.provider_details_dao._get_sms_providers_for_update', return_value=[
mmg, firetext
sns, other
])
dao_adjust_provider_priority_back_to_resting_points()
mock_get_providers.assert_called_once_with(timedelta(hours=1))
mock_adjust.assert_any_call(mmg, new_mmg)
mock_adjust.assert_any_call(firetext, new_firetext)
mock_adjust.assert_any_call(sns, new_sns)
mock_adjust.assert_any_call(other, new_other)
def test_adjust_provider_priority_back_to_resting_points_does_nothing_if_theyre_already_at_right_values(
restore_provider_details,
mocker,
):
mmg = get_provider_details_by_identifier('mmg')
firetext = get_provider_details_by_identifier('firetext')
mmg.priority = 60
firetext.priority = 40
sns = get_provider_details_by_identifier('sns')
sns.priority = 100
mock_adjust = mocker.patch('app.dao.provider_details_dao._adjust_provider_priority')
mocker.patch('app.dao.provider_details_dao._get_sms_providers_for_update', return_value=[mmg, firetext])
mocker.patch('app.dao.provider_details_dao._get_sms_providers_for_update', return_value=[sns])
dao_adjust_provider_priority_back_to_resting_points()
@@ -323,7 +314,6 @@ def test_adjust_provider_priority_back_to_resting_points_does_nothing_if_no_prov
assert mock_adjust.called is False
@pytest.mark.skip(reason="Needs updating for TTS: New SMS provider")
@freeze_time('2018-06-28 12:00')
def test_dao_get_provider_stats(notify_db_session):
service_1 = create_service(service_name='1')
@@ -331,34 +321,23 @@ def test_dao_get_provider_stats(notify_db_session):
sms_template_1 = create_template(service_1, 'sms')
sms_template_2 = create_template(service_2, 'sms')
create_ft_billing('2017-06-05', sms_template_2, provider='firetext', billable_unit=4)
create_ft_billing('2018-05-31', sms_template_1, provider='mmg', billable_unit=1)
create_ft_billing('2018-06-01', sms_template_1, provider='mmg',
rate_multiplier=2, billable_unit=1)
create_ft_billing('2018-06-03', sms_template_2, provider='firetext', billable_unit=4)
create_ft_billing('2018-06-15', sms_template_1, provider='firetext', billable_unit=1)
create_ft_billing('2018-06-28', sms_template_2, provider='mmg', billable_unit=2)
create_ft_billing('2017-06-05', sms_template_2, provider='sns', billable_unit=4)
create_ft_billing('2018-06-03', sms_template_2, provider='sns', billable_unit=4)
create_ft_billing('2018-06-15', sms_template_1, provider='sns', billable_unit=1)
results = dao_get_provider_stats()
assert len(results) > 0
ses = next(result for result in results if result.identifier == 'ses')
firetext = next(result for result in results if result.identifier == 'firetext')
mmg = next(result for result in results if result.identifier == 'mmg')
sns = next(result for result in results if result.identifier == 'sns')
assert ses.display_name == 'AWS SES'
assert ses.created_by_name is None
assert ses.current_month_billable_sms == 0
assert firetext.display_name == 'Firetext'
assert firetext.notification_type == 'sms'
assert firetext.supports_international is False
assert firetext.active is True
assert firetext.current_month_billable_sms == 5
assert mmg.identifier == 'mmg'
assert mmg.display_name == 'MMG'
assert mmg.supports_international is True
assert mmg.active is True
assert mmg.current_month_billable_sms == 4
assert sns.display_name == 'AWS SNS'
assert sns.notification_type == 'sms'
assert sns.supports_international is True
assert sns.active is True
assert sns.current_month_billable_sms == 5

View File

@@ -258,7 +258,7 @@ def test_should_add_user_to_service(notify_db_session):
name='Test User',
email_address='new_user@digital.cabinet-office.gov.uk',
password='password',
mobile_number='+447700900986'
mobile_number='+12028675309'
)
save_model_user(new_user, validated_email_access=True)
dao_add_user_to_service(service, new_user)
@@ -327,7 +327,7 @@ def test_should_remove_user_from_service(notify_db_session):
name='Test User',
email_address='new_user@digital.cabinet-office.gov.uk',
password='password',
mobile_number='+447700900986'
mobile_number='+12028675309'
)
save_model_user(new_user, validated_email_access=True)
dao_add_user_to_service(service, new_user)
@@ -428,7 +428,7 @@ def test_get_all_user_services_only_returns_services_user_has_access_to(notify_d
name='Test User',
email_address='new_user@digital.cabinet-office.gov.uk',
password='password',
mobile_number='+447700900986'
mobile_number='+12028675309'
)
save_model_user(new_user, validated_email_access=True)
dao_add_user_to_service(service_3, new_user)
@@ -486,7 +486,7 @@ def test_dao_fetch_live_services_data(sample_user):
assert results == [
{'service_id': mock.ANY, 'service_name': 'Sample service', 'organisation_name': 'test_org_1',
'organisation_type': 'federal', 'consent_to_research': None, 'contact_name': 'Test User',
'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+447700900986',
'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+12028675309',
'live_date': datetime(2014, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None,
'letter_volume_intent': None, 'sms_totals': 2, 'email_totals': 1, 'letter_totals': 1,
'free_sms_fragment_limit': 100},
@@ -498,7 +498,7 @@ def test_dao_fetch_live_services_data(sample_user):
'free_sms_fragment_limit': 200},
{'service_id': mock.ANY, 'service_name': 'second', 'organisation_name': None, 'consent_to_research': None,
'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk',
'contact_mobile': '+447700900986', 'live_date': datetime(2017, 4, 20, 10, 0), 'sms_volume_intent': None,
'contact_mobile': '+12028675309', 'live_date': datetime(2017, 4, 20, 10, 0), 'sms_volume_intent': None,
'organisation_type': None, 'email_volume_intent': None, 'letter_volume_intent': None,
'sms_totals': 0, 'email_totals': 0, 'letter_totals': 1,
'free_sms_fragment_limit': 300}
@@ -748,7 +748,7 @@ def test_add_existing_user_to_another_service_doesnot_change_old_permissions(not
name='Other Test User',
email_address='other_user@digital.cabinet-office.gov.uk',
password='password',
mobile_number='+447700900987'
mobile_number='+12028672000'
)
save_model_user(other_user, validated_email_access=True)
service_two = Service(name="service_two",

View File

@@ -37,11 +37,11 @@ from tests.app.db import (
@freeze_time('2020-01-28T12:00:00')
@pytest.mark.parametrize('phone_number', [
'+447700900986',
'+1-800-555-5555',
@pytest.mark.parametrize('phone_number, expected_phone_number', [
('2028675309', '+12028675309'),
('+1-800-555-5555', '+18005555555'),
])
def test_create_user(notify_db_session, phone_number):
def test_create_user(notify_db_session, phone_number, expected_phone_number):
email = 'notify@digital.cabinet-office.gov.uk'
data = {
'name': 'Test User',
@@ -55,7 +55,7 @@ def test_create_user(notify_db_session, phone_number):
user_query = User.query.first()
assert user_query.email_address == email
assert user_query.id == user.id
assert user_query.mobile_number == phone_number
assert user_query.mobile_number == expected_phone_number
assert user_query.email_access_validated_at == datetime.utcnow()
assert not user_query.platform_admin