Compare commits

..

2 commits

Author SHA1 Message Date
fc10307cc2 tests: test against health check endpoint
Some checks failed
ci / lint_and_test (push) Failing after 8s
2026-06-15 09:57:36 +01:00
6fb841516c tests: test configuration 2026-06-15 09:57:21 +01:00
4 changed files with 55 additions and 0 deletions

0
tests/__init__.py Normal file
View file

43
tests/conftest.py Normal file
View file

@ -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

2
tests/pytest.toml Normal file
View file

@ -0,0 +1,2 @@
[tool.pytest]
markers = []

10
tests/test_healthcheck.py Normal file
View file

@ -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"}