Tests: pytest-Suite für Konten, Haushalt, Kanban, Reisen und Migrationen
- 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>
This commit is contained in:
1 parent
dc4ce18593
commit
79cbaab092
10 files changed
+478
No files matched your search
@@ -0,0 +1,28 @@
|
||||
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
|
||||
Reference in new issue
Block a user