Skip to content
Myr

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 file

Take it

StuffTom Christiebefore adoption30530d4

lines 1–6why, one step back
1import pytest
23import httpcore456@pytest.mark.asyncio

Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7

line 7why, one step back
7async def test_get(server):

Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498

lines 8–10why, one step back
8 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 back
11 assert response.status_code == 200
12 assert response.body == b"Hello, world!"131415@pytest.mark.asyncio

Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7

line 16why, one step back
16async def test_post(server):

Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498

lines 17–18why, one step back
17 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 back
19 "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 back
21 response = await client.send(request)

StuffTom Christiebefore adoption30530d4

lines 22–25why, one step back
22 assert response.status_code == 200
232425@pytest.mark.asyncio

Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7

line 26why, one step back
26async def test_stream_response(server):

Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498

lines 27–29why, one step back
27 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 back
30 assert response.status_code == 200

Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7

line 31why, one step back
31 assert not hasattr(response, "body")

StuffTom Christiebefore adoption30530d4

lines 32–36why, one step back
32 body = await response.read()
33 assert body == b"Hello, world!"343536@pytest.mark.asyncio

Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7

lines 37–40why, one step back
37async 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 back
41

Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498

lines 42–44why, one step back
42 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 back
45 assert response.status_code == 200