mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Validate content length on broadcast API
The maximum content count of a broadcast varies depending on its encoding, so we can’t simply validate it against a schema. This commit moves to using the validation from `notifications-utils`, and raising a custom error response.
This commit is contained in:
@@ -191,3 +191,34 @@ def test_unsupported_message_types_400(
|
||||
} in (
|
||||
json.loads(response.get_data(as_text=True))['errors']
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('xml_document, expected_error', (
|
||||
(sample_cap_xml_documents.LONG_UCS2, (
|
||||
'description must be 615 characters or fewer (because it '
|
||||
'could not be GSM7 encoded)'
|
||||
)),
|
||||
(sample_cap_xml_documents.LONG_GSM7, (
|
||||
'description must be 1,395 characters or fewer'
|
||||
)),
|
||||
))
|
||||
def test_content_too_long_returns_400(
|
||||
client,
|
||||
sample_broadcast_service,
|
||||
xml_document,
|
||||
expected_error,
|
||||
):
|
||||
auth_header = create_authorization_header(service_id=sample_broadcast_service.id)
|
||||
response = client.post(
|
||||
path='/v2/broadcast',
|
||||
data=xml_document,
|
||||
headers=[('Content-Type', 'application/cap+xml'), auth_header],
|
||||
)
|
||||
|
||||
assert json.loads(response.get_data(as_text=True)) == {
|
||||
'errors': [{
|
||||
'error': 'ValidationError',
|
||||
'message': expected_error,
|
||||
}],
|
||||
'status_code': 400,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user