bravado-core
bravado-core copied to clipboard
Validate response body fails on empty response with Python 3
I'm writing a test suite with .tox to validate a spec against an existing API and this error is raised with Python 3.4 and Python3.5. Apparently empty bytearrays aren't considered on EMPTY_BODIES
.
def validate_response_body(op, response_spec, response):
"""Validate an outgoing response's body against the response's Swagger
specification.
:type op: :class:`bravado_core.operation.Operation`
:type response_spec: dict
:type response: :class:`bravado_core.response.OutgoingResponse`
:raises: SwaggerMappingError
"""
deref = op.swagger_spec.deref
# response that returns nothing in the body
response_body_spec = deref(response_spec.get('schema'))
if response_body_spec is None:
if response.text in EMPTY_BODIES:
return
raise SwaggerMappingError(
> "Response body should be empty: {0}".format(response.text))
E bravado_core.exception.SwaggerMappingError: Response body should be empty: b''
Currently EMPTY_BODIES
is defined as (None, '', '{}', 'null')
. For Python 3 compatibility, this should probably be (None, b'', u'', '{}', 'null')
.