test_api.py
This file
Path
tests/test_api.py
73 lines · 1.8 KiB · Python
Last changed by
Add top-level API (#75)Tom Christiebefore adoptionfc627f3
History of this fileTake it
Add top-level API (#75)Tom Christiebefore adoptionfc627f3
lines 1–73why, one step back1import asyncio2import functools34import pytest56import httpcore789def 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):28 response = httpcore.get("http://127.0.0.1:8000/")29 assert response.status_code == 20030 assert response.reason_phrase == "OK"31 assert response.text == "Hello, world!"323334@threadpool35def test_post(server):36 response = httpcore.post("http://127.0.0.1:8000/", data=b"Hello, world!")37 assert response.status_code == 20038 assert response.reason_phrase == "OK"394041@threadpool42def test_options(server):43 response = httpcore.options("http://127.0.0.1:8000/")44 assert response.status_code == 20045 assert response.reason_phrase == "OK"464748@threadpool49def test_head(server):50 response = httpcore.head("http://127.0.0.1:8000/")51 assert response.status_code == 20052 assert response.reason_phrase == "OK"535455@threadpool56def test_put(server):57 response = httpcore.put("http://127.0.0.1:8000/", data=b"Hello, world!")58 assert response.status_code == 20059 assert response.reason_phrase == "OK"606162@threadpool63def test_patch(server):64 response = httpcore.patch("http://127.0.0.1:8000/", data=b"Hello, world!")65 assert response.status_code == 20066 assert response.reason_phrase == "OK"676869@threadpool70def test_delete(server):71 response = httpcore.delete("http://127.0.0.1:8000/")72 assert response.status_code == 20073 assert response.reason_phrase == "OK"