Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

85 lines · 2.0 KiB · Python

Last changed by

http3 (#86)Tom Christiebefore adoptionc9747aa

History of this file

Take it

1import asyncio2import functools34import pytest56import http3789def 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 = http3.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 = http3.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_post_byte_iterator(server):43    def data():44        yield b"Hello"45        yield b", "46        yield b"world!"4748    response = http3.post("http://127.0.0.1:8000/", data=data())49    assert response.status_code == 20050    assert response.reason_phrase == "OK"515253@threadpool54def test_options(server):55    response = http3.options("http://127.0.0.1:8000/")56    assert response.status_code == 20057    assert response.reason_phrase == "OK"585960@threadpool61def test_head(server):62    response = http3.head("http://127.0.0.1:8000/")63    assert response.status_code == 20064    assert response.reason_phrase == "OK"656667@threadpool68def test_put(server):69    response = http3.put("http://127.0.0.1:8000/", data=b"Hello, world!")70    assert response.status_code == 20071    assert response.reason_phrase == "OK"727374@threadpool75def test_patch(server):76    response = http3.patch("http://127.0.0.1:8000/", data=b"Hello, world!")77    assert response.status_code == 20078    assert response.reason_phrase == "OK"798081@threadpool82def test_delete(server):83    response = http3.delete("http://127.0.0.1:8000/")84    assert response.status_code == 20085    assert response.reason_phrase == "OK"