mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 18:38:14 -04:00
Fixing tests, fixing tests...
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -95,7 +95,7 @@ def _update_statuses_from_row(update_dict, row):
|
||||
NotificationStatus.VALIDATION_FAILED,
|
||||
NotificationStatus.VIRUS_SCAN_FAILED,
|
||||
):
|
||||
update_dict[StatisticsType.FAILED] += row.count
|
||||
update_dict[StatisticsType.FAILURE] += row.count
|
||||
|
||||
|
||||
def create_empty_monthly_notification_status_stats_dict(year):
|
||||
|
||||
@@ -2102,7 +2102,7 @@ def test_set_sms_prefixing_for_service_cant_be_none(
|
||||
{
|
||||
StatisticsType.REQUESTED: 2,
|
||||
StatisticsType.DELIVERED: 1,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
},
|
||||
),
|
||||
(
|
||||
@@ -2110,7 +2110,7 @@ def test_set_sms_prefixing_for_service_cant_be_none(
|
||||
{
|
||||
StatisticsType.REQUESTED: 1,
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -2158,12 +2158,12 @@ def test_get_services_with_detailed_flag(client, sample_template):
|
||||
assert data[0]["statistics"] == {
|
||||
NotificationType.EMAIL: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 0,
|
||||
},
|
||||
NotificationType.SMS: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 3,
|
||||
},
|
||||
}
|
||||
@@ -2189,12 +2189,12 @@ def test_get_services_with_detailed_flag_excluding_from_test_key(
|
||||
assert data[0]["statistics"] == {
|
||||
NotificationType.EMAIL: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 0,
|
||||
},
|
||||
NotificationType.SMS: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 2,
|
||||
},
|
||||
}
|
||||
@@ -2267,12 +2267,12 @@ def test_get_detailed_services_groups_by_service(notify_db_session):
|
||||
assert data[0]["statistics"] == {
|
||||
NotificationType.EMAIL: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 0,
|
||||
},
|
||||
NotificationType.SMS: {
|
||||
StatisticsType.DELIVERED: 1,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 3,
|
||||
},
|
||||
}
|
||||
@@ -2280,12 +2280,12 @@ def test_get_detailed_services_groups_by_service(notify_db_session):
|
||||
assert data[1]["statistics"] == {
|
||||
NotificationType.EMAIL: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 0,
|
||||
},
|
||||
NotificationType.SMS: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 1,
|
||||
},
|
||||
}
|
||||
@@ -2312,12 +2312,12 @@ def test_get_detailed_services_includes_services_with_no_notifications(
|
||||
assert data[0]["statistics"] == {
|
||||
NotificationType.EMAIL: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 0,
|
||||
},
|
||||
NotificationType.SMS: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 1,
|
||||
},
|
||||
}
|
||||
@@ -2325,12 +2325,12 @@ def test_get_detailed_services_includes_services_with_no_notifications(
|
||||
assert data[1]["statistics"] == {
|
||||
NotificationType.EMAIL: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 0,
|
||||
},
|
||||
NotificationType.SMS: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 0,
|
||||
},
|
||||
}
|
||||
@@ -2354,12 +2354,12 @@ def test_get_detailed_services_only_includes_todays_notifications(sample_templat
|
||||
assert data[0]["statistics"] == {
|
||||
NotificationType.EMAIL: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 0,
|
||||
},
|
||||
NotificationType.SMS: {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 3,
|
||||
},
|
||||
}
|
||||
@@ -2407,12 +2407,12 @@ def test_get_detailed_services_for_date_range(
|
||||
assert len(data) == 1
|
||||
assert data[0]["statistics"][NotificationType.EMAIL] == {
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 0,
|
||||
}
|
||||
assert data[0]["statistics"][NotificationType.SMS] == {
|
||||
StatisticsType.DELIVERED: 2,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
StatisticsType.REQUESTED: 2,
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ def test_get_template_usage_by_month_returns_two_templates(
|
||||
{
|
||||
StatisticsType.REQUESTED: 2,
|
||||
StatisticsType.DELIVERED: 1,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
},
|
||||
),
|
||||
(
|
||||
@@ -125,7 +125,7 @@ def test_get_template_usage_by_month_returns_two_templates(
|
||||
{
|
||||
StatisticsType.REQUESTED: 1,
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -161,12 +161,12 @@ def test_get_service_notification_statistics_with_unknown_service(admin_request)
|
||||
NotificationType.SMS: {
|
||||
StatisticsType.REQUESTED: 0,
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
},
|
||||
NotificationType.EMAIL: {
|
||||
StatisticsType.REQUESTED: 0,
|
||||
StatisticsType.DELIVERED: 0,
|
||||
StatisticsType.FAILED: 0,
|
||||
StatisticsType.FAILURE: 0,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -410,7 +410,7 @@ def test_get_all_notifications_filter_by_template_type_invalid_template_type(
|
||||
assert len(json_response["errors"]) == 1
|
||||
assert (
|
||||
json_response["errors"][0]["message"]
|
||||
== "template_type orange is not one of [sms, email, letter]"
|
||||
== f"template_type orange is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in TemplateType])}]"
|
||||
)
|
||||
|
||||
|
||||
@@ -463,9 +463,7 @@ def test_get_all_notifications_filter_by_status_invalid_status(
|
||||
assert len(json_response["errors"]) == 1
|
||||
assert (
|
||||
json_response["errors"][0]["message"]
|
||||
== "status elephant is not one of [cancelled, created, sending, "
|
||||
"sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, "
|
||||
"pending-virus-check, validation-failed, virus-scan-failed]"
|
||||
== f"status elephant is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in NotificationStatus])}]"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -43,12 +43,7 @@ def test_get_notifications_valid_json(input):
|
||||
],
|
||||
)
|
||||
def test_get_notifications_request_invalid_statuses(invalid_statuses, valid_statuses):
|
||||
partial_error_status = (
|
||||
"is not one of "
|
||||
"[cancelled, created, sending, sent, delivered, pending, failed, "
|
||||
"technical-failure, temporary-failure, permanent-failure, pending-virus-check, "
|
||||
"validation-failed, virus-scan-failed]"
|
||||
)
|
||||
partial_error_status = f"is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in NotificationStatus])}]"
|
||||
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(
|
||||
@@ -75,7 +70,7 @@ def test_get_notifications_request_invalid_statuses(invalid_statuses, valid_stat
|
||||
def test_get_notifications_request_invalid_template_types(
|
||||
invalid_template_types, valid_template_types
|
||||
):
|
||||
partial_error_template_type = "is not one of [sms, email, letter]"
|
||||
partial_error_template_type = f"is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in TemplateType])}]"
|
||||
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(
|
||||
@@ -108,15 +103,13 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
|
||||
error_messages = [error["message"] for error in errors]
|
||||
for invalid_status in ["elephant", "giraffe"]:
|
||||
assert (
|
||||
f"status {invalid_status} is not one of [cancelled, created, sending, sent, delivered, "
|
||||
"pending, failed, technical-failure, temporary-failure, permanent-failure, "
|
||||
"pending-virus-check, validation-failed, virus-scan-failed]"
|
||||
f"status {invalid_status} is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in NotificationStatus])}]"
|
||||
in error_messages
|
||||
)
|
||||
|
||||
for invalid_template_type in ["orange", "avocado"]:
|
||||
assert (
|
||||
f"template_type {invalid_template_type} is not one of [sms, email, letter]"
|
||||
f"template_type {invalid_template_type} is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in TemplateType])}]"
|
||||
in error_messages
|
||||
)
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ def test_post_sms_notification_returns_201(
|
||||
assert resp_json["template"]["version"] == sample_template_with_placeholders.version
|
||||
assert (
|
||||
f"services/{sample_template_with_placeholders.service_id}/templates/"
|
||||
f"{sample_template_with_placeholders.service_id}"
|
||||
f"{sample_template_with_placeholders.id}"
|
||||
) in resp_json["template"]["uri"]
|
||||
assert not resp_json["scheduled_for"]
|
||||
assert mocked.called
|
||||
|
||||
@@ -120,7 +120,7 @@ def test_get_all_templates_for_invalid_type_returns_400(client, sample_service):
|
||||
"status_code": 400,
|
||||
"errors": [
|
||||
{
|
||||
"message": "type coconut is not one of [sms, email, letter]",
|
||||
"message": f"type coconut is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in TemplateType])}]",
|
||||
"error": "ValidationError",
|
||||
}
|
||||
],
|
||||
|
||||
@@ -280,7 +280,7 @@ def test_get_all_template_request_schema_against_invalid_args_is_invalid(templat
|
||||
assert len(errors["errors"]) == 1
|
||||
assert (
|
||||
errors["errors"][0]["message"]
|
||||
== "type unknown is not one of [sms, email, letter]"
|
||||
== f"type unknown is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in TemplateType])}]"
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user