mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
@@ -32,18 +32,25 @@ def get_performance_dashboard():
|
|||||||
today = str(datetime.utcnow().date())
|
today = str(datetime.utcnow().date())
|
||||||
|
|
||||||
start_date = datetime.strptime(
|
start_date = datetime.strptime(
|
||||||
request.args.get("start_date", today), "%Y-%m-%d",
|
request.args.get("start_date", today),
|
||||||
|
"%Y-%m-%d",
|
||||||
|
).date()
|
||||||
|
end_date = datetime.strptime(
|
||||||
|
request.args.get("end_date", today),
|
||||||
|
"%Y-%m-%d",
|
||||||
).date()
|
).date()
|
||||||
end_date = datetime.strptime(request.args.get("end_date", today), "%Y-%m-%d",).date()
|
|
||||||
total_for_all_time = get_total_notifications_for_date_range(
|
total_for_all_time = get_total_notifications_for_date_range(
|
||||||
start_date=None, end_date=None,
|
start_date=None,
|
||||||
|
end_date=None,
|
||||||
)
|
)
|
||||||
total_notifications, emails, sms = transform_results_into_totals(total_for_all_time)
|
total_notifications, emails, sms = transform_results_into_totals(total_for_all_time)
|
||||||
totals_for_date_range = get_total_notifications_for_date_range(
|
totals_for_date_range = get_total_notifications_for_date_range(
|
||||||
start_date=start_date, end_date=end_date,
|
start_date=start_date,
|
||||||
|
end_date=end_date,
|
||||||
)
|
)
|
||||||
processing_time_results = get_processing_time_percentage_for_date_range(
|
processing_time_results = get_processing_time_percentage_for_date_range(
|
||||||
start_date=start_date, end_date=end_date,
|
start_date=start_date,
|
||||||
|
end_date=end_date,
|
||||||
)
|
)
|
||||||
services = get_live_services_with_organization()
|
services = get_live_services_with_organization()
|
||||||
stats = {
|
stats = {
|
||||||
|
|||||||
@@ -644,7 +644,10 @@ def test_get_all_notifications_for_job_by_status(sample_job):
|
|||||||
|
|
||||||
assert len(notifications(filter_dict={"status": status}).items) == 1
|
assert len(notifications(filter_dict={"status": status}).items) == 1
|
||||||
|
|
||||||
assert len(notifications(filter_dict={"status": list(NotificationStatus)[:3]}).items) == 3
|
assert (
|
||||||
|
len(notifications(filter_dict={"status": list(NotificationStatus)[:3]}).items)
|
||||||
|
== 3
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_dao_get_notification_count_for_job_id(notify_db_session):
|
def test_dao_get_notification_count_for_job_id(notify_db_session):
|
||||||
|
|||||||
@@ -244,10 +244,12 @@ def test_create_email_branding_reject_invalid_brand_type(admin_request):
|
|||||||
response = admin_request.post(
|
response = admin_request.post(
|
||||||
"email_branding.create_email_branding", _data=data, _expected_status=400
|
"email_branding.create_email_branding", _data=data, _expected_status=400
|
||||||
)
|
)
|
||||||
|
type_str = ", ".join(
|
||||||
|
[f"<{type(e).__name__}.{e.name}: {e.value}>" for e in BrandType]
|
||||||
|
)
|
||||||
assert (
|
assert (
|
||||||
response["errors"][0]["message"]
|
response["errors"][0]["message"]
|
||||||
== f"brand_type NOT A TYPE is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in BrandType])}]"
|
== f"brand_type NOT A TYPE is not one of [{type_str}]"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -263,7 +265,10 @@ def test_update_email_branding_reject_invalid_brand_type(
|
|||||||
email_branding_id=email_branding.id,
|
email_branding_id=email_branding.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type_str = ", ".join(
|
||||||
|
[f"<{type(e).__name__}.{e.name}: {e.value}>" for e in BrandType]
|
||||||
|
)
|
||||||
assert (
|
assert (
|
||||||
response["errors"][0]["message"]
|
response["errors"][0]["message"]
|
||||||
== f"brand_type NOT A TYPE is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in BrandType])}]"
|
== f"brand_type NOT A TYPE is not one of [{type_str}]"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -127,9 +127,15 @@ def test_create_service_data_retention_returns_400_when_notification_type_is_inv
|
|||||||
json_resp = json.loads(response.get_data(as_text=True))
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert json_resp["errors"][0]["error"] == "ValidationError"
|
assert json_resp["errors"][0]["error"] == "ValidationError"
|
||||||
|
type_str = ", ".join(
|
||||||
|
[
|
||||||
|
f"<{type(e).__name__}.{e.name}: {e.value}>"
|
||||||
|
for e in (NotificationType.SMS, NotificationType.EMAIL)
|
||||||
|
]
|
||||||
|
)
|
||||||
assert (
|
assert (
|
||||||
json_resp["errors"][0]["message"]
|
json_resp["errors"][0]["message"]
|
||||||
== f"notification_type unknown is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in (NotificationType.SMS, NotificationType.EMAIL)])}]"
|
== f"notification_type unknown is not one of [{type_str}]"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -408,9 +408,12 @@ def test_get_all_notifications_filter_by_template_type_invalid_template_type(
|
|||||||
|
|
||||||
assert json_response["status_code"] == 400
|
assert json_response["status_code"] == 400
|
||||||
assert len(json_response["errors"]) == 1
|
assert len(json_response["errors"]) == 1
|
||||||
|
type_str = ", ".join(
|
||||||
|
[f"<{type(e).__name__}.{e.name}: {e.value}>" for e in TemplateType]
|
||||||
|
)
|
||||||
assert (
|
assert (
|
||||||
json_response["errors"][0]["message"]
|
json_response["errors"][0]["message"]
|
||||||
== f"template_type orange is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in TemplateType])}]"
|
== f"template_type orange is not one of [{type_str}]"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -461,9 +464,12 @@ def test_get_all_notifications_filter_by_status_invalid_status(
|
|||||||
|
|
||||||
assert json_response["status_code"] == 400
|
assert json_response["status_code"] == 400
|
||||||
assert len(json_response["errors"]) == 1
|
assert len(json_response["errors"]) == 1
|
||||||
|
type_str = ", ".join(
|
||||||
|
[f"<{type(e).__name__}.{e.name}: {e.value}>" for e in NotificationStatus]
|
||||||
|
)
|
||||||
assert (
|
assert (
|
||||||
json_response["errors"][0]["message"]
|
json_response["errors"][0]["message"]
|
||||||
== f"status elephant is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in NotificationStatus])}]"
|
== f"status elephant is not one of [{type_str}]"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ 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 = f"is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in NotificationStatus])}]"
|
type_str = ", ".join(
|
||||||
|
[f"<{type(e).__name__}.{e.name}: {e.value}>" for e in NotificationStatus]
|
||||||
|
)
|
||||||
|
partial_error_status = f"is not one of [{type_str}]"
|
||||||
|
|
||||||
with pytest.raises(ValidationError) as e:
|
with pytest.raises(ValidationError) as e:
|
||||||
validate(
|
validate(
|
||||||
@@ -70,7 +73,10 @@ 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 = f"is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in TemplateType])}]"
|
type_str = ", ".join(
|
||||||
|
[f"<{type(e).__name__}.{e.name}: {e.value}>" for e in TemplateType]
|
||||||
|
)
|
||||||
|
partial_error_template_type = f"is not one of [{type_str}]"
|
||||||
|
|
||||||
with pytest.raises(ValidationError) as e:
|
with pytest.raises(ValidationError) as e:
|
||||||
validate(
|
validate(
|
||||||
@@ -101,15 +107,18 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
|
|||||||
assert len(errors) == 4
|
assert len(errors) == 4
|
||||||
|
|
||||||
error_messages = [error["message"] for error in errors]
|
error_messages = [error["message"] for error in errors]
|
||||||
|
type_str = ", ".join(
|
||||||
|
[f"<{type(e).__name__}.{e.name}: {e.value}>" for e in NotificationStatus]
|
||||||
|
)
|
||||||
for invalid_status in ["elephant", "giraffe"]:
|
for invalid_status in ["elephant", "giraffe"]:
|
||||||
assert (
|
assert f"status {invalid_status} is not one of [{type_str}]" in error_messages
|
||||||
f"status {invalid_status} is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in NotificationStatus])}]"
|
|
||||||
in error_messages
|
|
||||||
)
|
|
||||||
|
|
||||||
|
type_str = ", ".join(
|
||||||
|
[f"<{type(e).__name__}.{e.name}: {e.value}>" for e in TemplateType]
|
||||||
|
)
|
||||||
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 [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in TemplateType])}]"
|
f"template_type {invalid_template_type} is not one of [{type_str}]"
|
||||||
in error_messages
|
in error_messages
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -116,11 +116,14 @@ def test_get_all_templates_for_invalid_type_returns_400(client, sample_service):
|
|||||||
|
|
||||||
json_response = json.loads(response.get_data(as_text=True))
|
json_response = json.loads(response.get_data(as_text=True))
|
||||||
|
|
||||||
|
type_str = ", ".join(
|
||||||
|
[f"<{type(e).__name__}.{e.name}: {e.value}>" for e in TemplateType]
|
||||||
|
)
|
||||||
assert json_response == {
|
assert json_response == {
|
||||||
"status_code": 400,
|
"status_code": 400,
|
||||||
"errors": [
|
"errors": [
|
||||||
{
|
{
|
||||||
"message": f"type coconut is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in TemplateType])}]",
|
"message": f"type coconut is not one of [{type_str}]",
|
||||||
"error": "ValidationError",
|
"error": "ValidationError",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -278,10 +278,10 @@ def test_get_all_template_request_schema_against_invalid_args_is_invalid(templat
|
|||||||
|
|
||||||
assert errors["status_code"] == 400
|
assert errors["status_code"] == 400
|
||||||
assert len(errors["errors"]) == 1
|
assert len(errors["errors"]) == 1
|
||||||
assert (
|
type_str = ", ".join(
|
||||||
errors["errors"][0]["message"]
|
[f"<{type(e).__name__}.{e.name}: {e.value}>" for e in TemplateType]
|
||||||
== f"type unknown is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in TemplateType])}]"
|
|
||||||
)
|
)
|
||||||
|
assert errors["errors"][0]["message"] == f"type unknown is not one of [{type_str}]"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("response", valid_json_get_all_response)
|
@pytest.mark.parametrize("response", valid_json_get_all_response)
|
||||||
|
|||||||
Reference in New Issue
Block a user