fix tests

This commit is contained in:
Kenneth Kehl
2024-08-20 08:10:14 -07:00
parent 6e22cf101e
commit 7acb10078d
2 changed files with 18 additions and 33 deletions

View File

@@ -82,33 +82,13 @@ def send_sms_to_provider(notification):
# the phone number is for the verification code on login, which is not a job. # the phone number is for the verification code on login, which is not a job.
recipient = None recipient = None
# It is our 2facode, maybe # It is our 2facode, maybe
if notification.job_id is None: recipient = _get_verify_code(notification)
key = f"2facode-{notification.id}".replace(" ", "")
recipient = redis_store.get(key)
if recipient:
recipient = recipient.decode("utf-8")
else:
try:
recipient = get_phone_number_from_s3(
notification.service_id,
notification.job_id,
notification.job_row_number,
)
except Exception:
# It is our 2facode, maybe
key = f"2facode-{notification.id}".replace(" ", "")
recipient = redis_store.get(key)
if recipient:
recipient = recipient.decode("utf-8")
if recipient is None: if recipient is None:
si = notification.service_id recipient = get_phone_number_from_s3(
ji = notification.job_id notification.service_id,
jrn = notification.job_row_number notification.job_id,
raise Exception( notification.job_row_number,
f"The recipient for (Service ID: {si}; Job ID: {ji}; Job Row Number {jrn} was not found."
) )
sender_numbers = get_sender_numbers(notification) sender_numbers = get_sender_numbers(notification)
@@ -146,6 +126,14 @@ def send_sms_to_provider(notification):
return message_id return message_id
def _get_verify_code(notification):
key = f"2facode-{notification.id}".replace(" ", "")
recipient = redis_store.get(key)
if recipient:
recipient = recipient.decode("utf-8")
return recipient
def get_sender_numbers(notification): def get_sender_numbers(notification):
possible_senders = dao_get_sms_senders_by_service_id(notification.service_id) possible_senders = dao_get_sms_senders_by_service_id(notification.service_id)
sender_numbers = [] sender_numbers = []

View File

@@ -76,11 +76,10 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
sample_sms_template_with_html, mocker sample_sms_template_with_html, mocker
): ):
mocker.patch("app.delivery.send_to_providers.redis_store", return_value=None) mocker.patch("app.delivery.send_to_providers._get_verify_code", return_value=None)
db_notification = create_notification( db_notification = create_notification(
template=sample_sms_template_with_html, template=sample_sms_template_with_html,
personalisation={}, personalisation={},
job_id="myjobid",
status=NotificationStatus.CREATED, status=NotificationStatus.CREATED,
reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender(), reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender(),
) )
@@ -117,7 +116,9 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
def test_should_send_personalised_template_to_correct_email_provider_and_persist( def test_should_send_personalised_template_to_correct_email_provider_and_persist(
sample_email_template_with_html, mocker sample_email_template_with_html, mocker
): ):
mock_redis = mocker.patch("app.delivery.send_to_providers.redis_store") mock_redis = mocker.patch(
"app.delivery.send_to_providers._get_verify_code", return_value=None
)
utf8_encoded_email = "jo.smith@example.com".encode("utf-8") utf8_encoded_email = "jo.smith@example.com".encode("utf-8")
mock_redis.get.return_value = utf8_encoded_email mock_redis.get.return_value = utf8_encoded_email
email = utf8_encoded_email email = utf8_encoded_email
@@ -224,7 +225,6 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
status=NotificationStatus.CREATED, status=NotificationStatus.CREATED,
reply_to_text=sample_template.service.get_default_sms_sender(), reply_to_text=sample_template.service.get_default_sms_sender(),
normalised_to="2028675309", normalised_to="2028675309",
job_id="myjobid",
) )
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3") mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
@@ -694,7 +694,6 @@ def test_should_send_sms_to_international_providers(
notification_international = create_notification( notification_international = create_notification(
template=sample_template, template=sample_template,
to_field="+6011-17224412", to_field="+6011-17224412",
job_id="myjobid",
personalisation={"name": "Jo"}, personalisation={"name": "Jo"},
status=NotificationStatus.CREATED, status=NotificationStatus.CREATED,
international=True, international=True,
@@ -804,7 +803,6 @@ def test_send_sms_to_provider_should_use_normalised_to(mocker, client, sample_te
send_mock = mocker.patch("app.aws_sns_client.send_sms") send_mock = mocker.patch("app.aws_sns_client.send_sms")
notification = create_notification( notification = create_notification(
template=sample_template, template=sample_template,
job_id="myjobid",
to_field="+12028675309", to_field="+12028675309",
normalised_to="2028675309", normalised_to="2028675309",
reply_to_text="testing", reply_to_text="testing",
@@ -861,7 +859,7 @@ def test_send_sms_to_provider_should_return_template_if_found_in_redis(
mocker, client, sample_template mocker, client, sample_template
): ):
mocker.patch("app.delivery.send_to_providers.redis_store", return_value=None) mocker.patch("app.delivery.send_to_providers._get_verify_coe", return_value=None)
mocker.patch( mocker.patch(
"app.delivery.send_to_providers.get_sender_numbers", return_value=["testing"] "app.delivery.send_to_providers.get_sender_numbers", return_value=["testing"]
) )
@@ -885,7 +883,6 @@ def test_send_sms_to_provider_should_return_template_if_found_in_redis(
send_mock = mocker.patch("app.aws_sns_client.send_sms") send_mock = mocker.patch("app.aws_sns_client.send_sms")
notification = create_notification( notification = create_notification(
template=sample_template, template=sample_template,
job_id="myjobid",
to_field="+447700900855", to_field="+447700900855",
normalised_to="447700900855", normalised_to="447700900855",
reply_to_text="testing", reply_to_text="testing",