Skip to content

Commit

Permalink
use sns for non-CA zone 1 (#2205)
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels authored Jul 2, 2024
1 parent 8c4f9e5 commit beed504
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/delivery/send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ def provider_to_use(

has_dedicated_number = sender is not None and sender.startswith("+1")
cannot_determine_recipient_country = False
recipient_outside_canada = False
sending_to_us_number = False
if to is not None:
match = next(iter(phonenumbers.PhoneNumberMatcher(to, "US")), None)
Expand All @@ -378,13 +379,16 @@ def provider_to_use(
phonenumbers.region_code_for_number(match.number) == "US"
): # The US is a special case that needs to send from a US toll free number
sending_to_us_number = True
elif phonenumbers.region_code_for_number(match.number) != "CA":
recipient_outside_canada = True
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 cannot_determine_recipient_country
or international
or recipient_outside_canada
or not current_app.config["AWS_PINPOINT_SC_POOL_ID"]
or ((not current_app.config["AWS_PINPOINT_DEFAULT_POOL_ID"]) and not using_sc_pool_template)
)
Expand Down
11 changes: 11 additions & 0 deletions tests/app/delivery/test_send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ def test_should_use_sns_for_sms_if_sending_outside_zone_1(self, restore_provider
provider = send_to_providers.provider_to_use("sms", "1234", "+17065551234", international=True)
assert provider.name == "sns"

def test_should_use_sns_for_sms_if_sending_to_non_CA_zone_1(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": "default_pool_id",
},
):
provider = send_to_providers.provider_to_use("sms", "1234", "+16715550123")
assert provider.name == "sns"

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

0 comments on commit beed504

Please sign in to comment.