feat(01-01): add test scaffold, health and static asset tests, fix deprecated APIs

- requirements-dev.txt with pytest and httpx
- tests/conftest.py: client and tmp_data_dir fixtures
- tests/test_health.py: GET /health returns 200 with {"status": "ok"}
- tests/test_static.py: no CDN URLs in templates, dashboard returns 200
- Fix imptune/api/pages.py: use request= kwarg in TemplateResponse (Starlette compat)
- Fix imptune/main.py: replace deprecated on_event with asynccontextmanager lifespan
This commit is contained in:
2026-04-10 11:26:48 +02:00
parent 139503944b
commit 34c7cb30f1
6 changed files with 84 additions and 12 deletions
+26
View File
@@ -0,0 +1,26 @@
import os
import pytest
from fastapi.testclient import TestClient
@pytest.fixture
def client(tmp_data_dir):
from imptune.main import app
return TestClient(app)
@pytest.fixture
def tmp_data_dir(tmp_path, monkeypatch):
"""Set DATA_DIR to a temp directory so tests don't write to /data."""
data_dir = tmp_path / "data"
data_dir.mkdir()
monkeypatch.setenv("DATA_DIR", str(data_dir))
# Patch config module so the app uses the temp dir
import imptune.config as cfg
cfg.DATA_DIR = str(data_dir)
cfg.DB_PATH = str(data_dir / "imptune.db")
cfg.DRIVERS_DIR = str(data_dir / "drivers")
return data_dir