mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
Filter provider details by international flags
This commit is contained in:
@@ -60,6 +60,7 @@ def dao_toggle_sms_provider(identifier):
|
|||||||
@transactional
|
@transactional
|
||||||
def dao_switch_sms_provider_to_provider_with_identifier(identifier):
|
def dao_switch_sms_provider_to_provider_with_identifier(identifier):
|
||||||
new_provider = get_provider_details_by_identifier(identifier)
|
new_provider = get_provider_details_by_identifier(identifier)
|
||||||
|
|
||||||
if provider_is_inactive(new_provider):
|
if provider_is_inactive(new_provider):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ def dao_switch_sms_provider_to_provider_with_identifier(identifier):
|
|||||||
providers_to_update = []
|
providers_to_update = []
|
||||||
|
|
||||||
if conflicting_provider:
|
if conflicting_provider:
|
||||||
providers_to_update = switch_providers(conflicting_provider, new_provider)
|
switch_providers(conflicting_provider, new_provider)
|
||||||
else:
|
else:
|
||||||
current_provider = get_current_provider('sms')
|
current_provider = get_current_provider('sms')
|
||||||
if not provider_is_primary(current_provider, new_provider, identifier):
|
if not provider_is_primary(current_provider, new_provider, identifier):
|
||||||
@@ -79,10 +80,14 @@ def dao_switch_sms_provider_to_provider_with_identifier(identifier):
|
|||||||
dao_update_provider_details(provider)
|
dao_update_provider_details(provider)
|
||||||
|
|
||||||
|
|
||||||
def get_provider_details_by_notification_type(notification_type):
|
def get_provider_details_by_notification_type(notification_type, supports_international=False):
|
||||||
return ProviderDetails.query.filter_by(
|
|
||||||
notification_type=notification_type
|
filters = [ProviderDetails.notification_type == notification_type]
|
||||||
).order_by(asc(ProviderDetails.priority)).all()
|
|
||||||
|
if supports_international:
|
||||||
|
filters.append(ProviderDetails.supports_international == supports_international)
|
||||||
|
|
||||||
|
return ProviderDetails.query.filter(*filters).order_by(asc(ProviderDetails.priority)).all()
|
||||||
|
|
||||||
|
|
||||||
@transactional
|
@transactional
|
||||||
|
|||||||
@@ -35,16 +35,24 @@ def test_can_get_all_providers(restore_provider_details):
|
|||||||
assert len(get_provider_details()) == 5
|
assert len(get_provider_details()) == 5
|
||||||
|
|
||||||
|
|
||||||
def test_can_get_sms_providers(restore_provider_details):
|
def test_can_get_sms_non_international_providers(restore_provider_details):
|
||||||
sms_providers = get_provider_details_by_notification_type('sms')
|
sms_providers = get_provider_details_by_notification_type('sms')
|
||||||
assert len(sms_providers) == 3
|
assert len(sms_providers) == 3
|
||||||
assert all('sms' == prov.notification_type for prov in sms_providers)
|
assert all('sms' == prov.notification_type for prov in sms_providers)
|
||||||
|
assert all(not prov.supports_international for prov in sms_providers)
|
||||||
|
|
||||||
|
|
||||||
|
def test_can_get_sms_international_providers(restore_provider_details):
|
||||||
|
sms_providers = get_provider_details_by_notification_type('sms', True)
|
||||||
|
assert len(sms_providers) == 1
|
||||||
|
assert all('sms' == prov.notification_type for prov in sms_providers)
|
||||||
|
assert all(prov.supports_international for prov in sms_providers)
|
||||||
|
|
||||||
|
|
||||||
def test_can_get_sms_providers_in_order_of_priority(restore_provider_details):
|
def test_can_get_sms_providers_in_order_of_priority(restore_provider_details):
|
||||||
providers = get_provider_details_by_notification_type('sms')
|
providers = get_provider_details_by_notification_type('sms', False)
|
||||||
|
|
||||||
assert providers[0].priority < providers[1].priority < providers[2].priority
|
assert providers[0].priority < providers[1].priority
|
||||||
|
|
||||||
|
|
||||||
def test_can_get_email_providers_in_order_of_priority(restore_provider_details):
|
def test_can_get_email_providers_in_order_of_priority(restore_provider_details):
|
||||||
|
|||||||
Reference in New Issue
Block a user