bravado-core icon indicating copy to clipboard operation
bravado-core copied to clipboard

Validate response body fails on empty response with Python 3

Open gabisurita opened this issue 8 years ago • 1 comments

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''

gabisurita avatar Dec 05 '16 18:12 gabisurita

Currently EMPTY_BODIES is defined as (None, '', '{}', 'null'). For Python 3 compatibility, this should probably be (None, b'', u'', '{}', 'null').

ngaya-ll avatar Aug 16 '17 21:08 ngaya-ll