fix tests

This commit is contained in:
Kenneth Kehl
2024-01-22 10:55:09 -08:00
parent ed3a356ad1
commit 6dc9828663
19 changed files with 282 additions and 99 deletions

View File

@@ -85,16 +85,19 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
):
db_notification = create_notification(
template=sample_sms_template_with_html,
personalisation={"name": "Jo"},
status="created",
reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender(),
)
db_notification.personalisation = {"name": "Jo"}
mocker.patch("app.aws_sns_client.send_sms")
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_s3.return_value = "2028675309"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {"name": "Jo"}
send_to_providers.send_sms_to_provider(db_notification)
aws_sns_client.send_sms.assert_called_once_with(
@@ -122,8 +125,8 @@ def test_should_send_personalised_template_to_correct_email_provider_and_persist
db_notification = create_notification(
template=sample_email_template_with_html,
personalisation={"name": "Jo"},
)
db_notification.personalisation = {"name": "Jo"}
mocker.patch("app.aws_ses_client.send_email", return_value="reference")
@@ -156,6 +159,12 @@ def test_should_not_send_email_message_when_service_is_inactive_notifcation_is_i
):
sample_service.active = False
send_mock = mocker.patch("app.aws_ses_client.send_email", return_value="reference")
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_s3.return_value = "2028675309"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {"name": "Jo"}
with pytest.raises(NotificationTechnicalFailureException) as e:
send_to_providers.send_email_to_provider(sample_notification)
@@ -170,6 +179,12 @@ def test_should_not_send_sms_message_when_service_is_inactive_notification_is_in
sample_service.active = False
send_mock = mocker.patch("app.aws_sns_client.send_sms", return_value="reference")
mock_phone = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_phone.return_value = "15555555555"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {}
with pytest.raises(NotificationTechnicalFailureException) as e:
send_to_providers.send_sms_to_provider(sample_notification)
assert str(sample_notification.id) in str(e.value)
@@ -191,6 +206,9 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_s3.return_value = "2028675309"
mock_s3_p = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_s3_p.return_value = {}
mocker.patch("app.aws_sns_client.send_sms")
version_on_notification = sample_template.version
@@ -236,6 +254,13 @@ def test_should_have_sending_status_if_fake_callback_function_fails(
"app.delivery.send_to_providers.send_sms_response", side_effect=HTTPError
)
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_s3.return_value = "2028675309"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {"name": "Jo"}
sample_notification.key_type = KEY_TYPE_TEST
with pytest.raises(HTTPError):
send_to_providers.send_sms_to_provider(sample_notification)
@@ -250,6 +275,13 @@ def test_should_not_send_to_provider_when_status_is_not_created(
mocker.patch("app.aws_sns_client.send_sms")
response_mock = mocker.patch("app.delivery.send_to_providers.send_sms_response")
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_s3.return_value = "2028675309"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {"name": "Jo"}
send_to_providers.send_sms_to_provider(notification)
app.aws_sns_client.send_sms.assert_not_called()
@@ -266,14 +298,19 @@ def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
service = create_service(service_name="Łódź Housing Service")
template = create_template(service, content=msg)
db_notification = create_notification(
template=template, personalisation={"misc": placeholder}
template=template,
)
db_notification.personalisation = {"misc": placeholder}
mocker.patch("app.aws_sns_client.send_sms")
mock_phone = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_phone.return_value = "15555555555"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {"misc": placeholder}
send_to_providers.send_sms_to_provider(db_notification)
aws_sns_client.send_sms.assert_called_once_with(
@@ -296,6 +333,9 @@ def test_send_sms_should_use_service_sms_sender(
mock_phone = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_phone.return_value = "15555555555"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {}
send_to_providers.send_sms_to_provider(
db_notification,
)
@@ -318,7 +358,11 @@ def test_send_email_to_provider_should_not_send_to_provider_when_status_is_not_c
notification = create_notification(template=sample_email_template, status="sending")
mocker.patch("app.aws_ses_client.send_email")
mocker.patch("app.delivery.send_to_providers.send_email_response")
mock_phone = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_phone.return_value = "15555555555"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {}
send_to_providers.send_sms_to_provider(notification)
app.aws_ses_client.send_email.assert_not_called()
app.delivery.send_to_providers.send_email_response.assert_not_called()
@@ -532,6 +576,9 @@ def test_should_update_billable_units_and_status_according_to_research_mode_and_
mock_phone = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_phone.return_value = "15555555555"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {}
send_to_providers.send_sms_to_provider(notification)
assert notification.billable_units == billable_units
assert notification.status == expected_status
@@ -546,6 +593,13 @@ def test_should_set_notification_billable_units_and_reduces_provider_priority_if
sample_notification.billable_units = 0
assert sample_notification.sent_by is None
mock_phone = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_phone.return_value = "15555555555"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {}
# flake8 no longer likes raises with a generic exception
try:
send_to_providers.send_sms_to_provider(sample_notification)
@@ -574,6 +628,9 @@ def test_should_send_sms_to_international_providers(
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_s3.return_value = "601117224412"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {}
send_to_providers.send_sms_to_provider(notification_international)
aws_sns_client.send_sms.assert_called_once_with(
@@ -613,6 +670,9 @@ def test_should_handle_sms_sender_and_prefix_message(
mock_phone = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_phone.return_value = "15555555555"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {}
send_to_providers.send_sms_to_provider(notification)
aws_sns_client.send_sms.assert_called_once_with(
@@ -653,6 +713,9 @@ def test_send_sms_to_provider_should_use_normalised_to(mocker, client, sample_te
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_s3.return_value = "12028675309"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {}
send_to_providers.send_sms_to_provider(notification)
send_mock.assert_called_once_with(
to="12028675309",
@@ -712,6 +775,9 @@ def test_send_sms_to_provider_should_return_template_if_found_in_redis(
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
mock_s3.return_value = "447700900855"
mock_personalisation = mocker.patch("app.delivery.send_to_providers.get_personalisation_from_s3")
mock_personalisation.return_value = {}
send_to_providers.send_sms_to_provider(notification)
assert mock_get_template.called is False
assert mock_get_service.called is False