Sprint 1: Stammdaten-Modelle/-Endpunkte, Admin-Benutzerverwaltung, Zuständigkeits-Vererbung (E2)
CI / backend-tests (push) Failing after 0s

- ORM-Modelle: Bereich, Kategorie, Standort, Objekttyp, Material (Prompt 06/07),
  minimales Objekt-Modell (voll ausgebaut erst Sprint 2), Zustaendigkeit/
  Kontrollverantwortung
- Admin-API 7a: GET/POST Stammdaten-Endpunkte, PATCH Material, Benutzerverwaltung
  (anlegen/Rollen ändern), Zuständigkeits-/Kontrollverantwortungs-CRUD
- Vererbungslogik E2 als eigener Service (app/services/zustaendigkeit.py):
  Standort-Zuordnung vererbt sich auf alle Objekte, Objekt-Zeile ist Vereinigung
  statt Ersatz - GET /zustaendigkeiten/benutzer/{id}/objekte exponiert das
- Tests: Stammdaten-CRUD + Rollenrechte, Benutzerverwaltung (inkl. 409 bei
  Login-Duplikat), E2-Vererbungslogik (Standort-only, Standort+Objekt-Vereinigung,
  End-to-End über den Endpunkt)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L85hmKbvX7Cqkq47KnQhFt
This commit is contained in:
2026-09-03 23:12:49 +02:00
co-authored by Claude Sonnet 5
parent 035b22fd1e
commit b9cf195a63
19 changed files with 937 additions and 2 deletions
+61
View File
@@ -8,6 +8,8 @@ from app.core.security import hash_password
from app.db.session import get_db
from app.main import app
from app.models.auth import Benutzer, BenutzerRolle, RolleTyp
from app.models.objekt import Objekt
from app.models.stammdaten import Bereich, Objekttyp, Standort
# Erwartet eine bereits per Alembic migrierte Test-Datenbank (CI: install -> migrate -> pytest,
# siehe testphasen.md Phase 0). Jeder Test läuft in einer Transaktion, die am Ende zurückgerollt
@@ -80,3 +82,62 @@ async def admin_user(db_session):
db_session.add(BenutzerRolle(benutzer_id=benutzer.id, rolle=RolleTyp.administration))
await db_session.flush()
return benutzer
async def login(client, username: str, password: str = "test-passwort-123") -> str:
response = await client.post(
"/api/v1/auth/login", data={"username": username, "password": password}
)
assert response.status_code == 200, response.text
return response.json()["access_token"]
def auth_header(token: str) -> dict:
return {"Authorization": f"Bearer {token}"}
@pytest_asyncio.fixture
async def hauptserver_id(db_session):
# Seed-Migration 0002 legt genau einen Datensatz mit typ='haupt' an (Sprintplan E6).
from sqlalchemy import select
from app.models.auth import KnotenTyp, Systemknoten
result = await db_session.execute(
select(Systemknoten.id).where(Systemknoten.typ == KnotenTyp.haupt)
)
return result.scalar_one()
@pytest_asyncio.fixture
async def standort_factory(db_session):
async def _make(name: str) -> Standort:
standort = Standort(name=name)
db_session.add(standort)
await db_session.flush()
return standort
return _make
@pytest_asyncio.fixture
async def objekt_factory(db_session, hauptserver_id):
async def _make(*, name: str, code: str, standort: Standort) -> Objekt:
bereich = Bereich(name=f"Bereich-{code}")
db_session.add(bereich)
await db_session.flush()
objekttyp = Objekttyp(bereich_id=bereich.id, name=f"Typ-{code}")
db_session.add(objekttyp)
await db_session.flush()
objekt = Objekt(
code=code,
name=name,
objekttyp_id=objekttyp.id,
standort_id=standort.id,
zustaendiger_server_id=hauptserver_id,
)
db_session.add(objekt)
await db_session.flush()
return objekt
return _make