From 6fb841516c66b5055ea9287ded18c3a5ed3b3658 Mon Sep 17 00:00:00 2001 From: luxferre Date: Mon, 15 Jun 2026 09:57:21 +0100 Subject: [PATCH 1/2] tests: test configuration --- tests/__init__.py | 0 tests/conftest.py | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/pytest.toml | 2 ++ 3 files changed, 45 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/pytest.toml diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..ea4db34 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,43 @@ +import pytest + +from typing import AsyncGenerator +from httpx import AsyncClient, ASGITransport +from sqlalchemy.orm import sessionmaker + +from src.main import app # inited FastAPI app +from src.database import engine, Base, get_db + + +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) + + +@pytest.fixture() +def db_session(): + Base.metadata.drop_all(bind=engine) + Base.metadata.create_all(bind=engine) + db = SessionLocal() + try: + _seed(db) + yield db + finally: + db.rollback() + db.close() + + +@pytest.fixture +async def default_client(db_session) -> AsyncGenerator[AsyncClient, None]: + def get_db_override(): + return db_session + + app.dependency_overrides[get_db] = get_db_override + transport = ASGITransport(app=app) + async with AsyncClient( + transport=transport, base_url="http://localhost:8000/api/v1" + ) as ac: + yield ac + + app.dependency_overrides.clear() + + +def _seed(db): + pass diff --git a/tests/pytest.toml b/tests/pytest.toml new file mode 100644 index 0000000..ce95129 --- /dev/null +++ b/tests/pytest.toml @@ -0,0 +1,2 @@ +[tool.pytest] +markers = [] \ No newline at end of file From fc10307cc257757b67c4feb328dab75ff0de8061 Mon Sep 17 00:00:00 2001 From: luxferre Date: Mon, 15 Jun 2026 09:57:36 +0100 Subject: [PATCH 2/2] tests: test against health check endpoint --- tests/test_healthcheck.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/test_healthcheck.py diff --git a/tests/test_healthcheck.py b/tests/test_healthcheck.py new file mode 100644 index 0000000..47a3993 --- /dev/null +++ b/tests/test_healthcheck.py @@ -0,0 +1,10 @@ +import pytest +from httpx import AsyncClient + + +@pytest.mark.anyio +async def test_healthcheck(default_client: AsyncClient): + resp = await default_client.get("/healthcheck") + + assert resp.status_code == 200 + assert resp.json() == {"status": "ok"}