Skip to content
Myr

Add tests for additional HTTP methods on async client

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add tests for raise_for_status and SyncResponse properties

authored by Yeray Diaz Diaz · committed by Yeray Diaz Diaz · parent e46ee49 · Browse files · 3 files+77 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+77 added−9 removed

  • tests:+73 added−9 removed
  • other:+4 added−0 removed

3 files+77 added−9 removed

modified:httpcore/models.py+4 added
820 unmodified lines
821 break822823 def close(self) -> None:824 return self._loop.run_until_complete(self._response.close())825826 def __repr__(self) -> str:827 class_name = self.__class__.__name__828 return f"<{class_name}({self.status_code}, {self.reason_phrase!r})>"
modified:tests/client/test_async_client.py+46 added
8 unmodified lines
9 async with httpcore.AsyncClient() as client:10 response = await client.get(url)11 assert response.status_code == 20012 assert response.text == "Hello, world!"13 assert response.protocol == "HTTP/1.1"14 assert response.headers15 assert repr(response) == "<Response(200, 'OK')>"161718@pytest.mark.asyncio19async def test_post(server):
47 unmodified lines
67 with pytest.raises(httpcore.exceptions.HttpError):68 response.raise_for_status()69 else:70 assert response.raise_for_status() is None717273@pytest.mark.asyncio74async def test_options(server):75 url = "http://127.0.0.1:8000/"76 async with httpcore.AsyncClient() as client:77 response = await client.options(url)78 assert response.status_code == 20079 assert response.text == "Hello, world!"808182@pytest.mark.asyncio83async def test_head(server):84 url = "http://127.0.0.1:8000/"85 async with httpcore.AsyncClient() as client:86 response = await client.head(url)87 assert response.status_code == 20088 assert response.text == ""899091@pytest.mark.asyncio92async def test_put(server):93 url = "http://127.0.0.1:8000/"94 async with httpcore.AsyncClient() as client:95 response = await client.put(url, data=b"Hello, world!")96 assert response.status_code == 200979899@pytest.mark.asyncio100async def test_patch(server):101 url = "http://127.0.0.1:8000/"102 async with httpcore.AsyncClient() as client:103 response = await client.patch(url, data=b"Hello, world!")104 assert response.status_code == 200105106107@pytest.mark.asyncio108async def test_delete(server):109 url = "http://127.0.0.1:8000/"110 async with httpcore.AsyncClient() as client:111 response = await client.delete(url)112 assert response.status_code == 200113 assert response.text == "Hello, world!"
modified:tests/client/test_client.py+27 added-9 removed
23 unmodified lines
242526@threadpool27def test_get(server):28 url = "http://127.0.0.1:8000/"29 with httpcore.Client() as http:29 response = http.get("http://127.0.0.1:8000/")30 response = http.get(url)31 assert response.status_code == 20032 assert response.url == httpcore.URL(url)33 assert response.content == b"Hello, world!"34 assert response.text == "Hello, world!"35 assert response.protocol == "HTTP/1.1"36 assert response.encoding == "iso-8859-1"37 assert response.request.url == httpcore.URL(url)38 assert response.headers39 assert response.is_redirect is False35 assert repr(response) == "<SyncResponse(status_code=200)>"40 assert repr(response) == "<SyncResponse(200, 'OK')>"414243@threadpool44def test_post(server):
35 unmodified lines
80 response.close() # TODO: should Response be available as context managers?818283@threadpool84def test_raise_for_status(server):85 with httpcore.Client() as client:86 for status_code in (200, 400, 404, 500, 505):87 response = client.request(88 "GET", "http://127.0.0.1:8000/status/{}".format(status_code)89 )9091 if 400 <= status_code < 600:92 with pytest.raises(httpcore.exceptions.HttpError):93 response.raise_for_status()94 else:95 assert response.raise_for_status() is None969798@threadpool99def test_options(server):80 with httpcore.SyncClient() as http:100 with httpcore.Client() as http:101 response = http.options("http://127.0.0.1:8000/")82102 assert response.status_code == 200103 assert response.reason_phrase == "OK"104105106@threadpool107def test_head(server):89 with httpcore.SyncClient() as http:108 with httpcore.Client() as http:109 response = http.head("http://127.0.0.1:8000/")91110 assert response.status_code == 200111 assert response.reason_phrase == "OK"112113114@threadpool115def test_put(server):98 with httpcore.SyncClient() as http:116 with httpcore.Client() as http:117 response = http.put("http://127.0.0.1:8000/", data=b"Hello, world!")118 assert response.status_code == 200119 assert response.reason_phrase == "OK"120121122@threadpool123def test_patch(server):106 with httpcore.SyncClient() as http:124 with httpcore.Client() as http:125 response = http.patch("http://127.0.0.1:8000/", data=b"Hello, world!")126 assert response.status_code == 200127 assert response.reason_phrase == "OK"128129130@threadpool131def test_delete(server):114 with httpcore.SyncClient() as http:132 with httpcore.Client() as http:133 response = http.delete("http://127.0.0.1:8000/")134 assert response.status_code == 200135 assert response.reason_phrase == "OK"