test_api.py
This file
Path
tests/test_api.py
91 lines · 2.1 KiB · Python
Last changed by
Fix typos in docstringsSaugat Pachhaibefore adoption3451028
History of this fileTake it
Add top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 1–5why, one step back1import asyncio2import functools34import pytest5Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 6why, one step back6import httpxAdd top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 7–10why, one step back789def threadpool(func):10 """Fix typos in docstringsSaugat Pachhaibefore adoption3451028
line 11why, one step back11 Our sync tests should run in separate thread to the uvicorn server.Add top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 12–27why, one step back12 """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):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 28why, one step back28 response = httpx.get("http://127.0.0.1:8000/")Add top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 29–35why, one step back29 assert response.status_code == 20030 assert response.reason_phrase == "OK"31 assert response.text == "Hello, world!"323334@threadpool35def test_post(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 36why, one step back36 response = httpx.post("http://127.0.0.1:8000/", data=b"Hello, world!")Add top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 37–41why, one step back37 assert response.status_code == 20038 assert response.reason_phrase == "OK"394041@threadpoolSync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7
lines 42–47why, one step back42def test_post_byte_iterator(server):43 def data():44 yield b"Hello"45 yield b", "46 yield b"world!"47Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 48why, one step back48 response = httpx.post("http://127.0.0.1:8000/", data=data())Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7
lines 49–53why, one step back49 assert response.status_code == 20050 assert response.reason_phrase == "OK"515253@threadpoolAdd top-level API (#75)Tom Christiebefore adoptionfc627f3
line 54why, one step back54def test_options(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 55why, one step back55 response = httpx.options("http://127.0.0.1:8000/")Add top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 56–61why, one step back56 assert response.status_code == 20057 assert response.reason_phrase == "OK"585960@threadpool61def test_head(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 62why, one step back62 response = httpx.head("http://127.0.0.1:8000/")Add top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 63–68why, one step back63 assert response.status_code == 20064 assert response.reason_phrase == "OK"656667@threadpool68def test_put(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 69why, one step back69 response = httpx.put("http://127.0.0.1:8000/", data=b"Hello, world!")Add top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 70–75why, one step back70 assert response.status_code == 20071 assert response.reason_phrase == "OK"727374@threadpool75def test_patch(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 76why, one step back76 response = httpx.patch("http://127.0.0.1:8000/", data=b"Hello, world!")Add top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 77–82why, one step back77 assert response.status_code == 20078 assert response.reason_phrase == "OK"798081@threadpool82def test_delete(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 83why, one step back83 response = httpx.delete("http://127.0.0.1:8000/")Add top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 84–85why, one step back84 assert response.status_code == 20085 assert response.reason_phrase == "OK"Minor tweaks in line with requests behavior (#110)Tom Christiebefore adoptionfe1f9ed
lines 86–89why, one step back868788@threadpool89def test_get_invalid_url(server):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
lines 90–91why, one step back90 with pytest.raises(httpx.InvalidURL):91 httpx.get("invalid://example.org")