flask-resty icon indicating copy to clipboard operation
flask-resty copied to clipboard

Show more information on assert_response when status code fails

Open cancan101 opened this issue 5 years ago • 2 comments

Right now assert_response first checks the status_code: https://github.com/4Catalyzer/flask-resty/blob/289e4fff0909b54c8677701f87a4ee393099efc7/flask_resty/testing.py#L106 however this doesn't print any information as to what the error was other than the status code. In many cases, seeing the contents of errors is helpful for diagnosing the problem. This is especially true when a 200 is expected but some other error happens yielding a 4XX error.

I suggest something like:

def assert_response(response, expected_status_code, expected_data=UNDEFINED):
    if 200 <= response.status_code < 300:
        response_data = get_data(response)
    else:
        response_data = get_errors(response)

    assert response.status_code == expected_status_code, response_data

    if expected_data is UNDEFINED:
        return

...

cancan101 avatar Aug 07 '18 17:08 cancan101

I would wrap the assertion in a try/except block, print the raw response text and reraise. feel free to PR :)

itajaja avatar Aug 07 '18 17:08 itajaja

yeah we should hook into some better formatting here

taion avatar Aug 07 '18 17:08 taion