"sms" entries cleaned up.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-02-21 08:36:42 -05:00
parent 4429e48221
commit 9fde1f30ea
3 changed files with 87 additions and 44 deletions

View File

@@ -14,7 +14,7 @@ from app.dao import notifications_dao
from app.dao.provider_details_dao import get_provider_details_by_identifier
from app.delivery import send_to_providers
from app.delivery.send_to_providers import get_html_email_options, get_logo_url
from app.enums import BrandType, KeyType, NotificationStatus
from app.enums import BrandType, KeyType, NotificationStatus, NotificationType
from app.exceptions import NotificationTechnicalFailureException
from app.models import EmailBranding, Notification
from app.serialised_models import SerialisedService
@@ -53,7 +53,7 @@ def test_provider_to_use_should_only_return_sns_for_international(
sns = get_provider_details_by_identifier("sns")
sns.priority = international_provider_priority
ret = send_to_providers.provider_to_use("sms", international=True)
ret = send_to_providers.provider_to_use(NotificationType.SMS, international=True)
assert ret.name == "sns"
@@ -66,7 +66,7 @@ def test_provider_to_use_raises_if_no_active_providers(
# flake8 doesn't like raises with a generic exception
try:
send_to_providers.provider_to_use("sms")
send_to_providers.provider_to_use(NotificationType.SMS)
assert 1 == 0
except Exception:
assert 1 == 1
@@ -496,7 +496,9 @@ def test_update_notification_to_sending_does_not_update_status_from_a_final_stat
notification = create_notification(template=template, status=starting_status)
send_to_providers.update_notification_to_sending(
notification,
notification_provider_clients.get_client_by_name_and_type("sns", "sms"),
notification_provider_clients.get_client_by_name_and_type(
"sns", NotificationType.SMS
),
)
assert notification.status == expected_status

View File

@@ -92,22 +92,22 @@ def test_get_platform_stats_with_real_query(admin_request, notify_db_session):
start_date=date(2018, 10, 29),
)
assert response == {
"email": {
NotificationType.EMAIL: {
"failures": {
"virus-scan-failed": 0,
"temporary-failure": 0,
"permanent-failure": 0,
"technical-failure": 0,
NotificationStatus.VIRUS_SCAN_FAILED: 0,
NotificationStatus.TEMPORARY_FAILURE: 0,
NotificationStatus.PERMANENT_FAILURE: 0,
NotificationStatus.TECHNICAL_FAILURE: 0,
},
"total": 4,
"test-key": 0,
},
"sms": {
NotificationType.SMS: {
"failures": {
"virus-scan-failed": 0,
"temporary-failure": 0,
"permanent-failure": 0,
"technical-failure": 0,
NotificationStatus.VIRUS_SCAN_FAILED: 0,
NotificationStatus.TEMPORARY_FAILURE: 0,
NotificationStatus.PERMANENT_FAILURE: 0,
NotificationStatus.TECHNICAL_FAILURE: 0,
},
"total": 11,
"test-key": 1,

View File

@@ -18,7 +18,9 @@ def test_get_template_usage_by_month_returns_correct_data(
admin_request, sample_template
):
create_ft_notification_status(
local_date=date(2017, 4, 2), template=sample_template, count=3
local_date=date(2017, 4, 2),
template=sample_template,
count=3,
)
create_notification(sample_template, created_at=datetime.utcnow())
@@ -57,10 +59,14 @@ def test_get_template_usage_by_month_returns_two_templates(
hidden=True,
)
create_ft_notification_status(
local_date=datetime(2017, 4, 2), template=template_one, count=1
local_date=datetime(2017, 4, 2),
template=template_one,
count=1,
)
create_ft_notification_status(
local_date=datetime(2017, 4, 2), template=sample_template, count=3
local_date=datetime(2017, 4, 2),
template=sample_template,
count=3,
)
create_notification(sample_template, created_at=datetime.utcnow())
@@ -191,7 +197,7 @@ def test_get_monthly_notification_stats_returns_empty_stats_with_correct_dates(
]
assert sorted(response["data"].keys()) == keys
for val in response["data"].values():
assert val == {"sms": {}, "email": {}}
assert val == {NotificationType.SMS: {}, NotificationType.EMAIL: {}}
def test_get_monthly_notification_stats_returns_stats(admin_request, sample_service):
@@ -205,7 +211,9 @@ def test_get_monthly_notification_stats_returns_stats(admin_request, sample_serv
create_ft_notification_status(datetime(2016, 7, 1), template=sms_t1)
create_ft_notification_status(datetime(2016, 7, 1), template=sms_t2)
create_ft_notification_status(
datetime(2016, 7, 1), template=sms_t1, notification_status="created"
datetime(2016, 7, 1),
template=sms_t1,
notification_status=NotificationStatus.CREATED,
)
create_ft_notification_status(datetime(2016, 7, 1), template=email_template)
@@ -217,19 +225,19 @@ def test_get_monthly_notification_stats_returns_stats(admin_request, sample_serv
assert len(response["data"]) == 12
assert response["data"]["2016-06"] == {
"sms": {
NotificationType.SMS: {
# it combines the two days
"delivered": 2
NotificationStatus.DELIVERED: 2
},
"email": {},
NotificationType.EMAIL: {},
}
assert response["data"]["2016-07"] == {
# it combines the two template types
"sms": {
"created": 1,
"delivered": 2,
NotificationType.SMS: {
NotificationStatus.CREATED: 1,
NotificationStatus.DELIVERED: 2,
},
"email": {"delivered": 1},
NotificationType.EMAIL: {"delivered": 1},
}
@@ -274,14 +282,17 @@ def test_get_monthly_notification_stats_combines_todays_data_and_historic_stats(
)
assert len(response["data"]) == 6 # January to June
assert response["data"]["2016-05"] == {"sms": {"delivered": 1}, "email": {}}
assert response["data"]["2016-05"] == {
NotificationType.SMS: {NotificationStatus.DELIVERED: 1},
NotificationType.EMAIL: {},
}
assert response["data"]["2016-06"] == {
"sms": {
NotificationType.SMS: {
# combines the stats from the historic ft_notification_status and the current notifications
"created": 3,
"delivered": 1,
NotificationStatus.CREATED: 3,
NotificationStatus.DELIVERED: 1,
},
"email": {},
NotificationType.EMAIL: {},
}
@@ -289,13 +300,22 @@ def test_get_monthly_notification_stats_ignores_test_keys(
admin_request, sample_service
):
create_ft_notification_status(
datetime(2016, 6, 1), service=sample_service, key_type=KeyType.NORMAL, count=1
datetime(2016, 6, 1),
service=sample_service,
key_type=KeyType.NORMAL,
count=1,
)
create_ft_notification_status(
datetime(2016, 6, 1), service=sample_service, key_type=KeyType.TEAM, count=2
datetime(2016, 6, 1),
service=sample_service,
key_type=KeyType.TEAM,
count=2,
)
create_ft_notification_status(
datetime(2016, 6, 1), service=sample_service, key_type=KeyType.TEST, count=4
datetime(2016, 6, 1),
service=sample_service,
key_type=KeyType.TEST,
count=4,
)
response = admin_request.get(
@@ -304,20 +324,28 @@ def test_get_monthly_notification_stats_ignores_test_keys(
year=2016,
)
assert response["data"]["2016-06"]["sms"] == {"delivered": 3}
assert response["data"]["2016-06"][NotificationType.SMS] == {
NotificationStatus.DELIVERED: 3,
}
def test_get_monthly_notification_stats_checks_dates(admin_request, sample_service):
t = create_template(sample_service)
# create_ft_notification_status(datetime(2016, 3, 31), template=t, notification_status='created')
create_ft_notification_status(
datetime(2016, 4, 2), template=t, notification_status="sending"
datetime(2016, 4, 2),
template=t,
notification_status=NotificationStatus.SENDING,
)
create_ft_notification_status(
datetime(2017, 3, 31), template=t, notification_status="delivered"
datetime(2017, 3, 31),
template=t,
notification_status=NotificationStatus.DELIVERED,
)
create_ft_notification_status(
datetime(2017, 4, 11), template=t, notification_status="permanent-failure"
datetime(2017, 4, 11),
template=t,
notification_status=NotificationStatus.PERMANENT_FAILURE,
)
response = admin_request.get(
@@ -327,8 +355,12 @@ def test_get_monthly_notification_stats_checks_dates(admin_request, sample_servi
)
assert "2016-04" in response["data"]
assert "2017-04" not in response["data"]
assert response["data"]["2016-04"]["sms"] == {"sending": 1}
assert response["data"]["2016-04"]["sms"] == {"sending": 1}
assert response["data"]["2016-04"][NotificationType.SMS] == {
NotificationStatus.SENDING: 1,
}
assert response["data"]["2016-04"][NotificationType.SMS] == {
NotificationStatus.SENDING: 1,
}
def test_get_monthly_notification_stats_only_gets_for_one_service(
@@ -339,14 +371,23 @@ def test_get_monthly_notification_stats_only_gets_for_one_service(
templates = [create_template(services[0]), create_template(services[1])]
create_ft_notification_status(
datetime(2016, 6, 1), template=templates[0], notification_status="created"
datetime(2016, 6, 1),
template=templates[0],
notification_status=NotificationStatus.CREATED,
)
create_ft_notification_status(
datetime(2016, 6, 1), template=templates[1], notification_status="delivered"
datetime(2016, 6, 1),
template=templates[1],
notification_status=NotificationStatus.DELIVERED,
)
response = admin_request.get(
"service.get_monthly_notification_stats", service_id=services[0].id, year=2016
"service.get_monthly_notification_stats",
service_id=services[0].id,
year=2016,
)
assert response["data"]["2016-06"] == {"sms": {"created": 1}, "email": {}}
assert response["data"]["2016-06"] == {
NotificationType.SMS: {NotificationStatus.CREATED: 1},
NotificationType.EMAIL: {},
}