Skip to content

Commit

Permalink
Merge branch 'main' into task/remove-letters
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai authored Jun 4, 2024
2 parents 5f3b456 + ee48085 commit f2e92f1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
13 changes: 10 additions & 3 deletions app/delivery/send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def send_sms_to_provider(notification):
notification.to,
notification.international,
notification.reply_to_text,
template_id=notification.template_id,
)

template_dict = dao_get_template_by_id(notification.template_id, notification.template_version).__dict__
Expand Down Expand Up @@ -345,6 +346,7 @@ def provider_to_use(
to: Optional[str] = None,
international: bool = False,
sender: Optional[str] = None,
template_id: Optional[UUID] = None,
) -> Any:
"""
Get the provider to use for sending the notification.
Expand All @@ -356,6 +358,7 @@ def provider_to_use(
to (str, optional): recipient. Defaults to None.
international (bool, optional): Recipient is international. Defaults to False.
sender (str, optional): reply_to_text to use. Defaults to None.
template_id (str, optional): template_id to use. Defaults to None.
Raises:
Exception: No active providers.
Expand All @@ -371,12 +374,16 @@ def provider_to_use(
if match and phonenumbers.region_code_for_number(match.number) == "US":
sending_to_us_number = True

if (
using_sc_pool_template = template_id is not None and str(template_id) in current_app.config["AWS_PINPOINT_SC_TEMPLATE_IDS"]

do_not_use_pinpoint = (
has_dedicated_number
or sending_to_us_number
or current_app.config["AWS_PINPOINT_SC_POOL_ID"] is None
or current_app.config["AWS_PINPOINT_DEFAULT_POOL_ID"] is None
):
or (current_app.config["AWS_PINPOINT_DEFAULT_POOL_ID"] is None and not using_sc_pool_template)
)

if do_not_use_pinpoint:
active_providers_in_order = [
p
for p in get_provider_details_by_notification_type(notification_type, international)
Expand Down
27 changes: 26 additions & 1 deletion tests/app/delivery/test_send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@


class TestProviderToUse:
def test_should_use_pinpoint_for_sms_by_default(self, restore_provider_details, notify_api):
def test_should_use_pinpoint_for_sms_by_default_if_configured(self, restore_provider_details, notify_api):
with set_config_values(
notify_api,
{
Expand All @@ -63,6 +63,31 @@ def test_should_use_pinpoint_for_sms_by_default(self, restore_provider_details,
provider = send_to_providers.provider_to_use("sms", "1234", "+16135551234")
assert provider.name == "pinpoint"

def test_should_use_sns_for_sms_by_default_if_partially_configured(self, restore_provider_details, notify_api):
with set_config_values(
notify_api,
{
"AWS_PINPOINT_SC_POOL_ID": "sc_pool_id",
"AWS_PINPOINT_DEFAULT_POOL_ID": None,
"AWS_PINPOINT_SC_TEMPLATE_IDS": [],
},
):
provider = send_to_providers.provider_to_use("sms", "1234", "+16135551234", template_id=uuid.uuid4())
assert provider.name == "sns"

def test_should_use_pinpoint_for_sms_for_sc_template_if_sc_pool_configured(self, restore_provider_details, notify_api):
sc_template = uuid.uuid4()
with set_config_values(
notify_api,
{
"AWS_PINPOINT_SC_POOL_ID": "sc_pool_id",
"AWS_PINPOINT_DEFAULT_POOL_ID": None,
"AWS_PINPOINT_SC_TEMPLATE_IDS": [str(sc_template)],
},
):
provider = send_to_providers.provider_to_use("sms", "1234", "+16135551234", template_id=sc_template)
assert provider.name == "pinpoint"

def test_should_use_sns_for_sms_if_dedicated_number(self, restore_provider_details, notify_api):
with set_config_values(
notify_api,
Expand Down

0 comments on commit f2e92f1

Please sign in to comment.