mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 18:38:14 -04:00
Clean up more mmg and firetext references
This commit is contained in:
@@ -12,8 +12,7 @@ from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.models import NOTIFICATION_PENDING
|
||||
|
||||
sms_response_mapper = {
|
||||
# 'MMG': get_mmg_responses,
|
||||
# 'Firetext': get_firetext_responses,
|
||||
# 'SNS': get_sns_responses,
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-3
@@ -147,12 +147,11 @@ def purge_functional_test_data(user_email_prefix):
|
||||
|
||||
@notify_command(name='insert-inbound-numbers')
|
||||
@click.option('-f', '--file_name', required=True,
|
||||
help="""Full path of the file to upload, file is a contains inbound numbers,
|
||||
one number per line. The number must have the format of 07... not 447....""")
|
||||
help="""Full path of the file to upload, file is a contains inbound numbers, one number per line.""")
|
||||
def insert_inbound_numbers_from_file(file_name):
|
||||
print("Inserting inbound numbers from {}".format(file_name))
|
||||
with open(file_name) as file:
|
||||
sql = "insert into inbound_numbers values('{}', '{}', 'mmg', null, True, now(), null);"
|
||||
sql = "insert into inbound_numbers values('{}', '{}', 'sns', null, True, now(), null);"
|
||||
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
|
||||
@@ -104,7 +104,7 @@ def _update_notification_status(notification, status, provider_response=None):
|
||||
|
||||
|
||||
@autocommit
|
||||
def update_notification_status_by_id(notification_id, status, sent_by=None, detailed_status_code=None):
|
||||
def update_notification_status_by_id(notification_id, status, sent_by=None):
|
||||
notification = Notification.query.with_for_update().filter(Notification.id == notification_id).first()
|
||||
|
||||
if not notification:
|
||||
@@ -134,8 +134,7 @@ def update_notification_status_by_id(notification_id, status, sent_by=None, deta
|
||||
notification.sent_by = sent_by
|
||||
return _update_notification_status(
|
||||
notification=notification,
|
||||
status=status,
|
||||
detailed_status_code=detailed_status_code
|
||||
status=status
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -24,10 +24,8 @@ def get_provider_details_by_identifier(identifier):
|
||||
|
||||
|
||||
def get_alternative_sms_provider(identifier):
|
||||
if identifier == 'firetext':
|
||||
return 'mmg'
|
||||
elif identifier == 'mmg':
|
||||
return 'firetext'
|
||||
if identifier == 'sns':
|
||||
raise Exception("No alternative SMS providers currently available")
|
||||
raise ValueError('Unrecognised sms provider {}'.format(identifier))
|
||||
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ def send_email_to_provider(notification):
|
||||
technical_failure(notification=notification)
|
||||
return
|
||||
if notification.status == 'created':
|
||||
provider = provider_to_use(EMAIL_TYPE)
|
||||
provider = provider_to_use(EMAIL_TYPE, False)
|
||||
|
||||
template_dict = SerialisedTemplate.from_id_and_service_id(
|
||||
template_id=notification.template_id, service_id=service.id, version=notification.template_version
|
||||
@@ -175,12 +175,10 @@ provider_cache = TTLCache(maxsize=8, ttl=10)
|
||||
|
||||
@cached(cache=provider_cache)
|
||||
def provider_to_use(notification_type, international=True):
|
||||
international = False # TODO: remove or resolve the functionality of this flag
|
||||
# TODO rip firetext and mmg out of early migrations and clean up the expression below
|
||||
active_providers = [
|
||||
p for p in get_provider_details_by_notification_type(
|
||||
notification_type, international
|
||||
) if p.active and p.identifier not in ['firetext', 'mmg']
|
||||
) if p.active
|
||||
]
|
||||
|
||||
if not active_providers:
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
"""
|
||||
|
||||
Revision ID: 0382_remove_old_sms_providers
|
||||
Revises: 0381_encrypted_column_types
|
||||
Create Date: 2022-12-16 12:52:14.182717
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = '0382_remove_old_providers'
|
||||
down_revision = '0381_encrypted_column_types'
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.execute("DELETE FROM provider_details WHERE identifier IN ('mmg', 'firetext')")
|
||||
op.execute("DELETE FROM provider_details_history WHERE identifier IN ('mmg', 'firetext')")
|
||||
|
||||
|
||||
def downgrade():
|
||||
raise Exception("Irreversible migration")
|
||||
@@ -170,7 +170,7 @@ def test_create_nightly_billing_for_day_sms_rate_multiplier(
|
||||
created_at=yesterday,
|
||||
template=sample_template,
|
||||
status='delivered',
|
||||
sent_by='mmg',
|
||||
sent_by='sns',
|
||||
international=False,
|
||||
rate_multiplier=1.0,
|
||||
billable_units=1,
|
||||
@@ -179,7 +179,7 @@ def test_create_nightly_billing_for_day_sms_rate_multiplier(
|
||||
created_at=yesterday,
|
||||
template=sample_template,
|
||||
status='delivered',
|
||||
sent_by='mmg',
|
||||
sent_by='sns',
|
||||
international=False,
|
||||
rate_multiplier=second_rate,
|
||||
billable_units=1,
|
||||
@@ -214,7 +214,7 @@ def test_create_nightly_billing_for_day_different_templates(
|
||||
created_at=yesterday,
|
||||
template=sample_template,
|
||||
status='delivered',
|
||||
sent_by='mmg',
|
||||
sent_by='sns',
|
||||
international=False,
|
||||
rate_multiplier=1.0,
|
||||
billable_units=1,
|
||||
@@ -223,7 +223,7 @@ def test_create_nightly_billing_for_day_different_templates(
|
||||
created_at=yesterday,
|
||||
template=sample_email_template,
|
||||
status='delivered',
|
||||
sent_by='ses',
|
||||
sent_by='sns',
|
||||
international=False,
|
||||
rate_multiplier=0,
|
||||
billable_units=0,
|
||||
@@ -262,7 +262,7 @@ def test_create_nightly_billing_for_day_different_sent_by(
|
||||
created_at=yesterday,
|
||||
template=sample_template,
|
||||
status='delivered',
|
||||
sent_by='mmg',
|
||||
sent_by='sns',
|
||||
international=False,
|
||||
rate_multiplier=1.0,
|
||||
billable_units=1,
|
||||
@@ -271,7 +271,7 @@ def test_create_nightly_billing_for_day_different_sent_by(
|
||||
created_at=yesterday,
|
||||
template=sample_template,
|
||||
status='delivered',
|
||||
sent_by='firetext',
|
||||
sent_by='sns',
|
||||
international=False,
|
||||
rate_multiplier=1.0,
|
||||
billable_units=1,
|
||||
|
||||
@@ -75,9 +75,6 @@ class AnyStringWith(str):
|
||||
return self in other
|
||||
|
||||
|
||||
mmg_error = {'Error': '40', 'Description': 'error'}
|
||||
|
||||
|
||||
def _notification_json(template, to, personalisation=None, job_id=None, row_number=0):
|
||||
return {
|
||||
"template": str(template.id),
|
||||
|
||||
@@ -626,8 +626,8 @@ def ses_provider():
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mmg_provider():
|
||||
return ProviderDetails.query.filter_by(identifier='mmg').one()
|
||||
def sns_provider():
|
||||
return ProviderDetails.query.filter_by(identifier='sns').one()
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@@ -888,9 +888,8 @@ def sample_service_guest_list(notify_db_session):
|
||||
def sample_inbound_numbers(sample_service):
|
||||
service = create_service(service_name='sample service 2', check_if_service_exists=True)
|
||||
inbound_numbers = list()
|
||||
inbound_numbers.append(create_inbound_number(number='1', provider='mmg'))
|
||||
inbound_numbers.append(create_inbound_number(number='2', provider='mmg', active=False, service_id=service.id))
|
||||
inbound_numbers.append(create_inbound_number(number='3', provider='firetext', service_id=sample_service.id))
|
||||
inbound_numbers.append(create_inbound_number(number='1', provider='sns'))
|
||||
inbound_numbers.append(create_inbound_number(number='2', provider='sns', active=False, service_id=service.id))
|
||||
return inbound_numbers
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -16,7 +16,7 @@ def test_rest_get_inbound_numbers(admin_request, sample_inbound_numbers):
|
||||
|
||||
|
||||
def test_rest_get_inbound_number(admin_request, notify_db_session, sample_service):
|
||||
inbound_number = create_inbound_number(number='1', provider='mmg', active=False, service_id=sample_service.id)
|
||||
inbound_number = create_inbound_number(number='1', provider='sns', active=False, service_id=sample_service.id)
|
||||
|
||||
result = admin_request.get(
|
||||
'inbound_number.get_inbound_number_for_service',
|
||||
@@ -37,7 +37,7 @@ def test_rest_get_inbound_number_when_service_is_not_assigned_returns_empty_dict
|
||||
def test_rest_set_inbound_number_active_flag_off(
|
||||
admin_request, notify_db_session):
|
||||
service = create_service(service_name='test service 1')
|
||||
create_inbound_number(number='1', provider='mmg', active=True, service_id=service.id)
|
||||
create_inbound_number(number='1', provider='sns', active=True, service_id=service.id)
|
||||
|
||||
admin_request.post(
|
||||
'inbound_number.post_set_inbound_number_off',
|
||||
|
||||
@@ -11,7 +11,7 @@ def test_get_provider_details_returns_all_providers(admin_request, notify_db_ses
|
||||
json_resp = admin_request.get('provider_details.get_providers')['provider_details']
|
||||
|
||||
assert len(json_resp) > 0
|
||||
assert {'ses', 'firetext', 'mmg', 'dvla'} <= {x['identifier'] for x in json_resp}
|
||||
assert {'ses', 'sns', 'dvla'} == {x['identifier'] for x in json_resp}
|
||||
|
||||
|
||||
def test_get_provider_details_by_id(client, notify_db_session):
|
||||
@@ -32,7 +32,7 @@ def test_get_provider_details_by_id(client, notify_db_session):
|
||||
|
||||
@freeze_time('2018-06-28 12:00')
|
||||
def test_get_provider_contains_correct_fields(client, sample_template):
|
||||
create_ft_billing('2018-06-01', sample_template, provider='mmg', billable_unit=1)
|
||||
create_ft_billing('2018-06-01', sample_template, provider='sns', billable_unit=1)
|
||||
|
||||
response = client.get(
|
||||
'/provider-details',
|
||||
|
||||
@@ -32,8 +32,8 @@ from tests.app.db import (
|
||||
|
||||
|
||||
@pytest.mark.parametrize('mobile_number', [
|
||||
'07700 900678',
|
||||
'+44 7700 900678'
|
||||
'5558675309',
|
||||
'+15558675309'
|
||||
])
|
||||
def test_should_build_service_guest_list_from_mobile_number(mobile_number):
|
||||
service_guest_list = ServiceGuestList.from_string('service_id', MOBILE_TYPE, mobile_number)
|
||||
@@ -93,7 +93,7 @@ def test_status_conversion(initial_statuses, expected_statuses):
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.000000")
|
||||
@pytest.mark.parametrize('template_type, recipient', [
|
||||
('sms', '+447700900855'),
|
||||
('sms', '+15558675309'),
|
||||
('email', 'foo@bar.com'),
|
||||
])
|
||||
def test_notification_for_csv_returns_correct_type(sample_service, template_type, recipient):
|
||||
|
||||
@@ -9,8 +9,8 @@ from tests.app.db import create_notification, create_template
|
||||
|
||||
|
||||
@pytest.mark.parametrize('billable_units, provider', [
|
||||
(1, 'mmg'),
|
||||
(0, 'mmg'),
|
||||
(1, 'sns'),
|
||||
(0, 'sns'),
|
||||
(1, None)
|
||||
])
|
||||
def test_get_notification_by_id_returns_200(
|
||||
|
||||
+2
-3
@@ -102,11 +102,10 @@ def _notify_db(notify_api, worker_id):
|
||||
def sms_providers(_notify_db):
|
||||
"""
|
||||
In production we randomly choose which provider to use based on their priority. To guarantee tests run the same each
|
||||
time, make sure we always choose mmg. You'll need to override them in your tests if you wish to do something
|
||||
time, make sure we always choose sns. You'll need to override them in your tests if you wish to do something
|
||||
different.
|
||||
"""
|
||||
get_provider_details_by_identifier('mmg').priority = 100
|
||||
get_provider_details_by_identifier('firetext').priority = 0
|
||||
get_provider_details_by_identifier('sns').priority = 100
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
|
||||
Reference in New Issue
Block a user