test_api.py
This file
Path
tests/test_api.py
45 lines · 1.4 KiB · Python
Last changed by
Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498
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):Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498
lines 8–10why, one step back8 async with httpcore.ConnectionPool() as client:9 request = httpcore.Request("GET", "http://127.0.0.1:8000/")10 response = await client.send(request)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):Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498
lines 17–18why, one step back17 async with httpcore.ConnectionPool() as client:18 request = httpcore.Request(Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
lines 19–20why, one step back19 "POST", "http://127.0.0.1:8000/", body=b"Hello, world!"20 )Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498
line 21why, one step back21 response = await client.send(request)StuffTom Christiebefore adoption30530d4
lines 22–25why, one step back22 assert response.status_code == 200232425@pytest.mark.asyncioMerge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
line 26why, one step back26async def test_stream_response(server):Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498
lines 27–29why, one step back27 async with httpcore.ConnectionPool() as client:28 request = httpcore.Request("GET", "http://127.0.0.1:8000/")29 response = await client.send(request, stream=True)StuffTom Christiebefore adoption30530d4
line 30why, one step back30 assert response.status_code == 200Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
line 31why, one step back31 assert not hasattr(response, "body")StuffTom Christiebefore adoption30530d4
lines 32–36why, one step back32 body = await response.read()33 assert body == b"Hello, world!"343536@pytest.mark.asyncioMerge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
lines 37–40why, one step back37async def test_stream_request(server):38 async def hello_world():39 yield b"Hello, "40 yield b"world!"StuffTom Christiebefore adoption30530d4
line 41why, one step back41Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498
lines 42–44why, one step back42 async with httpcore.ConnectionPool() as client:43 request = httpcore.Request("POST", "http://127.0.0.1:8000/", body=hello_world())44 response = await client.send(request)StuffTom Christiebefore adoption30530d4
line 45why, one step back45 assert response.status_code == 200