mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 10:28:55 -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.VALIDATION_FAILED,
|
||||||
NotificationStatus.VIRUS_SCAN_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):
|
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.REQUESTED: 2,
|
||||||
StatisticsType.DELIVERED: 1,
|
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.REQUESTED: 1,
|
||||||
StatisticsType.DELIVERED: 0,
|
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"] == {
|
assert data[0]["statistics"] == {
|
||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 3,
|
StatisticsType.REQUESTED: 3,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2189,12 +2189,12 @@ def test_get_services_with_detailed_flag_excluding_from_test_key(
|
|||||||
assert data[0]["statistics"] == {
|
assert data[0]["statistics"] == {
|
||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 2,
|
StatisticsType.REQUESTED: 2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2267,12 +2267,12 @@ def test_get_detailed_services_groups_by_service(notify_db_session):
|
|||||||
assert data[0]["statistics"] == {
|
assert data[0]["statistics"] == {
|
||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 1,
|
StatisticsType.DELIVERED: 1,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 3,
|
StatisticsType.REQUESTED: 3,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2280,12 +2280,12 @@ def test_get_detailed_services_groups_by_service(notify_db_session):
|
|||||||
assert data[1]["statistics"] == {
|
assert data[1]["statistics"] == {
|
||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 1,
|
StatisticsType.REQUESTED: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2312,12 +2312,12 @@ def test_get_detailed_services_includes_services_with_no_notifications(
|
|||||||
assert data[0]["statistics"] == {
|
assert data[0]["statistics"] == {
|
||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 1,
|
StatisticsType.REQUESTED: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2325,12 +2325,12 @@ def test_get_detailed_services_includes_services_with_no_notifications(
|
|||||||
assert data[1]["statistics"] == {
|
assert data[1]["statistics"] == {
|
||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2354,12 +2354,12 @@ def test_get_detailed_services_only_includes_todays_notifications(sample_templat
|
|||||||
assert data[0]["statistics"] == {
|
assert data[0]["statistics"] == {
|
||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 3,
|
StatisticsType.REQUESTED: 3,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2407,12 +2407,12 @@ def test_get_detailed_services_for_date_range(
|
|||||||
assert len(data) == 1
|
assert len(data) == 1
|
||||||
assert data[0]["statistics"][NotificationType.EMAIL] == {
|
assert data[0]["statistics"][NotificationType.EMAIL] == {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
}
|
}
|
||||||
assert data[0]["statistics"][NotificationType.SMS] == {
|
assert data[0]["statistics"][NotificationType.SMS] == {
|
||||||
StatisticsType.DELIVERED: 2,
|
StatisticsType.DELIVERED: 2,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 2,
|
StatisticsType.REQUESTED: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ def test_get_template_usage_by_month_returns_two_templates(
|
|||||||
{
|
{
|
||||||
StatisticsType.REQUESTED: 2,
|
StatisticsType.REQUESTED: 2,
|
||||||
StatisticsType.DELIVERED: 1,
|
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.REQUESTED: 1,
|
||||||
StatisticsType.DELIVERED: 0,
|
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: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILED: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
},
|
},
|
||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
StatisticsType.DELIVERED: 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 len(json_response["errors"]) == 1
|
||||||
assert (
|
assert (
|
||||||
json_response["errors"][0]["message"]
|
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 len(json_response["errors"]) == 1
|
||||||
assert (
|
assert (
|
||||||
json_response["errors"][0]["message"]
|
json_response["errors"][0]["message"]
|
||||||
== "status elephant is not one of [cancelled, created, sending, "
|
== f"status elephant is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in NotificationStatus])}]"
|
||||||
"sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, "
|
|
||||||
"pending-virus-check, validation-failed, virus-scan-failed]"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,12 +43,7 @@ def test_get_notifications_valid_json(input):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_get_notifications_request_invalid_statuses(invalid_statuses, valid_statuses):
|
def test_get_notifications_request_invalid_statuses(invalid_statuses, valid_statuses):
|
||||||
partial_error_status = (
|
partial_error_status = f"is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in NotificationStatus])}]"
|
||||||
"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]"
|
|
||||||
)
|
|
||||||
|
|
||||||
with pytest.raises(ValidationError) as e:
|
with pytest.raises(ValidationError) as e:
|
||||||
validate(
|
validate(
|
||||||
@@ -75,7 +70,7 @@ def test_get_notifications_request_invalid_statuses(invalid_statuses, valid_stat
|
|||||||
def test_get_notifications_request_invalid_template_types(
|
def test_get_notifications_request_invalid_template_types(
|
||||||
invalid_template_types, valid_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:
|
with pytest.raises(ValidationError) as e:
|
||||||
validate(
|
validate(
|
||||||
@@ -108,15 +103,13 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
|
|||||||
error_messages = [error["message"] for error in errors]
|
error_messages = [error["message"] for error in errors]
|
||||||
for invalid_status in ["elephant", "giraffe"]:
|
for invalid_status in ["elephant", "giraffe"]:
|
||||||
assert (
|
assert (
|
||||||
f"status {invalid_status} is not one of [cancelled, created, sending, sent, delivered, "
|
f"status {invalid_status} is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in NotificationStatus])}]"
|
||||||
"pending, failed, technical-failure, temporary-failure, permanent-failure, "
|
|
||||||
"pending-virus-check, validation-failed, virus-scan-failed]"
|
|
||||||
in error_messages
|
in error_messages
|
||||||
)
|
)
|
||||||
|
|
||||||
for invalid_template_type in ["orange", "avocado"]:
|
for invalid_template_type in ["orange", "avocado"]:
|
||||||
assert (
|
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
|
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 resp_json["template"]["version"] == sample_template_with_placeholders.version
|
||||||
assert (
|
assert (
|
||||||
f"services/{sample_template_with_placeholders.service_id}/templates/"
|
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"]
|
) in resp_json["template"]["uri"]
|
||||||
assert not resp_json["scheduled_for"]
|
assert not resp_json["scheduled_for"]
|
||||||
assert mocked.called
|
assert mocked.called
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ def test_get_all_templates_for_invalid_type_returns_400(client, sample_service):
|
|||||||
"status_code": 400,
|
"status_code": 400,
|
||||||
"errors": [
|
"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",
|
"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 len(errors["errors"]) == 1
|
||||||
assert (
|
assert (
|
||||||
errors["errors"][0]["message"]
|
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