Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

83 lines · 2.1 KiB · Python

Last changed by

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

History of this file

Take it

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

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

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)

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

lines 9–11why, one step back
9 assert response.status_code == 200
10 assert response.reason_phrase == "OK"11 assert response.text == "Hello, world!"

Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6

line 12why, one step back
12 assert response.http_version == "HTTP/1.1"

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

lines 13–14why, one step back
13
14

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!")

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

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():

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

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())

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

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)

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

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)

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

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!")

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

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!")

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

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)

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

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–80why, one step back
70async def test_stream(server):
71 async with httpx.stream("GET", server.url) as response:72 await response.read()7374 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):

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

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")