mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
write a test
This commit is contained in:
@@ -98,17 +98,7 @@ def send_sms_to_provider(notification):
|
|||||||
|
|
||||||
# TODO This is temporary to test the capability of validating phone numbers
|
# TODO This is temporary to test the capability of validating phone numbers
|
||||||
# The future home of the validation is TBD
|
# The future home of the validation is TBD
|
||||||
if "+" not in recipient:
|
_experimentally_validate_phone_numbers(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"))
|
|
||||||
|
|
||||||
sender_numbers = get_sender_numbers(notification)
|
sender_numbers = get_sender_numbers(notification)
|
||||||
if notification.reply_to_text not in sender_numbers:
|
if notification.reply_to_text not in sender_numbers:
|
||||||
@@ -145,6 +135,18 @@ def send_sms_to_provider(notification):
|
|||||||
return message_id
|
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):
|
def _get_verify_code(notification):
|
||||||
key = f"2facode-{notification.id}".replace(" ", "")
|
key = f"2facode-{notification.id}".replace(" ", "")
|
||||||
recipient = redis_store.get(key)
|
recipient = redis_store.get(key)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import os
|
|||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
|
|
||||||
|
import pytest
|
||||||
from cachetools import TTLCache, cached
|
from cachetools import TTLCache, cached
|
||||||
from flask import current_app
|
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.notifications_dao import dao_update_notification
|
||||||
from app.dao.provider_details_dao import get_provider_details_by_notification_type
|
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.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.enums import BrandType, KeyType, NotificationStatus, NotificationType
|
||||||
from app.exceptions import NotificationTechnicalFailureException
|
from app.exceptions import NotificationTechnicalFailureException
|
||||||
from app.serialised_models import SerialisedService, SerialisedTemplate
|
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"Send {notification.notification_type} for notification id {notification.id} "
|
||||||
f"to provider is not allowed: service {notification.service_id} is inactive"
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user