Files
knacky e77ca906d4 docs(backend): track sprint-0 follow-ups + flag integration migration gap
- `tasks/todo.md`: B0.5 description updated (re2 hard dep, no fallback);
  add a "Backend follow-ups (sprint 1+)" section with M1-M7 + N1-N6 from
  the code-review verdict.
- `CHANGELOG.md`: backend skeleton bullets refreshed (no re fallback,
  streaming blob store, audit + scope on CRUD, 56 unit tests); new
  "Code-review remediation" subsection lists B1 / MA1-MA6 / N4 / N6 / M8
  with one-line rationale each.
- `tests/integration/conftest.py`: leave `db.create_all()` in place but
  add an inline TODO (N6) pointing at the Alembic switchover that will
  exercise the F11 seed + audit-log role grants in CI.
2026-05-22 05:25:04 +02:00

52 lines
1.6 KiB
Python

"""Integration-level fixtures: testcontainers Postgres + Flask app + db session.
NF-state: SQLite is reserved for pure-logic unit tests; anything touching
constraints, RBAC role grants, or audit-log SQL behavior must run on a real
Postgres via testcontainers (spec H38).
"""
from __future__ import annotations
from collections.abc import Iterator
import pytest
try:
from testcontainers.postgres import PostgresContainer
except ImportError: # pragma: no cover
PostgresContainer = None # type: ignore[assignment]
@pytest.fixture(scope="session")
def postgres_dsn() -> Iterator[str]:
if PostgresContainer is None:
pytest.skip("testcontainers not installed")
with PostgresContainer("postgres:16-alpine") as pg:
url = pg.get_connection_url().replace("postgresql+psycopg2", "postgresql+psycopg")
yield url
@pytest.fixture
def app(postgres_dsn: str, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setenv("MIMIC_DATABASE_URL", postgres_dsn)
monkeypatch.setenv("MIMIC_ENV", "testing")
monkeypatch.setenv("MIMIC_SECRET_KEY", "test-not-real")
from mimic.app import create_app # noqa: PLC0415 (must follow env mutation)
from mimic.extensions import db # noqa: PLC0415
application = create_app()
with application.app_context():
# TODO (N6 follow-up, sprint 1): run Alembic migrations instead of
# db.create_all() so the integration tests exercise the real schema
# including the audit_log role grants and the F11 seed.
db.create_all()
yield application
db.session.remove()
db.drop_all()
@pytest.fixture
def client(app):
return app.test_client()