diff --git a/backend/setup.cfg b/backend/setup.cfg index 6f11b83..7a4f884 100644 --- a/backend/setup.cfg +++ b/backend/setup.cfg @@ -66,6 +66,7 @@ commands = deps = pytest pytest-asyncio + trio commands = pytest tests diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index 6c7cd08..f715e13 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -8,6 +8,7 @@ from urllib.parse import urlparse from fastapi import FastAPI, status from fastapi.testclient import TestClient +from httpx import AsyncClient from pytest import fixture from kibicara import email @@ -24,6 +25,15 @@ def client(): return TestClient(app) +@fixture(scope="module") +def asyncclient(): + Mapping.drop_all() + Mapping.create_all() + app = FastAPI() + app.include_router(router, prefix="/api") + return AsyncClient(app=app, base_url="http://test") + + @fixture(scope="module") def monkeymodule(): from _pytest.monkeypatch import MonkeyPatch diff --git a/backend/tests/tests_core/test_api_admin.py b/backend/tests/tests_core/test_api_admin.py index 167a664..aec3989 100644 --- a/backend/tests/tests_core/test_api_admin.py +++ b/backend/tests/tests_core/test_api_admin.py @@ -3,10 +3,12 @@ # SPDX-License-Identifier: 0BSD from fastapi import status +import pytest -def test_hoods_unauthorized(client): - response = client.get("/api/admin/hoods/") +@pytest.mark.anyio +async def test_hoods_unauthorized(asyncclient): + response = await asyncclient.get("/api/admin/hoods/") assert response.status_code == status.HTTP_401_UNAUTHORIZED diff --git a/setup.sh b/setup.sh index 13b674f..553e0f8 100755 --- a/setup.sh +++ b/setup.sh @@ -6,4 +6,4 @@ ln -sf ../../git-hooks/commit-msg .git/hooks/commit-msg # create virtualenv virtualenv -p $(which python3.10) backend/.venv -backend/.venv/bin/pip install tox black pytest pytest-aiohttp +backend/.venv/bin/pip install tox black pytest pytest-aiohttp trio