- 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>
35 lines
1.6 KiB
Python
35 lines
1.6 KiB
Python
BERLIN = {"geonameId": 2950159, "name": "Berlin", "country": "DE", "lat": 52.52, "lon": 13.41, "population": 3426354, "capital": True}
|
|
LEIDEN = {"geonameId": 2751773, "name": "Leiden", "country": "NL", "lat": 52.16, "lon": 4.49}
|
|
|
|
|
|
def test_staedte_anderer_nur_lesend(login):
|
|
anna, ben = login("anna"), login("ben")
|
|
anna.post("/api/reisen/staedte", json=BERLIN)
|
|
data = ben.get("/api/reisen").json()
|
|
assert data["cities"] == []
|
|
assert [(p["name"], [c["name"] for c in p["cities"]]) for p in data["others"]] == [("Anna", ["Berlin"])]
|
|
city_id = data["others"][0]["cities"][0]["id"]
|
|
assert ben.delete(f"/api/reisen/staedte/{city_id}").status_code == 404
|
|
assert anna.get("/api/reisen").json()["others"] == []
|
|
|
|
|
|
def test_hauptstadt_kennzeichen(login):
|
|
anna = login("anna")
|
|
anna.post("/api/reisen/staedte", json=BERLIN)
|
|
data = anna.post("/api/reisen/staedte", json=LEIDEN).json()
|
|
# Mit Angabe aus der Suche gespeichert, ohne Angabe "unbekannt" (wird im Hintergrund nachgetragen)
|
|
assert {c["name"]: c["capital"] for c in data["cities"]} == {"Berlin": True, "Leiden": None}
|
|
|
|
|
|
def test_doppelte_stadt_wird_ignoriert(login):
|
|
anna = login("anna")
|
|
anna.post("/api/reisen/staedte", json=BERLIN)
|
|
assert len(anna.post("/api/reisen/staedte", json=BERLIN).json()["cities"]) == 1
|
|
|
|
|
|
def test_land_markieren(login):
|
|
anna = login("anna")
|
|
assert anna.put("/api/reisen/laender/IS").json()["countries"] == ["IS"]
|
|
assert anna.delete("/api/reisen/laender/IS").json()["countries"] == []
|
|
assert anna.put("/api/reisen/laender/xx").status_code == 400
|