F1: GUI-Login-Hash gegen $-Korruption gehaertet. .env-Werte einfach-gequotet
geschrieben + Sanity-Check nach Sourcing. Zusaetzlich systemd-Ebene:
podman escapt $->$$ in Environment=, systemd 252 kollabiert das nicht ->
sed-Post-Processing der Unit-Dateien. Live-.env: GUI-Passwort rotiert.
F2: Explizite Dependent-Deletes gegen FK-500 (delete_scenario/loan), 409 bei
bestaetigtem Import-Delete. Test-Engine erzwingt PRAGMA foreign_keys=ON.
F3: Enum/Range-Validierung (Literal + Field ge/le) fuer Recurring, Loan,
Modifier inkl. PATCH-Pfade.
F4: Confirm nur fuer draft-Statements (sonst 409) + Dedup-Re-Check gegen
bestaetigte Buchungen vor dem Promoten.
F5: v_balance_history/v_balance_total addieren pro Konto den opening_balance
des fruehesten bestaetigten Statements (approved deviation vom Plan-SQL).
F6: patch_scenario Namenskollision -> 409; create_transaction unbekanntes
Konto -> 404 (statt 500).
F7: Generierte systemd-Unit-Dateien chmod 600 (enthalten Env-Secrets).
F8: Globaler htmx:responseError-Handler in base.html.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy import create_engine, event
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy.pool import StaticPool
|
|
|
|
from app.db import Base, get_session
|
|
import app.models # noqa: F401 ensures all ORM tables are registered on Base.metadata
|
|
|
|
|
|
@pytest.fixture
|
|
def db():
|
|
engine = create_engine(
|
|
"sqlite://", poolclass=StaticPool,
|
|
connect_args={"check_same_thread": False},
|
|
)
|
|
|
|
# SQLite does not enforce foreign keys unless told to per-connection. Turn
|
|
# enforcement on so the tests catch FK violations (missing cascades) the
|
|
# same way Postgres would in production.
|
|
@event.listens_for(engine, "connect")
|
|
def _fk_pragma(dbapi_conn, _):
|
|
cur = dbapi_conn.cursor()
|
|
cur.execute("PRAGMA foreign_keys=ON")
|
|
cur.close()
|
|
|
|
Base.metadata.create_all(engine)
|
|
with Session(engine) as session:
|
|
yield session
|
|
|
|
|
|
@pytest.fixture
|
|
def client(db, monkeypatch):
|
|
monkeypatch.setenv("FB_API_KEY", "test-key")
|
|
from app.config import get_settings
|
|
get_settings.cache_clear()
|
|
from app.auth import hash_password
|
|
monkeypatch.setenv("FB_GUI_PASSWORD_HASH", hash_password("geheim"))
|
|
get_settings.cache_clear()
|
|
from app.main import app
|
|
|
|
def _override_get_session():
|
|
yield db
|
|
|
|
app.dependency_overrides[get_session] = _override_get_session
|
|
with TestClient(app) as c:
|
|
yield c
|
|
app.dependency_overrides.clear()
|
|
get_settings.cache_clear()
|