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:
@@ -11,9 +11,9 @@ templates = Jinja2Templates(directory=str(Path(__file__).parent.parent / "templa
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
def dashboard(request: Request):
|
||||
return templates.TemplateResponse(
|
||||
"dashboard.html",
|
||||
{
|
||||
"request": request,
|
||||
request=request,
|
||||
name="dashboard.html",
|
||||
context={
|
||||
"recent_printers": [],
|
||||
"recent_packages": [],
|
||||
},
|
||||
|
||||
+11
-9
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI
|
||||
@@ -6,7 +8,15 @@ from fastapi.staticfiles import StaticFiles
|
||||
from imptune.api import health, pages
|
||||
from imptune.config import DATA_DIR, DRIVERS_DIR
|
||||
|
||||
app = FastAPI(title="ImpTune")
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
os.makedirs(DATA_DIR, exist_ok=True)
|
||||
os.makedirs(DRIVERS_DIR, exist_ok=True)
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(title="ImpTune", lifespan=lifespan)
|
||||
|
||||
# Serve baked-in static assets (pico.min.css, htmx.min.js, alpine.min.js)
|
||||
_static_dir = Path(__file__).parent / "static"
|
||||
@@ -15,11 +25,3 @@ app.mount("/static", StaticFiles(directory=str(_static_dir)), name="static")
|
||||
# Register routers
|
||||
app.include_router(health.router)
|
||||
app.include_router(pages.router)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
def on_startup():
|
||||
import os
|
||||
|
||||
os.makedirs(DATA_DIR, exist_ok=True)
|
||||
os.makedirs(DRIVERS_DIR, exist_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user