Skip to content

Commit

Permalink
tweak INTERNAL_TEST_NUMBER sending (#2419)
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels authored Jan 20, 2025
1 parent fed01ff commit a341728
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
11 changes: 9 additions & 2 deletions app/delivery/send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
from urllib3 import PoolManager
from urllib3.util import Retry

from app import bounce_rate_client, clients, document_download_client, statsd_client
from app import (
bounce_rate_client,
clients,
create_uuid,
document_download_client,
statsd_client,
)
from app.celery.research_mode_tasks import send_email_response, send_sms_response
from app.clients.sms import SmsSendingVehicles
from app.config import Config
Expand Down Expand Up @@ -99,8 +105,9 @@ def send_sms_to_provider(notification):

if service.research_mode or notification.key_type == KEY_TYPE_TEST or sending_to_internal_test_number:
current_app.logger.info(f"notification {notification.id} is sending to INTERNAL_TEST_NUMBER, no boto call to AWS.")
notification.reference = send_sms_response(provider.get_name(), notification.to)
notification.reference = str(create_uuid())
update_notification_to_sending(notification, provider)
send_sms_response(provider.get_name(), notification.to, notification.reference)
else:
try:
template_category_id = template_dict.get("template_category_id")
Expand Down
20 changes: 4 additions & 16 deletions tests/app/delivery/test_send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from flask import current_app
from notifications_utils.recipients import validate_and_format_phone_number
from pytest_mock import MockFixture
from requests import HTTPError

import app
from app import aws_sns_client
Expand Down Expand Up @@ -476,9 +475,8 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(sampl
def test_should_call_send_sms_response_task_if_research_mode(
notify_db, sample_service, sample_notification, mocker, research_mode, key_type
):
reference = str(uuid.uuid4())
mocker.patch("app.aws_sns_client.send_sms")
mocker.patch("app.delivery.send_to_providers.send_sms_response", return_value=reference)
mocker.patch("app.delivery.send_to_providers.send_sms_response", return_value="not-used")

if research_mode:
sample_service.research_mode = True
Expand All @@ -490,29 +488,19 @@ def test_should_call_send_sms_response_task_if_research_mode(
send_to_providers.send_sms_to_provider(sample_notification)
assert not aws_sns_client.send_sms.called

app.delivery.send_to_providers.send_sms_response.assert_called_once_with("sns", sample_notification.to)
app.delivery.send_to_providers.send_sms_response.assert_called_once_with(
"sns", sample_notification.to, sample_notification.reference
)

persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
assert persisted_notification.to == sample_notification.to
assert persisted_notification.template_id == sample_notification.template_id
assert persisted_notification.status == "sent"
assert persisted_notification.sent_at <= datetime.utcnow()
assert persisted_notification.sent_by == "sns"
assert persisted_notification.reference == reference
assert not persisted_notification.personalisation


def test_should_not_have_sent_status_if_fake_callback_function_fails(sample_notification, mocker):
mocker.patch("app.delivery.send_to_providers.send_sms_response", side_effect=HTTPError)

sample_notification.key_type = KEY_TYPE_TEST

with pytest.raises(HTTPError):
send_to_providers.send_sms_to_provider(sample_notification)
assert sample_notification.status == "created"
assert sample_notification.sent_by is None


def test_should_not_send_to_provider_when_status_is_not_created(sample_template, mocker):
notification = save_notification(create_notification(template=sample_template, status="sending"))
mocker.patch("app.aws_sns_client.send_sms")
Expand Down

0 comments on commit a341728

Please sign in to comment.