Even more cleanup.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-02-21 12:35:18 -05:00
parent 43a8b6539f
commit afc1de61f6
12 changed files with 94 additions and 85 deletions

View File

@@ -272,13 +272,19 @@ def test_only_normal_api_keys_can_return_job_notifications(
key_type,
):
normal_notification = create_notification(
template=sample_template, api_key=sample_api_key, key_type=KeyType.NORMAL
template=sample_template,
api_key=sample_api_key,
key_type=KeyType.NORMAL,
)
team_notification = create_notification(
template=sample_template, api_key=sample_team_api_key, key_type=KeyType.TEAM
template=sample_template,
api_key=sample_team_api_key,
key_type=KeyType.TEAM,
)
test_notification = create_notification(
template=sample_template, api_key=sample_test_api_key, key_type=KeyType.TEST
template=sample_template,
api_key=sample_test_api_key,
key_type=KeyType.TEST,
)
notification_objs = {

View File

@@ -1231,9 +1231,7 @@ def test_default_permissions_are_added_for_user_service(
str(sample_service.id)
]
assert sorted(i.value for i in PermissionType.defaults()) == sorted(
service_permissions
)
assert sorted(PermissionType.defaults()) == sorted(service_permissions)
def test_add_existing_user_to_another_service_with_all_permissions(
@@ -1790,7 +1788,7 @@ def test_get_all_notifications_for_service_filters_notifications_when_using_post
data = {
"page": 1,
"template_type": [TemplateType.SMS],
"status": ["created", "sending"],
"status": [NotificationStatus.CREATED, NotificationStatus.SENDING],
"to": "0855",
}
@@ -2103,7 +2101,7 @@ def test_get_detailed_service(
date(2000, 1, 1), NotificationType.SMS, sample_service, count=1
)
with freeze_time("2000-01-02T12:00:00"):
create_notification(template=sample_template, status="created")
create_notification(template=sample_template, status=NotificationStatus.CREATED)
resp = client.get(
f"/service/{sample_service.id}?detailed=True&today_only={today_only}",
headers=[create_admin_authorization_header()],
@@ -2114,10 +2112,10 @@ def test_get_detailed_service(
assert service["id"] == str(sample_service.id)
assert "statistics" in service.keys()
assert set(service["statistics"].keys()) == {
NotificationType.SMS.value,
NotificationType.EMAIL.value,
NotificationType.SMS,
NotificationType.EMAIL,
}
assert service["statistics"][NotificationType.SMS.value] == stats
assert service["statistics"][NotificationType.SMS] == stats
def test_get_services_with_detailed_flag(client, sample_template):
@@ -2136,8 +2134,8 @@ 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.value: {"delivered": 0, "failed": 0, "requested": 0},
NotificationType.SMS.value: {"delivered": 0, "failed": 0, "requested": 3},
NotificationType.EMAIL: {"delivered": 0, "failed": 0, "requested": 0},
NotificationType.SMS: {"delivered": 0, "failed": 0, "requested": 3},
}
@@ -2159,8 +2157,8 @@ 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.value: {"delivered": 0, "failed": 0, "requested": 0},
NotificationType.SMS.value: {"delivered": 0, "failed": 0, "requested": 2},
NotificationType.EMAIL: {"delivered": 0, "failed": 0, "requested": 0},
NotificationType.SMS: {"delivered": 0, "failed": 0, "requested": 2},
}
@@ -2229,27 +2227,27 @@ def test_get_detailed_services_groups_by_service(notify_db_session):
assert len(data) == 2
assert data[0]["id"] == str(service_1.id)
assert data[0]["statistics"] == {
NotificationType.EMAIL.value: {
NotificationStatus.DELIVERED: 0,
NotificationStatus.FAILED: 0,
NotificationType.EMAIL: {
"delivered": 0,
"failed": 0,
"requested": 0,
},
NotificationType.SMS.value: {
NotificationStatus.DELIVERED: 1,
NotificationStatus.FAILED: 0,
NotificationType.SMS: {
"delivered": 1,
"failed": 0,
"requested": 3,
},
}
assert data[1]["id"] == str(service_2.id)
assert data[1]["statistics"] == {
NotificationType.EMAIL.value: {
NotificationStatus.DELIVERED: 0,
NotificationStatus.FAILED: 0,
NotificationType.EMAIL: {
"delivered": 0,
"failed": 0,
"requested": 0,
},
NotificationType.SMS.value: {
NotificationStatus.DELIVERED: 0,
NotificationStatus.FAILED: 0,
NotificationType.SMS: {
"delivered": 0,
"failed": 0,
"requested": 1,
},
}
@@ -2274,27 +2272,27 @@ def test_get_detailed_services_includes_services_with_no_notifications(
assert len(data) == 2
assert data[0]["id"] == str(service_1.id)
assert data[0]["statistics"] == {
NotificationType.EMAIL.value: {
NotificationStatus.DELIVERED: 0,
NotificationStatus.FAILED: 0,
NotificationType.EMAIL: {
"delivered": 0,
"failed": 0,
"requested": 0,
},
NotificationType.SMS.value: {
NotificationStatus.DELIVERED: 0,
NotificationStatus.FAILED: 0,
NotificationType.SMS: {
"delivered": 0,
"failed": 0,
"requested": 1,
},
}
assert data[1]["id"] == str(service_2.id)
assert data[1]["statistics"] == {
NotificationType.EMAIL.value: {
NotificationStatus.DELIVERED: 0,
NotificationStatus.FAILED: 0,
NotificationType.EMAIL: {
"delivered": 0,
"failed": 0,
"requested": 0,
},
NotificationType.SMS.value: {
NotificationStatus.DELIVERED: 0,
NotificationStatus.FAILED: 0,
NotificationType.SMS: {
"delivered": 0,
"failed": 0,
"requested": 0,
},
}
@@ -2316,14 +2314,14 @@ def test_get_detailed_services_only_includes_todays_notifications(sample_templat
assert len(data) == 1
assert data[0]["statistics"] == {
NotificationType.EMAIL.value: {
NotificationStatus.DELIVERED: 0,
NotificationStatus.FAILED: 0,
NotificationType.EMAIL: {
"delivered": 0,
"failed": 0,
"requested": 0,
},
NotificationType.SMS.value: {
NotificationStatus.DELIVERED: 0,
NotificationStatus.FAILED: 0,
NotificationType.SMS: {
"delivered": 0,
"failed": 0,
"requested": 3,
},
}
@@ -2369,14 +2367,14 @@ def test_get_detailed_services_for_date_range(
)
assert len(data) == 1
assert data[0]["statistics"][NotificationType.EMAIL.value] == {
NotificationStatus.DELIVERED: 0,
NotificationStatus.FAILED: 0,
assert data[0]["statistics"][NotificationType.EMAIL] == {
"delivered": 0,
"failed": 0,
"requested": 0,
}
assert data[0]["statistics"][NotificationType.SMS.value] == {
NotificationStatus.DELIVERED: 2,
NotificationStatus.FAILED: 0,
assert data[0]["statistics"][NotificationType.SMS] == {
"delivered": 2,
"failed": 0,
"requested": 2,
}

View File

@@ -265,7 +265,8 @@ def test_populate_annual_billing_with_defaults(
notify_db_session, notify_api, organization_type, expected_allowance
):
service = create_service(
service_name=organization_type.value, organization_type=organization_type
service_name=organization_type,
organization_type=organization_type,
)
notify_api.test_cli_runner().invoke(
@@ -289,7 +290,8 @@ def test_populate_annual_billing_with_the_previous_years_allowance(
notify_db_session, notify_api, organization_type, expected_allowance
):
service = create_service(
service_name=organization_type.value, organization_type=organization_type
service_name=organization_type,
organization_type=organization_type,
)
notify_api.test_cli_runner().invoke(

View File

@@ -1,7 +1,7 @@
import pytest
from flask import json, url_for
from app.enums import NotificationType, TemplateType
from app.enums import NotificationStatus, NotificationType, TemplateType
from app.utils import DATETIME_FORMAT
from tests import create_service_authorization_header
from tests.app.db import create_notification, create_template
@@ -284,7 +284,7 @@ def test_get_all_notifications_except_job_notifications_returns_200(
assert len(json_response["notifications"]) == 2
assert json_response["notifications"][0]["id"] == str(notification.id)
assert json_response["notifications"][0]["status"] == "created"
assert json_response["notifications"][0]["status"] == NotificationStatus.CREATED
assert json_response["notifications"][0]["template"] == {
"id": str(notification.template.id),
"uri": notification.template.get_link(),
@@ -380,7 +380,7 @@ def test_get_all_notifications_filter_by_template_type(client, sample_service):
assert len(json_response["notifications"]) == 1
assert json_response["notifications"][0]["id"] == str(notification.id)
assert json_response["notifications"][0]["status"] == "created"
assert json_response["notifications"][0]["status"] == NotificationStatus.CREATED
assert json_response["notifications"][0]["template"] == {
"id": str(email_template.id),
"uri": notification.template.get_link(),
@@ -469,7 +469,11 @@ def test_get_all_notifications_filter_by_status_invalid_status(
def test_get_all_notifications_filter_by_multiple_statuses(client, sample_template):
notifications = [
create_notification(template=sample_template, status=_status)
for _status in ["created", "pending", "sending"]
for _status in [
NotificationStatus.CREATED,
NotificationStatus.PENDING,
NotificationStatus.SENDING,
]
]
failed_notification = create_notification(
template=sample_template, status="permanent-failure"
@@ -502,7 +506,8 @@ def test_get_all_notifications_filter_by_multiple_statuses(client, sample_templa
def test_get_all_notifications_filter_by_failed_status(client, sample_template):
created_notification = create_notification(
template=sample_template, status="created"
template=sample_template,
status=NotificationStatus.CREATED,
)
failed_notifications = [
create_notification(template=sample_template, status="failed")
@@ -692,6 +697,6 @@ def test_get_all_notifications_renames_letter_statuses(
noti["type"] == NotificationType.SMS
or noti["type"] == NotificationType.EMAIL
):
assert noti["status"] == "created"
assert noti["status"] == NotificationStatus.CREATED
else:
pytest.fail()

View File

@@ -39,7 +39,7 @@ def test_get_notifications_valid_json(input):
# multiple invalid statuses
(["elephant", "giraffe", "cheetah"], []),
# one bad status and one good status
(["elephant"], ["created"]),
(["elephant"], [NotificationStatus.CREATED]),
],
)
def test_get_notifications_request_invalid_statuses(invalid_statuses, valid_statuses):