- backend/tests: jede Test-Funktion bekommt eine frische Datenbank; test_migrationen.py baut ältere Datenbank-Stände nach und prüft die verlustfreie Umstellung (auch zweiter Start ohne Änderung) - requirements-dev.txt mit pytest - Fix (von den Tests gefunden): Eine neue, leere Datenbank bekam keine erste Liste "Zuhause"; jetzt einmalig beim ersten Start Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
from app.main import app
|
|
|
|
|
|
def test_ohne_anmeldung_gesperrt():
|
|
assert TestClient(app).get("/api/haushalt").status_code == 401
|
|
|
|
|
|
def test_erstes_konto_wird_admin():
|
|
client = TestClient(app)
|
|
assert client.get("/api/auth/status").json()["setupRequired"] is True
|
|
res = client.post("/api/auth/setup", json={"username": "erste", "password": "passwort123"})
|
|
assert res.status_code == 200
|
|
assert res.json()["isAdmin"] is True
|
|
# Danach gibt es kein zweites "erstes Konto"
|
|
assert TestClient(app).post("/api/auth/setup", json={"username": "zweite", "password": "passwort123"}).status_code == 403
|
|
|
|
|
|
def test_falsches_passwort(login):
|
|
login("anna")
|
|
res = TestClient(app).post("/api/auth/login", json={"username": "anna", "password": "falsch"})
|
|
assert res.status_code == 401
|
|
|
|
|
|
def test_benutzerverwaltung_nur_admin(login):
|
|
assert login("anna").get("/api/users").status_code == 403
|
|
assert login("chef", admin=True).get("/api/users").status_code == 200
|