Replaced "delivered".

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-02-21 13:18:33 -05:00
parent afc1de61f6
commit a118b16eb8
15 changed files with 228 additions and 121 deletions

View File

@@ -16,6 +16,7 @@ from app.celery.test_key_tasks import (
ses_soft_bounce_callback,
)
from app.dao.notifications_dao import get_notification_by_id
from app.enums import NotificationStatus
from app.models import Complaint
from tests.app.conftest import create_sample_notification
from tests.app.db import (
@@ -136,7 +137,7 @@ def test_process_ses_results(sample_email_template):
sample_email_template,
reference="ref1",
sent_at=datetime.utcnow(),
status="sending",
status=NotificationStatus.SENDING,
)
assert process_ses_results(response=ses_notification_callback(reference="ref1"))
@@ -147,7 +148,7 @@ def test_process_ses_results_retry_called(sample_email_template, mocker):
sample_email_template,
reference="ref1",
sent_at=datetime.utcnow(),
status="sending",
status=NotificationStatus.SENDING,
)
mocker.patch(
"app.dao.notifications_dao._update_notification_status",
@@ -196,15 +197,20 @@ def test_ses_callback_should_update_notification_status(
notify_db_session,
template=sample_email_template,
reference="ref",
status="sending",
status=NotificationStatus.SENDING,
sent_at=datetime.utcnow(),
)
create_service_callback_api(
service=sample_email_template.service, url="https://original_url.com"
)
assert get_notification_by_id(notification.id).status == "sending"
assert (
get_notification_by_id(notification.id).status == NotificationStatus.SENDING
)
assert process_ses_results(ses_notification_callback(reference="ref"))
assert get_notification_by_id(notification.id).status == "delivered"
assert (
get_notification_by_id(notification.id).status
== NotificationStatus.DELIVERED
)
send_mock.assert_called_once_with(
[str(notification.id), ANY], queue="service-callbacks"
)
@@ -222,11 +228,15 @@ def test_ses_callback_should_not_update_notification_status_if_already_delivered
"app.celery.process_ses_receipts_tasks.notifications_dao._update_notification_status"
)
notification = create_notification(
template=sample_email_template, reference="ref", status="delivered"
template=sample_email_template,
reference="ref",
status=NotificationStatus.DELIVERED,
)
assert process_ses_results(ses_notification_callback(reference="ref")) is None
assert get_notification_by_id(notification.id).status == "delivered"
mock_dup.assert_called_once_with(notification, "delivered")
assert (
get_notification_by_id(notification.id).status == NotificationStatus.DELIVERED
)
mock_dup.assert_called_once_with(notification, NotificationStatus.DELIVERED)
assert mock_upd.call_count == 0
@@ -283,12 +293,17 @@ def test_ses_callback_does_not_call_send_delivery_status_if_no_db_entry(
notify_db_session,
template=sample_email_template,
reference="ref",
status="sending",
status=NotificationStatus.SENDING,
sent_at=datetime.utcnow(),
)
assert get_notification_by_id(notification.id).status == "sending"
assert (
get_notification_by_id(notification.id).status == NotificationStatus.SENDING
)
assert process_ses_results(ses_notification_callback(reference="ref"))
assert get_notification_by_id(notification.id).status == "delivered"
assert (
get_notification_by_id(notification.id).status
== NotificationStatus.DELIVERED
)
send_mock.assert_not_called()
@@ -304,7 +319,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent(
template=sample_email_template,
reference="ref1",
sent_at=datetime.utcnow(),
status="sending",
status=NotificationStatus.SENDING,
)
create_sample_notification(
_notify_db,
@@ -312,7 +327,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent(
template=sample_email_template,
reference="ref2",
sent_at=datetime.utcnow(),
status="sending",
status=NotificationStatus.SENDING,
)
create_sample_notification(
_notify_db,
@@ -320,7 +335,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent(
template=sample_email_template,
reference="ref3",
sent_at=datetime.utcnow(),
status="sending",
status=NotificationStatus.SENDING,
)
create_service_callback_api(
service=sample_email_template.service, url="https://original_url.com"
@@ -342,15 +357,18 @@ def test_ses_callback_should_set_status_to_temporary_failure(
notify_db_session,
template=sample_email_template,
reference="ref",
status="sending",
status=NotificationStatus.SENDING,
sent_at=datetime.utcnow(),
)
create_service_callback_api(
service=notification.service, url="https://original_url.com"
)
assert get_notification_by_id(notification.id).status == "sending"
assert get_notification_by_id(notification.id).status == NotificationStatus.SENDING
assert process_ses_results(ses_soft_bounce_callback(reference="ref"))
assert get_notification_by_id(notification.id).status == "temporary-failure"
assert (
get_notification_by_id(notification.id).status
== NotificationStatus.TEMPORARY_FAILURE
)
assert send_mock.called
@@ -365,15 +383,18 @@ def test_ses_callback_should_set_status_to_permanent_failure(
notify_db_session,
template=sample_email_template,
reference="ref",
status="sending",
status=NotificationStatus.SENDING,
sent_at=datetime.utcnow(),
)
create_service_callback_api(
service=sample_email_template.service, url="https://original_url.com"
)
assert get_notification_by_id(notification.id).status == "sending"
assert get_notification_by_id(notification.id).status == NotificationStatus.SENDING
assert process_ses_results(ses_hard_bounce_callback(reference="ref"))
assert get_notification_by_id(notification.id).status == "permanent-failure"
assert (
get_notification_by_id(notification.id).status
== NotificationStatus.PERMANENT_FAILURE
)
assert send_mock.called
@@ -392,7 +413,7 @@ def test_ses_callback_should_send_on_complaint_to_user_callback_api(
template=sample_email_template,
reference="ref1",
sent_at=datetime.utcnow(),
status="sending",
status=NotificationStatus.SENDING,
)
response = ses_complaint_callback()
assert process_ses_results(response)

View File

@@ -161,7 +161,7 @@ def test__send_data_to_service_callback_api_does_not_retry_if_request_returns_40
created_at=datestr,
updated_at=datestr,
sent_at=datestr,
status="sent",
status=NotificationStatus.SENT,
)
encrypted_data = _set_up_data_for_status_update(callback_api, notification)
mocked = mocker.patch(

View File

@@ -36,7 +36,10 @@ def test_make_sns_callback(notify_api, rmock, mocker):
assert rmock.called
assert rmock.request_history[0].url == endpoint
assert json.loads(rmock.request_history[0].text)["status"] == "delivered"
assert (
json.loads(rmock.request_history[0].text)["status"]
== NotificationStatus.DELIVERED
)
def test_callback_logs_on_api_call_failure(notify_api, rmock, mocker):
@@ -86,5 +89,5 @@ def test_delivered_sns_callback(mocker):
get_notification_by_id.return_value = n
data = json.loads(sns_callback("1234"))
assert data["status"] == "delivered"
assert data["status"] == NotificationStatus.DELIVERED
assert data["CID"] == "1234"

View File

@@ -12,37 +12,38 @@ from app.clients.email.aws_ses import (
AwsSesClientThrottlingSendRateException,
get_aws_responses,
)
from app.enums import NotificationStatus, StatisticsType
def test_should_return_correct_details_for_delivery():
response_dict = get_aws_responses("Delivery")
assert response_dict["message"] == "Delivered"
assert response_dict["notification_status"] == "delivered"
assert response_dict["notification_statistics_status"] == "delivered"
assert response_dict["notification_status"] == NotificationStatus.DELIVERED
assert response_dict["notification_statistics_status"] == StatisticsType.DELIVERED
assert response_dict["success"]
def test_should_return_correct_details_for_hard_bounced():
response_dict = get_aws_responses("Permanent")
assert response_dict["message"] == "Hard bounced"
assert response_dict["notification_status"] == "permanent-failure"
assert response_dict["notification_statistics_status"] == "failure"
assert response_dict["notification_status"] == NotificationStatus.PERMANENT_FAILURE
assert response_dict["notification_statistics_status"] == StatisticsType.FAILURE
assert not response_dict["success"]
def test_should_return_correct_details_for_soft_bounced():
response_dict = get_aws_responses("Temporary")
assert response_dict["message"] == "Soft bounced"
assert response_dict["notification_status"] == "temporary-failure"
assert response_dict["notification_statistics_status"] == "failure"
assert response_dict["notification_status"] == NotificationStatus.TEMPORARY_FAILURE
assert response_dict["notification_statistics_status"] == StatisticsType.FAILURE
assert not response_dict["success"]
def test_should_return_correct_details_for_complaint():
response_dict = get_aws_responses("Complaint")
assert response_dict["message"] == "Complaint"
assert response_dict["notification_status"] == "delivered"
assert response_dict["notification_statistics_status"] == "delivered"
assert response_dict["notification_status"] == NotificationStatus.DELIVERED
assert response_dict["notification_statistics_status"] == StatisticsType.DELIVERED
assert response_dict["success"]

View File

@@ -116,8 +116,8 @@ def test_fetch_billing_data_for_day_only_calls_query_for_permission_type(
service = create_service(service_permissions=[notification_type])
email_template = create_template(service=service, template_type=TemplateType.EMAIL)
sms_template = create_template(service=service, template_type=TemplateType.SMS)
create_notification(template=email_template, status="delivered")
create_notification(template=sms_template, status="delivered")
create_notification(template=email_template, status=NotificationStatus.DELIVERED)
create_notification(template=sms_template, status=NotificationStatus.DELIVERED)
today = datetime.utcnow()
results = fetch_billing_data_for_day(
process_day=today.date(), check_permissions=True

View File

@@ -7,6 +7,7 @@ from app.celery.process_ses_receipts_tasks import (
handle_complaint,
)
from app.dao.notifications_dao import get_notification_by_id
from app.enums import NotificationStatus
from app.models import Complaint
from tests.app.db import (
create_notification,
@@ -23,10 +24,12 @@ def test_ses_callback_should_not_set_status_once_status_is_delivered(
):
notification = create_notification(
sample_email_template,
status="delivered",
status=NotificationStatus.DELIVERED,
)
assert get_notification_by_id(notification.id).status == "delivered"
assert (
get_notification_by_id(notification.id).status == NotificationStatus.DELIVERED
)
def test_process_ses_results_in_complaint(sample_email_template):

View File

@@ -21,6 +21,7 @@ from app.enums import (
OrganizationType,
PermissionType,
ServicePermissionType,
StatisticsType,
TemplateType,
)
from app.models import (
@@ -1775,10 +1776,14 @@ def test_get_all_notifications_for_service_filters_notifications_when_using_post
)
create_notification(
service_1_sms_template, to_field="+447700900000", normalised_to="447700900000"
service_1_sms_template,
to_field="+447700900000",
normalised_to="447700900000",
)
create_notification(
service_1_sms_template, status="delivered", normalised_to="447700900855"
service_1_sms_template,
status=NotificationStatus.DELIVERED,
normalised_to="447700900855",
)
create_notification(service_1_email_template, normalised_to="447700900855")
# create notification for service_2
@@ -2089,8 +2094,22 @@ def test_set_sms_prefixing_for_service_cant_be_none(
@pytest.mark.parametrize(
"today_only,stats",
[
("False", {"requested": 2, "delivered": 1, "failed": 0}),
("True", {"requested": 1, "delivered": 0, "failed": 0}),
(
"False",
{
StatisticsType.REQUESTED: 2,
StatisticsType.DELIVERED: 1,
StatisticsType.FAILED: 0,
},
),
(
"True",
{
StatisticsType.REQUESTED: 1,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
},
),
],
ids=["seven_days", "today"],
)
@@ -2134,8 +2153,16 @@ def test_get_services_with_detailed_flag(client, sample_template):
assert data[0]["name"] == "Sample service"
assert data[0]["id"] == str(notifications[0].service_id)
assert data[0]["statistics"] == {
NotificationType.EMAIL: {"delivered": 0, "failed": 0, "requested": 0},
NotificationType.SMS: {"delivered": 0, "failed": 0, "requested": 3},
NotificationType.EMAIL: {
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 0,
},
NotificationType.SMS: {
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 3,
},
}
@@ -2157,8 +2184,16 @@ def test_get_services_with_detailed_flag_excluding_from_test_key(
data = resp.json["data"]
assert len(data) == 1
assert data[0]["statistics"] == {
NotificationType.EMAIL: {"delivered": 0, "failed": 0, "requested": 0},
NotificationType.SMS: {"delivered": 0, "failed": 0, "requested": 2},
NotificationType.EMAIL: {
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 0,
},
NotificationType.SMS: {
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 2,
},
}
@@ -2228,27 +2263,27 @@ def test_get_detailed_services_groups_by_service(notify_db_session):
assert data[0]["id"] == str(service_1.id)
assert data[0]["statistics"] == {
NotificationType.EMAIL: {
"delivered": 0,
"failed": 0,
"requested": 0,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 0,
},
NotificationType.SMS: {
"delivered": 1,
"failed": 0,
"requested": 3,
StatisticsType.DELIVERED: 1,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 3,
},
}
assert data[1]["id"] == str(service_2.id)
assert data[1]["statistics"] == {
NotificationType.EMAIL: {
"delivered": 0,
"failed": 0,
"requested": 0,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 0,
},
NotificationType.SMS: {
"delivered": 0,
"failed": 0,
"requested": 1,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 1,
},
}
@@ -2273,27 +2308,27 @@ def test_get_detailed_services_includes_services_with_no_notifications(
assert data[0]["id"] == str(service_1.id)
assert data[0]["statistics"] == {
NotificationType.EMAIL: {
"delivered": 0,
"failed": 0,
"requested": 0,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 0,
},
NotificationType.SMS: {
"delivered": 0,
"failed": 0,
"requested": 1,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 1,
},
}
assert data[1]["id"] == str(service_2.id)
assert data[1]["statistics"] == {
NotificationType.EMAIL: {
"delivered": 0,
"failed": 0,
"requested": 0,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 0,
},
NotificationType.SMS: {
"delivered": 0,
"failed": 0,
"requested": 0,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 0,
},
}
@@ -2315,14 +2350,14 @@ def test_get_detailed_services_only_includes_todays_notifications(sample_templat
assert len(data) == 1
assert data[0]["statistics"] == {
NotificationType.EMAIL: {
"delivered": 0,
"failed": 0,
"requested": 0,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 0,
},
NotificationType.SMS: {
"delivered": 0,
"failed": 0,
"requested": 3,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 3,
},
}
@@ -2368,14 +2403,14 @@ def test_get_detailed_services_for_date_range(
assert len(data) == 1
assert data[0]["statistics"][NotificationType.EMAIL] == {
"delivered": 0,
"failed": 0,
"requested": 0,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 0,
}
assert data[0]["statistics"][NotificationType.SMS] == {
"delivered": 2,
"failed": 0,
"requested": 2,
StatisticsType.DELIVERED: 2,
StatisticsType.FAILED: 0,
StatisticsType.REQUESTED: 2,
}
@@ -2598,13 +2633,13 @@ def test_search_for_notification_by_to_field_filters_by_status(client, sample_te
notification1 = create_notification(
sample_template,
to_field="+447700900855",
status="delivered",
status=NotificationStatus.DELIVERED,
normalised_to="447700900855",
)
create_notification(
sample_template,
to_field="+447700900855",
status="sending",
status=NotificationStatus.SENDING,
normalised_to="447700900855",
)
@@ -2630,13 +2665,13 @@ def test_search_for_notification_by_to_field_filters_by_statuses(
notification1 = create_notification(
sample_template,
to_field="+447700900855",
status="delivered",
status=NotificationStatus.DELIVERED,
normalised_to="447700900855",
)
notification2 = create_notification(
sample_template,
to_field="+447700900855",
status="sending",
status=NotificationStatus.SENDING,
normalised_to="447700900855",
)

View File

@@ -4,7 +4,13 @@ from datetime import date, datetime
import pytest
from freezegun import freeze_time
from app.enums import KeyType, NotificationStatus, NotificationType, TemplateType
from app.enums import (
KeyType,
NotificationStatus,
NotificationType,
StatisticsType,
TemplateType,
)
from tests.app.db import (
create_ft_notification_status,
create_notification,
@@ -106,8 +112,22 @@ def test_get_template_usage_by_month_returns_two_templates(
@pytest.mark.parametrize(
"today_only, stats",
[
(False, {"requested": 2, "delivered": 1, "failed": 0}),
(True, {"requested": 1, "delivered": 0, "failed": 0}),
(
False,
{
StatisticsType.REQUESTED: 2,
StatisticsType.DELIVERED: 1,
StatisticsType.FAILED: 0,
},
),
(
True,
{
StatisticsType.REQUESTED: 1,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
},
),
],
ids=["seven_days", "today"],
)
@@ -138,8 +158,16 @@ def test_get_service_notification_statistics_with_unknown_service(admin_request)
)
assert resp["data"] == {
NotificationType.SMS: {"requested": 0, "delivered": 0, "failed": 0},
NotificationType.EMAIL: {"requested": 0, "delivered": 0, "failed": 0},
NotificationType.SMS: {
StatisticsType.REQUESTED: 0,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
},
NotificationType.EMAIL: {
StatisticsType.REQUESTED: 0,
StatisticsType.DELIVERED: 0,
StatisticsType.FAILED: 0,
},
}
@@ -237,7 +265,7 @@ def test_get_monthly_notification_stats_returns_stats(admin_request, sample_serv
NotificationStatus.CREATED: 1,
NotificationStatus.DELIVERED: 2,
},
NotificationType.EMAIL: {"delivered": 1},
NotificationType.EMAIL: {StatisticsType.DELIVERED: 1},
}

View File

@@ -152,21 +152,29 @@ def test_notification_for_csv_returns_correct_job_row_number(sample_job):
@pytest.mark.parametrize(
"template_type, status, expected_status",
[
(TemplateType.EMAIL, "failed", "Failed"),
(TemplateType.EMAIL, "technical-failure", "Technical failure"),
(TemplateType.EMAIL, NotificationStatus.FAILED, "Failed"),
(TemplateType.EMAIL, NotificationStatus.TECHNICAL_FAILURE, "Technical failure"),
(
TemplateType.EMAIL,
"temporary-failure",
NotificationStatus.TEMPORARY_FAILURE,
"Inbox not accepting messages right now",
),
(TemplateType.EMAIL, "permanent-failure", "Email address doesnt exist"),
(
TemplateType.EMAIL,
NotificationStatus.PERMANENT_FAILURE,
"Email address doesnt exist",
),
(
TemplateType.SMS,
"temporary-failure",
NotificationStatus.TEMPORARY_FAILURE,
"Unable to find carrier response -- still looking",
),
(TemplateType.SMS, "permanent-failure", "Unable to find carrier response."),
(TemplateType.SMS, "sent", "Sent internationally"),
(
TemplateType.SMS,
NotificationStatus.PERMANENT_FAILURE,
"Unable to find carrier response.",
),
(TemplateType.SMS, NotificationStatus.SENT, "Sent internationally"),
],
)
def test_notification_for_csv_returns_formatted_status(

View File

@@ -630,7 +630,8 @@ def test_get_all_notifications_filter_multiple_query_parameters(
# TODO had to change pending to sending. Is that correct?
# this is the notification we are looking for
older_notification = create_notification(
template=sample_email_template, status="sending"
template=sample_email_template,
status=NotificationStatus.SENDING,
)
# wrong status
@@ -639,13 +640,16 @@ def test_get_all_notifications_filter_multiple_query_parameters(
sample_email_template.service, template_type=TemplateType.SMS
)
# wrong template
create_notification(template=wrong_template, status="sending")
create_notification(template=wrong_template, status=NotificationStatus.SENDING)
# we only want notifications created before this one
newer_notification = create_notification(template=sample_email_template)
# this notification was created too recently
create_notification(template=sample_email_template, status="sending")
create_notification(
template=sample_email_template,
status=NotificationStatus.SENDING,
)
auth_header = create_service_authorization_header(
service_id=newer_notification.service_id