mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 13:59:49 -04:00
Use existing postage format for validation
Also adds explicit test for checking of postage
This commit is contained in:
@@ -4,11 +4,10 @@ send_pdf_letter_request = {
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"title": "Send an uploaded pdf letter",
|
"title": "Send an uploaded pdf letter",
|
||||||
"properties": {
|
"properties": {
|
||||||
"postage": {"enum": ["first", "second"]},
|
"postage": {"type": "string", "format": "postage"},
|
||||||
"filename": {"type": "string"},
|
"filename": {"type": "string"},
|
||||||
"created_by": {"type": "string"},
|
"created_by": {"type": "string"},
|
||||||
"file_id": {"type": "string"},
|
"file_id": {"type": "string"},
|
||||||
},
|
},
|
||||||
|
|
||||||
"required": ["postage", "filename", "created_by", "file_id"]
|
"required": ["postage", "filename", "created_by", "file_id"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2297,21 +2297,35 @@ def test_create_pdf_letter(mocker, sample_service_full_permissions, client, fake
|
|||||||
assert json_resp == {'id': fake_uuid}
|
assert json_resp == {'id': fake_uuid}
|
||||||
|
|
||||||
|
|
||||||
def test_create_pdf_letter_validates_against_json_schema(sample_service_full_permissions, client):
|
@pytest.mark.parametrize('post_data, expected_errors', [
|
||||||
|
(
|
||||||
|
{},
|
||||||
|
[
|
||||||
|
{'error': 'ValidationError', 'message': 'postage is a required property'},
|
||||||
|
{'error': 'ValidationError', 'message': 'filename is a required property'},
|
||||||
|
{'error': 'ValidationError', 'message': 'created_by is a required property'},
|
||||||
|
{'error': 'ValidationError', 'message': 'file_id is a required property'}
|
||||||
|
]
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{"postage": "third", "filename": "string", "created_by": "string", "file_id": "string"},
|
||||||
|
[
|
||||||
|
{'error': 'ValidationError', 'message': 'postage invalid. It must be either first or second.'}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
])
|
||||||
|
def test_create_pdf_letter_validates_against_json_schema(
|
||||||
|
sample_service_full_permissions, client, post_data, expected_errors
|
||||||
|
):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
url_for('service.create_pdf_letter', service_id=sample_service_full_permissions.id),
|
url_for('service.create_pdf_letter', service_id=sample_service_full_permissions.id),
|
||||||
data=json.dumps({}),
|
data=json.dumps(post_data),
|
||||||
headers=[('Content-Type', 'application/json'), create_authorization_header()]
|
headers=[('Content-Type', 'application/json'), create_authorization_header()]
|
||||||
)
|
)
|
||||||
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'] == [
|
assert json_resp['errors'] == expected_errors
|
||||||
{'error': 'ValidationError', 'message': 'postage is a required property'},
|
|
||||||
{'error': 'ValidationError', 'message': 'filename is a required property'},
|
|
||||||
{'error': 'ValidationError', 'message': 'created_by is a required property'},
|
|
||||||
{'error': 'ValidationError', 'message': 'file_id is a required property'}
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_notification_for_service_includes_template_redacted(admin_request, sample_notification):
|
def test_get_notification_for_service_includes_template_redacted(admin_request, sample_notification):
|
||||||
|
|||||||
Reference in New Issue
Block a user