- AGENTS.md: ground rules (legal access, evidence, fairness), invariants that are easy to break, commands, and notes on the owner's dev machine; CLAUDE.md imports it - backend/tests/Dockerfile.debian: test image from Debian packages for networks where PyPI is unreachable, documented in testing.md - roadmap: list what v2 has not been verified against yet Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2.8 KiB
Testing
cd backend
pytest # everything below except the DB smoke test
pytest tests/test_golden.py -k parlament # one adapter's golden tests
UPDATE_GOLDEN=1 pytest tests/test_golden.py # regenerate expected outputs (review the diff!)
| suite | what it covers | needs |
|---|---|---|
tests/test_core.py |
framework invariants: request identity, secret redaction, registry consistency, record serialisation, OpenAPI→TS generator, shared helpers | nothing |
tests/test_parsers.py |
parsing helpers (vote texts, CSV layouts of the Rechnungshof, dates, normalisation) | nothing |
tests/test_extraction.py |
roll-call lists, immunity reports, event/legal/office-title detection | nothing |
tests/test_golden.py |
every captured fixture replayed through adapter.parse() and compared with <case>.expected.json |
nothing |
Parsers are pure, so none of these needs a database or network.
Without PyPI access
tests/Dockerfile.debian installs the dependencies from Debian packages instead (everything except
procrastinate and mcp, which the tests don't need):
docker build -t politrack-test -f backend/tests/Dockerfile.debian backend/tests
docker run --rm -v "$PWD/backend:/app" politrack-test python3 -m pytest -q -p no:cacheprovider
The same image can run adapters against the compose database: add --network politics-tracking_default
and -e POLITRACK_DATABASE_URL=postgresql://politrack:<password>@db:5432/politrack, then
python3 -m politrack.cli run <adapter> --max-requests 20.
Golden fixtures
tests/fixtures/<adapter name>/<case>.request.json {url, kind, meta, content_type, body_file}
tests/fixtures/<adapter name>/<case>.<ext> the captured body
tests/fixtures/<adapter name>/<case>.expected.json parse() output (records as JSON)
Capture with politrack fixture <adapter> <url> <case> --kind <kind> --meta '{"…": …}'. A fixture
without .expected.json creates it on the first run and is skipped until you have reviewed it.
When a source changes its format: capture a new case next to the old one (keep the old one if the
publisher still serves old documents in that format), fix the parser, bump parser_version.
Against a real database
The quickest end-to-end check uses the compose stack:
docker compose up -d db && docker compose run --rm migrate
docker compose run --rm api politrack run parlament.persons --max-requests 20 -p periods='["XXVIII"]'
docker compose run --rm api politrack enrich
docker compose run --rm api politrack status
curl -s localhost:8000/api/v1/stats
--max-requests keeps test runs polite. Each run is recorded in the run table (stats, errors) and
shown by politrack status and /api/v1/admin/runs.
Frontend
npm run typecheck (strict TypeScript against the generated API types) and npm run build.