fix tests

This commit is contained in:
Kenneth Kehl
2024-07-31 14:21:30 -07:00
parent 1e26511dc6
commit e244278ccf
2 changed files with 24 additions and 6 deletions

View File

@@ -103,12 +103,7 @@ def send_sms_to_provider(notification):
f"The recipient for (Service ID: {si}; Job ID: {ji}; Job Row Number {jrn} was not found." f"The recipient for (Service ID: {si}; Job ID: {ji}; Job Row Number {jrn} was not found."
) )
possible_senders = dao_get_sms_senders_by_service_id( sender_numbers = get_sender_numbers(notification)
notification.service_id
)
sender_numbers = []
for possible_sender in possible_senders:
sender_numbers.append(possible_sender.sms_sender)
if notification.reply_to_text not in sender_numbers: if notification.reply_to_text not in sender_numbers:
raise ValueError( raise ValueError(
f"{notification.reply_to_text} not in {sender_numbers} #notify-admin-1701" f"{notification.reply_to_text} not in {sender_numbers} #notify-admin-1701"
@@ -143,6 +138,14 @@ def send_sms_to_provider(notification):
return message_id return message_id
def get_sender_numbers(notification):
possible_senders = dao_get_sms_senders_by_service_id(notification.service_id)
sender_numbers = []
for possible_sender in possible_senders:
sender_numbers.append(possible_sender.sms_sender)
return sender_numbers
def send_email_to_provider(notification): def send_email_to_provider(notification):
# Someone needs an email, possibly new registration # Someone needs an email, possibly new registration
recipient = redis_store.get(f"email-address-{notification.id}") recipient = redis_store.get(f"email-address-{notification.id}")

View File

@@ -318,6 +318,9 @@ def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
# é, o, and u are in GSM. # é, o, and u are in GSM.
# ī, grapes, tabs, zero width space and ellipsis are not # ī, grapes, tabs, zero width space and ellipsis are not
# ó isn't in GSM, but it is in the welsh alphabet so will still be sent # ó isn't in GSM, but it is in the welsh alphabet so will still be sent
mocker.patch(
"app.delivery.send_to_providers.get_sender_numbers", return_value=["testing"]
)
msg = "a é ī o u 🍇 foo\tbar\u200bbaz((misc))…" msg = "a é ī o u 🍇 foo\tbar\u200bbaz((misc))…"
placeholder = "∆∆∆abc" placeholder = "∆∆∆abc"
gsm_message = "?ódz Housing Service: a é i o u ? foo barbaz???abc..." gsm_message = "?ódz Housing Service: a é i o u ? foo barbaz???abc..."
@@ -609,6 +612,10 @@ def __update_notification(notification_to_update, research_mode, expected_status
def test_should_update_billable_units_and_status_according_to_research_mode_and_key_type( def test_should_update_billable_units_and_status_according_to_research_mode_and_key_type(
sample_template, mocker, research_mode, key_type, billable_units, expected_status sample_template, mocker, research_mode, key_type, billable_units, expected_status
): ):
mocker.patch(
"app.delivery.send_to_providers.get_sender_numbers", return_value=["testing"]
)
notification = create_notification( notification = create_notification(
template=sample_template, template=sample_template,
billable_units=0, billable_units=0,
@@ -771,6 +778,10 @@ def test_send_email_to_provider_uses_reply_to_from_notification(
def test_send_sms_to_provider_should_use_normalised_to(mocker, client, sample_template): def test_send_sms_to_provider_should_use_normalised_to(mocker, client, sample_template):
mocker.patch(
"app.delivery.send_to_providers.get_sender_numbers", return_value=["testing"]
)
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, to_field="+12028675309", normalised_to="2028675309" template=sample_template, to_field="+12028675309", normalised_to="2028675309"
@@ -826,6 +837,10 @@ def test_send_email_to_provider_should_user_normalised_to(
def test_send_sms_to_provider_should_return_template_if_found_in_redis( 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.get_sender_numbers", return_value=["testing"]
)
from app.schemas import service_schema, template_schema from app.schemas import service_schema, template_schema
service_dict = service_schema.dump(sample_template.service) service_dict = service_schema.dump(sample_template.service)