mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 16:31:15 -05: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",
|
||||
"title": "Send an uploaded pdf letter",
|
||||
"properties": {
|
||||
"postage": {"enum": ["first", "second"]},
|
||||
"postage": {"type": "string", "format": "postage"},
|
||||
"filename": {"type": "string"},
|
||||
"created_by": {"type": "string"},
|
||||
"file_id": {"type": "string"},
|
||||
},
|
||||
|
||||
"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}
|
||||
|
||||
|
||||
def test_create_pdf_letter_validates_against_json_schema(sample_service_full_permissions, client):
|
||||
response = client.post(
|
||||
url_for('service.create_pdf_letter', service_id=sample_service_full_permissions.id),
|
||||
data=json.dumps({}),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()]
|
||||
)
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert response.status_code == 400
|
||||
assert json_resp['errors'] == [
|
||||
@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(
|
||||
url_for('service.create_pdf_letter', service_id=sample_service_full_permissions.id),
|
||||
data=json.dumps(post_data),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()]
|
||||
)
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert response.status_code == 400
|
||||
assert json_resp['errors'] == expected_errors
|
||||
|
||||
|
||||
def test_get_notification_for_service_includes_template_redacted(admin_request, sample_notification):
|
||||
|
||||
Reference in New Issue
Block a user