Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels committed Jul 8, 2024
1 parent f1daf45 commit 182e21a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/app/clients/test_aws_pinpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
26 changes: 26 additions & 0 deletions tests/app/delivery/test_send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 182e21a

Please sign in to comment.