diff --git a/app/delivery/send_to_providers.py b/app/delivery/send_to_providers.py index c7de7a32c2..5f74f76033 100644 --- a/app/delivery/send_to_providers.py +++ b/app/delivery/send_to_providers.py @@ -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__ @@ -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. @@ -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. @@ -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) diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index a8637afdfe..6b7dbf2210 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -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, { @@ -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,