Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

63 lines · 1.7 KiB · Python

Last changed by

Serve test server in thread (#292)Florimond Mancabefore adoption994403b

History of this file

Take it

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 1–2why, one step back
1import pytest
2

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 3why, one step back
3import httpx

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 4–6why, one step back
4
56def test_get(server):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 7why, one step back
7 response = httpx.get("http://127.0.0.1:8000/")

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

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

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

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

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 12–14why, one step back
12
1314def test_post(server):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 15why, one step back
15 response = httpx.post("http://127.0.0.1:8000/", data=b"Hello, world!")

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 16–19why, one step back
16 assert response.status_code == 200
17 assert response.reason_phrase == "OK"1819

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 20–25why, one step back
20def test_post_byte_iterator(server):
21 def data():22 yield b"Hello"23 yield b", "24 yield b"world!"25

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 26why, one step back
26 response = httpx.post("http://127.0.0.1:8000/", data=data())

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 27–30why, one step back
27 assert response.status_code == 200
28 assert response.reason_phrase == "OK"2930

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

line 31why, one step back
31def test_options(server):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 32why, one step back
32 response = httpx.options("http://127.0.0.1:8000/")

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 33–37why, one step back
33 assert response.status_code == 200
34 assert response.reason_phrase == "OK"353637def test_head(server):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 38why, one step back
38 response = httpx.head("http://127.0.0.1:8000/")

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 39–43why, one step back
39 assert response.status_code == 200
40 assert response.reason_phrase == "OK"414243def test_put(server):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 44why, one step back
44 response = httpx.put("http://127.0.0.1:8000/", data=b"Hello, world!")

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 45–49why, one step back
45 assert response.status_code == 200
46 assert response.reason_phrase == "OK"474849def test_patch(server):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 50why, one step back
50 response = httpx.patch("http://127.0.0.1:8000/", data=b"Hello, world!")

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 51–55why, one step back
51 assert response.status_code == 200
52 assert response.reason_phrase == "OK"535455def test_delete(server):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 56why, one step back
56 response = httpx.delete("http://127.0.0.1:8000/")

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

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

Minor tweaks in line with requests behavior (#110)Tom Christiebefore adoptionfe1f9ed

lines 59–61why, one step back
59
6061def test_get_invalid_url(server):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 62–63why, one step back
62 with pytest.raises(httpx.InvalidURL):
63 httpx.get("invalid://example.org")