test_async_client.py
This file
Path
tests/client/test_async_client.py
131 lines · 4.3 KiB · Python
Last changed by
Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
History of this fileTake it
Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 1–2why, one step back1import pytest2Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 3why, one step back3import httpxMerge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 4–5why, one step back45Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 6why, one step back6async def test_get(server, backend):Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 7why, one step back7 url = server.urlParametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 8why, one step back8 async with httpx.AsyncClient(backend=backend) as client:Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 9–11why, one step back9 response = await client.get(url)10 assert response.status_code == 20011 assert response.text == "Hello, world!"Response.protocol -> Response.http_version (#250)Tom Christiebefore adoptionc1ec1c3
line 12why, one step back12 assert response.http_version == "HTTP/1.1"Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
line 13why, one step back13 assert response.headersFixed response repr. (#101)updatatodaybefore adoptionf9e3ad4
line 14why, one step back14 assert repr(response) == "<Response [200 OK]>"Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 15–17why, one step back151617@pytest.mark.asyncioParametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 18–21why, one step back18async def test_get_no_backend(server):19 """20 Verify that the client is capable of making a simple request if not given a backend.21 """Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 22why, one step back22 url = server.urlRenaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 23why, one step back23 async with httpx.AsyncClient() as client:Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 24–32why, one step back24 response = await client.get(url)25 assert response.status_code == 20026 assert response.text == "Hello, world!"27 assert response.http_version == "HTTP/1.1"28 assert response.headers29 assert repr(response) == "<Response [200 OK]>"303132async def test_post(server, backend):Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 33why, one step back33 url = server.urlParametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 34why, one step back34 async with httpx.AsyncClient(backend=backend) as client:Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 35–38why, one step back35 response = await client.post(url, data=b"Hello, world!")36 assert response.status_code == 2003738Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 39why, one step back39async def test_post_json(server, backend):Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 40why, one step back40 url = server.urlParametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 41why, one step back41 async with httpx.AsyncClient(backend=backend) as client:Add json interfacesTom Christiebefore adoption5a63d31
lines 42–45why, one step back42 response = await client.post(url, json={"text": "Hello, world!"})43 assert response.status_code == 2004445Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 46–47why, one step back46async def test_stream_response(server, backend):47 async with httpx.AsyncClient(backend=backend) as client:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 48why, one step back48 response = await client.request("GET", server.url, stream=True)Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 49–54why, one step back49 assert response.status_code == 20050 body = await response.read()51 assert body == b"Hello, world!"52 assert response.content == b"Hello, world!"5354Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 55–56why, one step back55async def test_access_content_stream_response(server, backend):56 async with httpx.AsyncClient(backend=backend) as client:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 57why, one step back57 response = await client.request("GET", server.url, stream=True)Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
line 58why, one step back58 assert response.status_code == 200Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 59why, one step back59 with pytest.raises(httpx.ResponseNotRead):Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 60–62why, one step back60 response.content6162Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 63why, one step back63async def test_stream_request(server, backend):Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 64–67why, one step back64 async def hello_world():65 yield b"Hello, "66 yield b"world!"67Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 68why, one step back68 async with httpx.AsyncClient(backend=backend) as client:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 69why, one step back69 response = await client.request("POST", server.url, data=hello_world())Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 70–72why, one step back70 assert response.status_code == 2007172Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 73–74why, one step back73async def test_raise_for_status(server, backend):74 async with httpx.AsyncClient(backend=backend) as client:Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 75–76why, one step back75 for status_code in (200, 400, 404, 500, 505):76 response = await client.request(Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 77why, one step back77 "GET", server.url.copy_with(path=f"/status/{status_code}")Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 78–80why, one step back78 )7980 if 400 <= status_code < 600:Added base class HTTPError with request/response attribute (#162)halbowbefore adoption92fbe5f
line 81why, one step back81 with pytest.raises(httpx.exceptions.HTTPError) as exc_info:Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
line 82why, one step back82 response.raise_for_status()Added base class HTTPError with request/response attribute (#162)halbowbefore adoption92fbe5f
line 83why, one step back83 assert exc_info.value.response == responseMerge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 84–87why, one step back84 else:85 assert response.raise_for_status() is None8687Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 88–89why, one step back88async def test_options(server, backend):89 async with httpx.AsyncClient(backend=backend) as client:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 90why, one step back90 response = await client.options(server.url)Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 91–94why, one step back91 assert response.status_code == 20092 assert response.text == "Hello, world!"9394Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 95–96why, one step back95async def test_head(server, backend):96 async with httpx.AsyncClient(backend=backend) as client:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 97why, one step back97 response = await client.head(server.url)Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 98–101why, one step back98 assert response.status_code == 20099 assert response.text == ""100101Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 102–103why, one step back102async def test_put(server, backend):103 async with httpx.AsyncClient(backend=backend) as client:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 104why, one step back104 response = await client.put(server.url, data=b"Hello, world!")Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 105–107why, one step back105 assert response.status_code == 200106107Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 108–109why, one step back108async def test_patch(server, backend):109 async with httpx.AsyncClient(backend=backend) as client:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 110why, one step back110 response = await client.patch(server.url, data=b"Hello, world!")Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 111–113why, one step back111 assert response.status_code == 200112113Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 114–115why, one step back114async def test_delete(server, backend):115 async with httpx.AsyncClient(backend=backend) as client:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 116why, one step back116 response = await client.delete(server.url)Merge pull request #56 from yeraydiazdiaz/test-additional-http-methodsTom Christiebefore adoption87cab4c
lines 117–118why, one step back117 assert response.status_code == 200118 assert response.text == "Hello, world!"Add 100-continue test (#68)Tom Christiebefore adoption4fe6bc0
lines 119–120why, one step back119120Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 121why, one step back121async def test_100_continue(server, backend):Add 100-continue test (#68)Tom Christiebefore adoption4fe6bc0
lines 122–124why, one step back122 headers = {"Expect": "100-continue"}123 data = b"Echo request body"124Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 125why, one step back125 async with httpx.AsyncClient(backend=backend) as client:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
lines 126–128why, one step back126 response = await client.post(127 server.url.copy_with(path="/echo_body"), headers=headers, data=data128 )Add 100-continue test (#68)Tom Christiebefore adoption4fe6bc0
lines 129–131why, one step back129130 assert response.status_code == 200131 assert response.content == data