Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

83 lines · 2.1 KiB · Python

Last changed by

Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8

History of this file

Take it

The walk stopped after 200 commits: lines older than 5dc646f point at it.

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 1–5why, one step back
1import pytest
23import httpx45

Drop sync (#544)Tom Christiebefore adoption206c537

lines 6–8why, one step back
6@pytest.mark.asyncio
7async def test_get(server):8 response = await httpx.get(server.url)

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 9–14why, one step back
9 assert response.status_code == 200
10 assert response.reason_phrase == "OK"11 assert response.text == "Hello, world!"12 assert response.http_version == "HTTP/1.1"1314

Drop sync (#544)Tom Christiebefore adoption206c537

lines 15–17why, one step back
15@pytest.mark.asyncio
16async def test_post(server):17 response = await httpx.post(server.url, data=b"Hello, world!")

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 18–21why, one step back
18 assert response.status_code == 200
19 assert response.reason_phrase == "OK"2021

Drop sync (#544)Tom Christiebefore adoption206c537

lines 22–24why, one step back
22@pytest.mark.asyncio
23async def test_post_byte_iterator(server):24 async def data():

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 25–28why, one step back
25 yield b"Hello"
26 yield b", "27 yield b"world!"28

Drop sync (#544)Tom Christiebefore adoption206c537

line 29why, one step back
29 response = await httpx.post(server.url, data=data())

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 30–33why, one step back
30 assert response.status_code == 200
31 assert response.reason_phrase == "OK"3233

Drop sync (#544)Tom Christiebefore adoption206c537

lines 34–36why, one step back
34@pytest.mark.asyncio
35async def test_options(server):36 response = await httpx.options(server.url)

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 37–40why, one step back
37 assert response.status_code == 200
38 assert response.reason_phrase == "OK"3940

Drop sync (#544)Tom Christiebefore adoption206c537

lines 41–43why, one step back
41@pytest.mark.asyncio
42async def test_head(server):43 response = await httpx.head(server.url)

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 44–47why, one step back
44 assert response.status_code == 200
45 assert response.reason_phrase == "OK"4647

Drop sync (#544)Tom Christiebefore adoption206c537

lines 48–50why, one step back
48@pytest.mark.asyncio
49async def test_put(server):50 response = await httpx.put(server.url, data=b"Hello, world!")

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 51–54why, one step back
51 assert response.status_code == 200
52 assert response.reason_phrase == "OK"5354

Drop sync (#544)Tom Christiebefore adoption206c537

lines 55–57why, one step back
55@pytest.mark.asyncio
56async def test_patch(server):57 response = await httpx.patch(server.url, data=b"Hello, world!")

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 58–61why, one step back
58 assert response.status_code == 200
59 assert response.reason_phrase == "OK"6061

Drop sync (#544)Tom Christiebefore adoption206c537

lines 62–64why, one step back
62@pytest.mark.asyncio
63async def test_delete(server):64 response = await httpx.delete(server.url)

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 65–68why, one step back
65 assert response.status_code == 200
66 assert response.reason_phrase == "OK"6768

Drop sync (#544)Tom Christiebefore adoption206c537

line 69why, one step back
69@pytest.mark.asyncio

Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b

lines 70–71why, one step back
70async def test_stream(server):
71 async with httpx.stream("GET", server.url) as response:

Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8

line 72why, one step back
72 await response.aread()

Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b

lines 73–80why, one step back
73
74 assert response.status_code == 20075 assert response.reason_phrase == "OK"76 assert response.text == "Hello, world!"77 assert response.http_version == "HTTP/1.1"787980@pytest.mark.asyncio

Drop sync (#544)Tom Christiebefore adoption206c537

line 81why, one step back
81async def test_get_invalid_url(server):

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

line 82why, one step back
82 with pytest.raises(httpx.InvalidURL):

Drop sync (#544)Tom Christiebefore adoption206c537

line 83why, one step back
83 await httpx.get("invalid://example.org")