Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

91 lines · 2.1 KiB · Python

Last changed by

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

History of this file

Take it

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

lines 1–5why, one step back
1import asyncio
2import functools34import pytest5

http3 (#86)Tom Christiebefore adoptionc9747aa

line 6why, one step back
6import http3

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

lines 7–27why, one step back
7
89def threadpool(func):10 """11 Our sync tests should run in seperate thread to the uvicorn server.12 """1314 @functools.wraps(func)15 async def wrapped(*args, **kwargs):16 nonlocal func1718 loop = asyncio.get_event_loop()19 if kwargs:20 func = functools.partial(func, **kwargs)21 await loop.run_in_executor(None, func, *args)2223 return pytest.mark.asyncio(wrapped)242526@threadpool27def test_get(server):

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

lines 29–35why, one step back
29 assert response.status_code == 200
30 assert response.reason_phrase == "OK"31 assert response.text == "Hello, world!"323334@threadpool35def test_post(server):

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

lines 37–41why, one step back
37 assert response.status_code == 200
38 assert response.reason_phrase == "OK"394041@threadpool

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 42–47why, one step back
42def test_post_byte_iterator(server):
43 def data():44 yield b"Hello"45 yield b", "46 yield b"world!"47

http3 (#86)Tom Christiebefore adoptionc9747aa

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

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 49–53why, one step back
49 assert response.status_code == 200
50 assert response.reason_phrase == "OK"515253@threadpool

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

lines 56–61why, one step back
56 assert response.status_code == 200
57 assert response.reason_phrase == "OK"585960@threadpool61def test_head(server):

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

lines 63–68why, one step back
63 assert response.status_code == 200
64 assert response.reason_phrase == "OK"656667@threadpool68def test_put(server):

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

lines 70–75why, one step back
70 assert response.status_code == 200
71 assert response.reason_phrase == "OK"727374@threadpool75def test_patch(server):

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

lines 77–82why, one step back
77 assert response.status_code == 200
78 assert response.reason_phrase == "OK"798081@threadpool82def test_delete(server):

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

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

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

lines 86–91why, one step back
86
8788@threadpool89def test_get_invalid_url(server):90 with pytest.raises(http3.InvalidURL):91 http3.get("invalid://example.org")