]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Test `raise_for_status` 39/head
authorMatus Ferech <matus.ferech@telekom.com>
Sat, 4 May 2019 15:44:35 +0000 (17:44 +0200)
committerMatus Ferech <matus.ferech@telekom.com>
Sat, 4 May 2019 15:44:35 +0000 (17:44 +0200)
tests/test_client.py

index 43a33bef7aa2e8f4979e0ac7fc5f0ae979e3d49b..1d33379c60be03c66d2ccebacb16e1dfe9e06a26 100644 (file)
@@ -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