write a test

This commit is contained in:
Kenneth Kehl
2024-10-02 13:08:34 -07:00
parent a0c27975a5
commit 5d265135d3
2 changed files with 30 additions and 11 deletions

View File

@@ -98,17 +98,7 @@ def send_sms_to_provider(notification):
# TODO This is temporary to test the capability of validating phone numbers
# The future home of the validation is TBD
if "+" not in recipient:
recipient_lookup = f"+{recipient}"
else:
recipient_lookup = recipient
if recipient_lookup in current_app.config[
"SIMULATED_SMS_NUMBERS"
] and os.getenv("NOTIFY_ENVIRONMENT") in ["development", "test"]:
current_app.logger.info(hilite("#validate-phone-number fired"))
aws_pinpoint_client.validate_phone_number("01", recipient)
else:
current_app.logger.info(hilite("#validate-phone-number not fired"))
_experimentally_validate_phone_numbers(recipient)
sender_numbers = get_sender_numbers(notification)
if notification.reply_to_text not in sender_numbers:
@@ -145,6 +135,18 @@ def send_sms_to_provider(notification):
return message_id
def _experimentally_validate_phone_numbers(recipient):
if "+" not in recipient:
recipient_lookup = f"+{recipient}"
else:
recipient_lookup = recipient
if recipient_lookup in current_app.config["SIMULATED_SMS_NUMBERS"] and os.getenv(
"NOTIFY_ENVIRONMENT"
) in ["development", "test"]:
current_app.logger.info(hilite("#validate-phone-number fired"))
aws_pinpoint_client.validate_phone_number("01", recipient)
def _get_verify_code(notification):
key = f"2facode-{notification.id}".replace(" ", "")
recipient = redis_store.get(key)

View File

@@ -3,6 +3,7 @@ import os
from contextlib import suppress
from urllib import parse
import pytest
from cachetools import TTLCache, cached
from flask import current_app
@@ -19,6 +20,7 @@ from app.dao.email_branding_dao import dao_get_email_branding_by_id
from app.dao.notifications_dao import dao_update_notification
from app.dao.provider_details_dao import get_provider_details_by_notification_type
from app.dao.service_sms_sender_dao import dao_get_sms_senders_by_service_id
from app.delivery.send_to_providers import _experimentally_validate_phone_numbers
from app.enums import BrandType, KeyType, NotificationStatus, NotificationType
from app.exceptions import NotificationTechnicalFailureException
from app.serialised_models import SerialisedService, SerialisedTemplate
@@ -306,3 +308,18 @@ def technical_failure(notification):
f"Send {notification.notification_type} for notification id {notification.id} "
f"to provider is not allowed: service {notification.service_id} is inactive"
)
@pytest.mark.parametrize(
("recipient", "expected_invoke"),
[
("15555555555", False),
],
)
def test_experimentally_validate_phone_numbers(recipient, expected_invoke, mocker):
mock_pinpoint = mocker.patch("app.delivery.send_to_providers.aws_pinpoint_client")
_experimentally_validate_phone_numbers(recipient)
if expected_invoke:
mock_pinpoint.phone_number_validate.assert_called_once_with("foo")
else:
mock_pinpoint.phone_number_validate.assert_not_called()