From beed50491f76047a09efbb204ed455c266d6bccc Mon Sep 17 00:00:00 2001 From: Steve Astels Date: Tue, 2 Jul 2024 15:16:44 -0400 Subject: [PATCH] use sns for non-CA zone 1 (#2205) --- app/delivery/send_to_providers.py | 4 ++++ tests/app/delivery/test_send_to_providers.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/delivery/send_to_providers.py b/app/delivery/send_to_providers.py index c262a379e9..331e846b7d 100644 --- a/app/delivery/send_to_providers.py +++ b/app/delivery/send_to_providers.py @@ -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) @@ -378,6 +379,8 @@ 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 = ( @@ -385,6 +388,7 @@ def provider_to_use( 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) ) diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index 88f5bb38ee..05482eca2d 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -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,