From 182e21ab91f91153dd5cf4673213f13b4e57e6b1 Mon Sep 17 00:00:00 2001 From: Stephen Astels Date: Mon, 8 Jul 2024 12:17:04 -0400 Subject: [PATCH] tests --- tests/app/clients/test_aws_pinpoint.py | 15 +++++++++++ tests/app/delivery/test_send_to_providers.py | 26 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/tests/app/clients/test_aws_pinpoint.py b/tests/app/clients/test_aws_pinpoint.py index ad7546d1ad..8879c98682 100644 --- a/tests/app/clients/test_aws_pinpoint.py +++ b/tests/app/clients/test_aws_pinpoint.py @@ -71,3 +71,18 @@ def test_send_sms_returns_raises_error_if_there_is_no_valid_number_is_found(noti aws_pinpoint_client.send_sms(to, content, reference) assert "No valid numbers found for SMS delivery" in str(excinfo.value) + + +def test_handles_opted_out_numbers(notify_api, mocker, sample_template): + # mock_client = mocker.patch.object(aws_pinpoint_client, "_client", create=True) + # mocker.patch.object(aws_pinpoint_client, "statsd_client", create=True) + + conflict_error = aws_pinpoint_client._client.exceptions.ConflictException( + error_response={"Reason": "DESTINATION_PHONE_NUMBER_OPTED_OUT"}, operation_name="send_text_message" + ) + mocker.patch("app.aws_pinpoint_client._client.send_text_message", side_effect=conflict_error) + + to = "6135555555" + content = "foo" + reference = "ref" + assert aws_pinpoint_client.send_sms(to, content, reference=reference, template_id=sample_template.id) == "opted_out" diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index 05482eca2d..a848696e1f 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -189,6 +189,32 @@ def test_should_return_highest_priority_active_provider(restore_provider_details assert send_to_providers.provider_to_use("sms", "1234").name == first.identifier +def test_should_handle_opted_out_phone_numbers_if_using_pinpoint(notify_api, sample_template, mocker): + # statsd_mock = mocker.patch("app.delivery.send_to_providers.statsd_client") + mocker.patch("app.aws_pinpoint_client.send_sms", return_value="opted_out") + db_notification = save_notification( + create_notification( + template=sample_template, + to_field="+16135551234", + status="created", + reply_to_text=sample_template.service.get_default_sms_sender(), + ) + ) + + with set_config_values( + notify_api, + { + "AWS_PINPOINT_SC_POOL_ID": "sc_pool_id", + "AWS_PINPOINT_DEFAULT_POOL_ID": "default_pool_id", + }, + ): + send_to_providers.send_sms_to_provider(db_notification) + + notification = Notification.query.filter_by(id=db_notification.id).one() + assert notification.status == "permanent-failure" + assert notification.provider_response == "Phone number is opted out" + + def test_should_send_personalised_template_to_correct_sms_provider_and_persist(sample_sms_template_with_html, mocker): db_notification = save_notification( create_notification(