"""An app to lock, built here rather than imported. `auth/` has to survive being copied into a project that has never heard of this one, so its tests are not allowed to reach for `app/` or `pipeline/` either -- `tests/test_coupling.py` reads the imports of every file under this folder and says so. What they need is a FastAPI app with a page, an API route, a socket, and a couple of neighbours to prove the open list is matched the way it claims. That is this file, and it is nine routes. A module rather than a conftest fixture because two tests build the same database twice, to see what a restart does, and a fixture cannot be asked for twice in one test. """ from __future__ import annotations import os from fastapi import FastAPI, WebSocket from fastapi.responses import PlainTextResponse from auth import AuthConfig, AuthStore, connect def build(db: str | os.PathLike[str], *, host: str = "0.0.0.0", **settings: object) -> FastAPI: """One app, locked or not depending on what it is told the server binds.""" app = FastAPI() connect(app, AuthStore(db), AuthConfig(**settings), host=host, open=("/static/",), stylesheet="/static/app.css") @app.get("/", response_class=PlainTextResponse) def front() -> str: return "the front page" @app.get("/deep/page", response_class=PlainTextResponse) def deep() -> str: return "a page someone bookmarked" @app.get("/api/thing") def thing() -> dict[str, bool]: return {"ok": True} @app.get("/health") def health() -> dict[str, bool]: return {"ok": True} # The neighbours, so "matched whole, not as a prefix" is proved against # routes that exist rather than against two 404s. @app.get("/healthz") def healthz() -> dict[str, bool]: return {"ok": True} @app.get("/loginx", response_class=PlainTextResponse) def loginx() -> str: return "not the login page" @app.get("/static/app.css", response_class=PlainTextResponse) def stylesheet() -> str: return "body { }" @app.websocket("/ws/jobs") async def socket(ws: WebSocket) -> None: await ws.accept() await ws.send_json({"type": "jobs"}) await ws.close() return app