def test_post_raises_exception_on_error_if_raises_exception_is_true( responses, fake_url): responses.add( responses.POST, "{}/fake-resource/".format(fake_url), json=[{ "code": "unsupported", "message": "Wait, that's illegal!" }], status=400, ) session = APISession(fake_url) with pytest.raises(RequestError) as exc: session.post("/fake-resource/", {}, raise_exception=True) assert exc.value.status_code == 400 assert exc.value.detail == [{ "code": "unsupported", "message": "Wait, that's illegal!" }] assert responses.calls[0].request.headers[ "Content-Type"] == "application/json"
def test_post_doesnt_raise_exception_on_error_by_default(responses, fake_url): responses.add( responses.POST, "{}/fake-resource/".format(fake_url), json=[{ "code": "unsupported", "message": "Wait, that's illegal!" }], status=400, ) session = APISession(fake_url) result = session.post("/fake-resource/", {}) assert result == [{ "code": "unsupported", "message": "Wait, that's illegal!" }] assert responses.calls[0].request.headers[ "Content-Type"] == "application/json"