Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show more information on assert_response when status code fails #209

Open
cancan101 opened this issue Aug 7, 2018 · 2 comments
Open

Show more information on assert_response when status code fails #209

cancan101 opened this issue Aug 7, 2018 · 2 comments

Comments

@cancan101
Copy link
Contributor

Right now assert_response first checks the status_code:

assert response.status_code == expected_status_code

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

...
@itajaja
Copy link
Member

itajaja commented Aug 7, 2018

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

@taion
Copy link
Contributor

taion commented Aug 7, 2018

yeah we should hook into some better formatting here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants