test_api.py
This file
Path
tests/test_api.py
43 lines · 1.2 KiB · Python
Last changed by
Finessing interfaceTom Christiebefore adoptiond7619a9
History of this fileTake it
StuffTom Christiebefore adoption30530d4
lines 1–6why, one step back1import pytest23import httpcore456@pytest.mark.asyncioMerge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
line 7why, one step back7async def test_get(server):Finessing interfaceTom Christiebefore adoptiond7619a9
line 8why, one step back8 url = "http://127.0.0.1:8000/"Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 9why, one step back9 async with httpcore.Client() as client:Finessing interfaceTom Christiebefore adoptiond7619a9
line 10why, one step back10 response = await client.get(url)StuffTom Christiebefore adoption30530d4
lines 11–15why, one step back11 assert response.status_code == 20012 assert response.body == b"Hello, world!"131415@pytest.mark.asyncioMerge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
line 16why, one step back16async def test_post(server):Finessing interfaceTom Christiebefore adoptiond7619a9
line 17why, one step back17 url = "http://127.0.0.1:8000/"Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 18why, one step back18 async with httpcore.Client() as client:Finessing interfaceTom Christiebefore adoptiond7619a9
line 19why, one step back19 response = await client.post(url, body=b"Hello, world!")StuffTom Christiebefore adoption30530d4
lines 20–23why, one step back20 assert response.status_code == 200212223@pytest.mark.asyncioMerge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
line 24why, one step back24async def test_stream_response(server):Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 25–26why, one step back25 async with httpcore.Client() as client:26 response = await client.request("GET", "http://127.0.0.1:8000/", stream=True)StuffTom Christiebefore adoption30530d4
line 27why, one step back27 assert response.status_code == 200Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
line 28why, one step back28 assert not hasattr(response, "body")StuffTom Christiebefore adoption30530d4
lines 29–33why, one step back29 body = await response.read()30 assert body == b"Hello, world!"313233@pytest.mark.asyncioMerge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
lines 34–37why, one step back34async def test_stream_request(server):35 async def hello_world():36 yield b"Hello, "37 yield b"world!"StuffTom Christiebefore adoption30530d4
line 38why, one step back38Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 39–40why, one step back39 async with httpcore.Client() as client:40 response = await client.request(Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
lines 41–42why, one step back41 "POST", "http://127.0.0.1:8000/", body=hello_world()42 )StuffTom Christiebefore adoption30530d4
line 43why, one step back43 assert response.status_code == 200