mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Clean up more mmg and firetext references
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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,30 +174,26 @@ 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
|
||||
@@ -242,27 +238,24 @@ 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.skip(reason="Reenable if/when we add a second SMS provider")
|
||||
@pytest.mark.parametrize('existing_mmg, existing_firetext, new_mmg, new_firetext', [
|
||||
(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
|
||||
@@ -298,13 +291,11 @@ def test_adjust_provider_priority_back_to_resting_points_does_nothing_if_theyre_
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user