mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
More fixes for everyone.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -58,9 +58,7 @@ def test_get_notifications_request_invalid_statuses(invalid_statuses, valid_stat
|
|||||||
errors = json.loads(str(e.value)).get("errors")
|
errors = json.loads(str(e.value)).get("errors")
|
||||||
assert len(errors) == len(invalid_statuses)
|
assert len(errors) == len(invalid_statuses)
|
||||||
for index, value in enumerate(invalid_statuses):
|
for index, value in enumerate(invalid_statuses):
|
||||||
assert errors[index]["message"] == "status {} {}".format(
|
assert errors[index]["message"] == f"status {value} {partial_error_status}"
|
||||||
value, partial_error_status
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@@ -71,13 +69,13 @@ def test_get_notifications_request_invalid_statuses(invalid_statuses, valid_stat
|
|||||||
# multiple invalid template_types
|
# multiple invalid template_types
|
||||||
(["orange", "avocado", "banana"], []),
|
(["orange", "avocado", "banana"], []),
|
||||||
# one bad template_type and one good template_type
|
# one bad template_type and one good template_type
|
||||||
(["orange"], ["sms"]),
|
(["orange"], [TemplateType.SMS]),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
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]"
|
partial_error_template_type = "is not one of [sms, email, letter]"
|
||||||
|
|
||||||
with pytest.raises(ValidationError) as e:
|
with pytest.raises(ValidationError) as e:
|
||||||
validate(
|
validate(
|
||||||
@@ -88,8 +86,8 @@ def test_get_notifications_request_invalid_template_types(
|
|||||||
errors = json.loads(str(e.value)).get("errors")
|
errors = json.loads(str(e.value)).get("errors")
|
||||||
assert len(errors) == len(invalid_template_types)
|
assert len(errors) == len(invalid_template_types)
|
||||||
for index, value in enumerate(invalid_template_types):
|
for index, value in enumerate(invalid_template_types):
|
||||||
assert errors[index]["message"] == "template_type {} {}".format(
|
assert errors[index]["message"] == (
|
||||||
value, partial_error_template_type
|
f"template_type {value} {partial_error_template_type}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -97,8 +95,8 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
|
|||||||
with pytest.raises(ValidationError) as e:
|
with pytest.raises(ValidationError) as e:
|
||||||
validate(
|
validate(
|
||||||
{
|
{
|
||||||
"status": ["created", "elephant", "giraffe"],
|
"status": [NotificationStatus.CREATED, "elephant", "giraffe"],
|
||||||
"template_type": ["sms", "orange", "avocado"],
|
"template_type": [TemplateType.SMS, "orange", "avocado"],
|
||||||
},
|
},
|
||||||
get_notifications_request,
|
get_notifications_request,
|
||||||
)
|
)
|
||||||
@@ -110,17 +108,15 @@ 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 (
|
||||||
"status {} is not one of [cancelled, created, sending, sent, delivered, "
|
f"status {invalid_status} is not one of [cancelled, created, sending, sent, delivered, "
|
||||||
"pending, failed, technical-failure, temporary-failure, permanent-failure, "
|
"pending, failed, technical-failure, temporary-failure, permanent-failure, "
|
||||||
"pending-virus-check, validation-failed, virus-scan-failed]".format(
|
"pending-virus-check, validation-failed, virus-scan-failed]"
|
||||||
invalid_status
|
|
||||||
)
|
|
||||||
in error_messages
|
in error_messages
|
||||||
)
|
)
|
||||||
|
|
||||||
for invalid_template_type in ["orange", "avocado"]:
|
for invalid_template_type in ["orange", "avocado"]:
|
||||||
assert (
|
assert (
|
||||||
"template_type {} is not one of [sms, email]".format(invalid_template_type)
|
f"template_type {invalid_template_type} is not one of [sms, email, letter]"
|
||||||
in error_messages
|
in error_messages
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ def test_get_all_templates_returns_200(client, sample_service):
|
|||||||
create_template(
|
create_template(
|
||||||
sample_service,
|
sample_service,
|
||||||
template_type=tmp_type,
|
template_type=tmp_type,
|
||||||
subject="subject_{}".format(name) if tmp_type == TemplateType.EMAIL else "",
|
subject=f"subject_{name}" if tmp_type == TemplateType.EMAIL else "",
|
||||||
template_name=name,
|
template_name=name,
|
||||||
)
|
)
|
||||||
for name, tmp_type in product(("A", "B", "C"), TemplateType)
|
for name, tmp_type in product(("A", "B", "C"), TemplateType)
|
||||||
@@ -47,8 +47,8 @@ def test_get_all_templates_for_valid_type_returns_200(client, sample_service, tm
|
|||||||
create_template(
|
create_template(
|
||||||
sample_service,
|
sample_service,
|
||||||
template_type=tmp_type,
|
template_type=tmp_type,
|
||||||
template_name="Template {}".format(i),
|
template_name=f"Template {i}",
|
||||||
subject="subject_{}".format(i) if tmp_type == TemplateType.EMAIL else "",
|
subject=f"subject_{i}" if tmp_type == TemplateType.EMAIL else "",
|
||||||
)
|
)
|
||||||
for i in range(3)
|
for i in range(3)
|
||||||
]
|
]
|
||||||
@@ -56,7 +56,7 @@ def test_get_all_templates_for_valid_type_returns_200(client, sample_service, tm
|
|||||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
path="/v2/templates?type={}".format(tmp_type),
|
path=f"/v2/templates?type={tmp_type}",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ def test_get_correct_num_templates_for_valid_type_returns_200(
|
|||||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
path="/v2/templates?type={}".format(tmp_type),
|
path=f"/v2/templates?type={tmp_type}",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ def test_get_all_templates_for_invalid_type_returns_400(client, sample_service):
|
|||||||
invalid_type = "coconut"
|
invalid_type = "coconut"
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
path="/v2/templates?type={}".format(invalid_type),
|
path=f"/v2/templates?type={invalid_type}",
|
||||||
headers=[("Content-Type", "application/json"), auth_header],
|
headers=[("Content-Type", "application/json"), auth_header],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -122,7 +122,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]",
|
"message": "type coconut is not one of [sms, email, letter]",
|
||||||
"error": "ValidationError",
|
"error": "ValidationError",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ 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 errors["errors"][0]["message"] == "type unknown is not one of [sms, email]"
|
assert errors["errors"][0]["message"] == "type unknown is not one of [sms, email, letter]"
|
||||||
|
|
||||||
|
|
||||||
@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