snok/drf-openapi-tester

Fix response unpacking

Closed this issue · 0 comments

Our unpack_response function currently contains this piece of code:

    try:
        return response.json(), status_code
    except Exception as e:
        if status_code == 204:
            raise ImproperlyConfigured(
                'Response returned a 204, indicating no response. There is no response JSON to test.'
            )
        raise ValueError(f'Unable to unpack response object. Error: {e}')

The status code check was implemented to fix a bug I was experiencing while implementing the package, but on reflection, the solution is fundamentally flawed.

Instead of checking the response code, we should check for a response attribute, and raise an ImproperlyConfigured-error saying that we cannot compare the response to the response schema, without a response object.