chore(backend): DB-backed pytest harness (temp SQLite, real app, per-test rollback)

Platform v2 step 0.5. conftest.py now points DATABASE_URL/LOG_DIR/TLS_DIR at
a temp folder before anything imports config, builds the schema once per
session, and gives each test a connection-level transaction that is rolled
back (app commits become SAVEPOINT releases). Fixtures: db, client (TestClient
with get_db overridden, license open, no lifespan), make_user, login. Tests
using them are auto-marked `db`, so -m "not db" keeps the quick set.
test_harness.py proves login -> /api/auth/me and the rollback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 16:40:53 +02:00
co-authored by Claude Opus 5.5
parent 9fa728c039
commit 980127379b
3 changed files with 213 additions and 3 deletions
+5 -1
View File
@@ -8,12 +8,16 @@ Run them **before a release** and after changing anything they cover.
```powershell
cd client-services/local_backend
pip install -r requirements-dev.txt # once
python -m pytest tests -q # license rules, LAN-IP detection + priority, TLS identity
python -m pytest tests -q # everything: unit tests + DB tests (~4 s)
python -m pytest tests -q -m "not db" # quick set only: license rules, LAN IP, TLS identity, logging
python -m pytest tests -q -m db # DB tests only: real app + temp SQLite database
cd ../waiter_pwa
npm test # server rediscovery scan
```
**DB tests** (`local_backend/tests/conftest.py`) run the real FastAPI app against a throwaway SQLite database in a temp folder (never your dev or venue DB). Fixtures: `db` (session, rolled back after each test even if the code commits), `client` (TestClient with `get_db` overridden, license check open, no lifespan), `make_user(role=..., perms=...)` (password `password`, PIN `1234`), `login(user)` (auth headers). A test that uses any of them is marked `db` automatically.
## Full: end-to-end suites
```powershell