Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

43 lines · 1.2 KiB · Python

Last changed by

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

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

lines 7–9why, one step back
7async def test_get(server):
8 async with httpcore.ConnectionPool() as http:9 response = await http.request("GET", "http://127.0.0.1:8000/")

StuffTom Christiebefore adoption30530d4

lines 10–14why, one step back
10 assert response.status_code == 200
11 assert response.body == b"Hello, world!"121314@pytest.mark.asyncio

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

lines 15–19why, one step back
15async def test_post(server):
16 async with httpcore.ConnectionPool() as http:17 response = await http.request(18 "POST", "http://127.0.0.1:8000/", body=b"Hello, world!"19 )

StuffTom Christiebefore adoption30530d4

lines 20–23why, one step back
20 assert response.status_code == 200
212223@pytest.mark.asyncio

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

lines 24–26why, one step back
24async def test_stream_response(server):
25 async with httpcore.ConnectionPool() as http:26 response = await http.request("GET", "http://127.0.0.1:8000/", stream=True)

StuffTom Christiebefore adoption30530d4

line 27why, one step back
27 assert response.status_code == 200

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

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

StuffTom Christiebefore adoption30530d4

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

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

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

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

lines 39–42why, one step back
39 async with httpcore.ConnectionPool() as http:
40 response = await http.request(41 "POST", "http://127.0.0.1:8000/", body=hello_world()42 )

StuffTom Christiebefore adoption30530d4

line 43why, one step back
43 assert response.status_code == 200