forked from encode/httpx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
77 lines (53 loc) 路 2.1 KB
/
Copy pathtest_api.py
File metadata and controls
77 lines (53 loc) 路 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import typing
import pytest
from uvicorn.main import Server
import httpx
def test_get(server: Server) -> None:
response = httpx.get(server.url)
assert response.status_code == 200
assert response.reason_phrase == "OK"
assert response.text == "Hello, world!"
assert response.http_version == "HTTP/1.1"
def test_post(server: Server) -> None:
response = httpx.post(server.url, data=b"Hello, world!")
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_post_byte_iterator(server: Server) -> None:
def data() -> typing.Generator[bytes, None, None]:
yield b"Hello"
yield b", "
yield b"world!"
response = httpx.post(server.url, data=data())
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_options(server: Server) -> None:
response = httpx.options(server.url)
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_head(server: Server) -> None:
response = httpx.head(server.url)
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_put(server: Server) -> None:
response = httpx.put(server.url, data=b"Hello, world!")
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_patch(server: Server) -> None:
response = httpx.patch(server.url, data=b"Hello, world!")
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_delete(server: Server) -> None:
response = httpx.delete(server.url)
assert response.status_code == 200
assert response.reason_phrase == "OK"
def test_stream(server: Server) -> None:
with httpx.stream("GET", server.url) as response:
response.read()
assert response.status_code == 200
assert response.reason_phrase == "OK"
assert response.text == "Hello, world!"
assert response.http_version == "HTTP/1.1"
@pytest.mark.asyncio
async def test_get_invalid_url(server: Server) -> None:
with pytest.raises(httpx.InvalidURL):
await httpx.get("invalid://example.org") # type:ignore