mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Fish out the international provider if needed.
This commit is contained in:
@@ -121,21 +121,17 @@ def update_notification(notification, provider):
|
|||||||
|
|
||||||
|
|
||||||
def provider_to_use(notification_type, notification_id, international=False):
|
def provider_to_use(notification_type, notification_id, international=False):
|
||||||
provider = None
|
active_providers_in_order = [
|
||||||
# Default to MMG for international SMS
|
p for p in get_provider_details_by_notification_type(notification_type, international) if p.active
|
||||||
if notification_type == SMS_TYPE:
|
]
|
||||||
provider_id = 'mmg' if international else get_current_provider('sms')
|
|
||||||
provider = get_provider_details_by_identifier('mmg')
|
|
||||||
elif notification_type == EMAIL_TYPE:
|
|
||||||
provider = get_current_provider(notification_type)
|
|
||||||
|
|
||||||
if not provider:
|
if not active_providers_in_order:
|
||||||
current_app.logger.error(
|
current_app.logger.error(
|
||||||
"{} {} failed as no active providers".format(notification_type, notification_id)
|
"{} {} failed as no active providers".format(notification_type, notification_id)
|
||||||
)
|
)
|
||||||
raise Exception("No active {} providers".format(notification_type))
|
raise Exception("No active {} providers".format(notification_type))
|
||||||
|
|
||||||
return clients.get_client_by_name_and_type(provider.identifier, notification_type)
|
return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)
|
||||||
|
|
||||||
|
|
||||||
def get_logo_url(base_url, branding_path, logo_file):
|
def get_logo_url(base_url, branding_path, logo_file):
|
||||||
@@ -151,11 +147,8 @@ def get_logo_url(base_url, branding_path, logo_file):
|
|||||||
base_url = parse.urlparse(base_url)
|
base_url = parse.urlparse(base_url)
|
||||||
netloc = base_url.netloc
|
netloc = base_url.netloc
|
||||||
|
|
||||||
if (
|
# covers both preview and staging
|
||||||
base_url.netloc.startswith('localhost') or
|
if base_url.netloc.startswith('localhost') or 'notify.works' in base_url.netloc:
|
||||||
# covers both preview and staging
|
|
||||||
'notify.works' in base_url.netloc
|
|
||||||
):
|
|
||||||
path = '/static' + branding_path + logo_file
|
path = '/static' + branding_path + logo_file
|
||||||
else:
|
else:
|
||||||
if base_url.netloc.startswith('www'):
|
if base_url.netloc.startswith('www'):
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ import pytest
|
|||||||
from notifications_utils.recipients import validate_phone_number, format_phone_number
|
from notifications_utils.recipients import validate_phone_number, format_phone_number
|
||||||
|
|
||||||
import app
|
import app
|
||||||
from app import mmg_client
|
from app import mmg_client, firetext_client
|
||||||
from app.dao import (provider_details_dao, notifications_dao)
|
from app.dao import (provider_details_dao, notifications_dao)
|
||||||
|
from app.dao.provider_details_dao import dao_switch_sms_provider_to_provider_with_identifier
|
||||||
from app.delivery import send_to_providers
|
from app.delivery import send_to_providers
|
||||||
from app.models import (
|
from app.models import (
|
||||||
Notification,
|
Notification,
|
||||||
@@ -18,7 +19,7 @@ from app.models import (
|
|||||||
KEY_TYPE_TEAM,
|
KEY_TYPE_TEAM,
|
||||||
BRANDING_ORG,
|
BRANDING_ORG,
|
||||||
BRANDING_BOTH,
|
BRANDING_BOTH,
|
||||||
)
|
ProviderDetails)
|
||||||
|
|
||||||
from tests.app.db import create_service, create_template, create_notification
|
from tests.app.db import create_service, create_template, create_notification
|
||||||
|
|
||||||
@@ -471,3 +472,61 @@ def test_should_update_billable_units_according_to_research_mode_and_key_type(no
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert sample_notification.billable_units == billable_units
|
assert sample_notification.billable_units == billable_units
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_send_sms_to_international_providers(
|
||||||
|
restore_provider_details,
|
||||||
|
sample_sms_template_with_html,
|
||||||
|
sample_user,
|
||||||
|
mocker
|
||||||
|
):
|
||||||
|
mocker.patch('app.provider_details.switch_providers.get_user_by_id', return_value=sample_user)
|
||||||
|
|
||||||
|
dao_switch_sms_provider_to_provider_with_identifier('firetext')
|
||||||
|
|
||||||
|
db_notification_uk = create_notification(
|
||||||
|
template=sample_sms_template_with_html,
|
||||||
|
to_field="+447234123999",
|
||||||
|
personalisation={"name": "Jo"},
|
||||||
|
status='created',
|
||||||
|
international=False)
|
||||||
|
|
||||||
|
db_notification_international = create_notification(
|
||||||
|
template=sample_sms_template_with_html,
|
||||||
|
to_field="+447234123111",
|
||||||
|
personalisation={"name": "Jo"},
|
||||||
|
status='created',
|
||||||
|
international=True)
|
||||||
|
|
||||||
|
mocker.patch('app.mmg_client.send_sms')
|
||||||
|
mocker.patch('app.firetext_client.send_sms')
|
||||||
|
|
||||||
|
send_to_providers.send_sms_to_provider(
|
||||||
|
db_notification_uk
|
||||||
|
)
|
||||||
|
|
||||||
|
firetext_client.send_sms.assert_called_once_with(
|
||||||
|
to=format_phone_number(validate_phone_number("+447234123999")),
|
||||||
|
content=ANY,
|
||||||
|
reference=str(db_notification_uk.id),
|
||||||
|
sender=None
|
||||||
|
)
|
||||||
|
|
||||||
|
send_to_providers.send_sms_to_provider(
|
||||||
|
db_notification_international
|
||||||
|
)
|
||||||
|
|
||||||
|
mmg_client.send_sms.assert_called_once_with(
|
||||||
|
to=format_phone_number(validate_phone_number("+447234123111")),
|
||||||
|
content=ANY,
|
||||||
|
reference=str(db_notification_international.id),
|
||||||
|
sender=None
|
||||||
|
)
|
||||||
|
|
||||||
|
notification_uk = Notification.query.filter_by(id=db_notification_uk.id).one()
|
||||||
|
notification_int = Notification.query.filter_by(id=db_notification_international.id).one()
|
||||||
|
|
||||||
|
assert notification_uk.status == 'sending'
|
||||||
|
assert notification_uk.sent_by == 'firetext'
|
||||||
|
assert notification_int.status == 'sending'
|
||||||
|
assert notification_int.sent_by == 'mmg'
|
||||||
|
|||||||
Reference in New Issue
Block a user