test_api.py
This file
Path
tests/test_api.py
43 lines · 1.2 KiB · Python
Last changed by
AdaptersTom Christiebefore adoptionfab6fcd
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):AdaptersTom Christiebefore adoptionfab6fcd
lines 8–9why, one step back8 async with httpcore.Client() as client:9 response = await client.request("GET", "http://127.0.0.1:8000/")StuffTom Christiebefore adoption30530d4
lines 10–14why, one step back10 assert response.status_code == 20011 assert response.body == b"Hello, world!"121314@pytest.mark.asyncioMerge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
line 15why, one step back15async def test_post(server):AdaptersTom Christiebefore adoptionfab6fcd
lines 16–17why, one step back16 async with httpcore.Client() as client:17 response = await client.request(Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
lines 18–19why, one step back18 "POST", "http://127.0.0.1:8000/", body=b"Hello, world!"19 )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):AdaptersTom Christiebefore adoptionfab6fcd
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 back38AdaptersTom Christiebefore adoptionfab6fcd
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