From: Matus Ferech Date: Sat, 4 May 2019 15:44:35 +0000 (+0200) Subject: Test `raise_for_status` X-Git-Tag: 0.3.0~41^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c628eb061ced1c213c9dca8046930ac2657c5589;p=thirdparty%2Fhttpx.git Test `raise_for_status` --- diff --git a/tests/test_client.py b/tests/test_client.py index 43a33bef..1d33379c 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -50,3 +50,18 @@ async def test_stream_request(server): "POST", "http://127.0.0.1:8000/", content=hello_world() ) assert response.status_code == 200 + + +@pytest.mark.asyncio +async def test_raise_for_status(server): + async with httpcore.Client() as client: + for status_code in (200, 400, 404, 500, 505): + response = await client.request( + "GET", f"http://127.0.0.1:8000/status/{status_code}" + ) + + if 400 <= status_code < 600: + with pytest.raises(httpcore.exceptions.HttpError): + response.raise_for_status() + else: + assert response.raise_for_status() is None