107 lines
4.7 KiB
Python
107 lines
4.7 KiB
Python
"""Erfahrung und Level: berechnet aus dem Bestand, nicht gebucht."""
|
|
|
|
from app import punkte
|
|
|
|
|
|
def abend(client, film, movie_id=1):
|
|
return client.post("/api/watched", json={"movie_id": film(movie_id)}).json()["id"]
|
|
|
|
|
|
def stand(client, name):
|
|
return next(u for u in client.get("/api/users").json()["items"] if u["name"] == name)
|
|
|
|
|
|
def test_level_nach_dreieckszahlen():
|
|
assert punkte.level(0) == 1
|
|
assert punkte.level(1) == 2
|
|
assert punkte.level(2) == 2
|
|
assert punkte.level(3) == 3
|
|
assert punkte.level(20) == 6
|
|
assert punkte.level(21) == 7
|
|
assert punkte.level(1081) == 47
|
|
assert punkte.stand(21) == {"punkte": 21, "level": 7, "von": 21, "bis": 28}
|
|
|
|
|
|
def test_punkte_kommen_und_gehen_mit_dem_bestand(client, client2, film):
|
|
watched_id = abend(client, film)
|
|
assert stand(client, "Anna")["punkte"] == 0
|
|
|
|
client.post(f"/api/watched/{watched_id}/rating", json={"stars": 4})
|
|
assert stand(client, "Anna")["punkte"] == punkte.BEWERTEN
|
|
|
|
oben = client.post(f"/api/watched/{watched_id}/notes", json={"text": "gut"}).json()["id"]
|
|
client.post(f"/api/watched/{watched_id}/notes", json={"text": "nochmal"})
|
|
# Zwei Kommentare, einer zählt
|
|
assert stand(client, "Anna")["punkte"] == punkte.BEWERTEN + punkte.KOMMENTAR
|
|
|
|
client2.post(f"/api/watched/{watched_id}/notes", json={"text": "finde ich nicht", "parent_id": oben})
|
|
client2.post("/api/watched/hearts", json={"note_id": oben})
|
|
assert stand(client2, "Ben")["punkte"] == punkte.ANTWORT + punkte.HERZ
|
|
|
|
# Wertung weg, Punkte weg — nichts wird gebucht
|
|
client.post(f"/api/watched/{watched_id}/rating", json={"stars": 4})
|
|
assert stand(client, "Anna")["level"] == punkte.level(punkte.BEWERTEN + punkte.KOMMENTAR)
|
|
client.delete(f"/api/watched/{watched_id}")
|
|
assert stand(client, "Anna")["punkte"] == 0
|
|
assert stand(client2, "Ben")["punkte"] == 0
|
|
|
|
|
|
def test_anwesenheit_kommt_vom_rad(client, client2, zuschauer, hostmodus, film):
|
|
"""Wer vorschlägt oder sich einträgt, war dabei — sobald der Host den
|
|
gezogenen Film einträgt."""
|
|
from app import main
|
|
|
|
client.post("/api/suggestions", json={"movie_id": film(1)})
|
|
assert client2.post("/api/dabei").json()["dabei"] is True
|
|
liste = client2.get("/api/suggestions").json()
|
|
assert liste["dabei"] == ["Ben"] and liste["dabei_mine"] is True
|
|
|
|
hostmodus(zuschauer)
|
|
assert zuschauer.post("/api/spin").json()["started"] is True
|
|
main.letzter_dreh["start"] = 0.0 # Animation vorbei
|
|
watched_id = zuschauer.post("/api/watched", json={"movie_id": film(1)}).json()["id"]
|
|
|
|
f = next(x for x in client.get("/api/watched").json() if x["id"] == watched_id)
|
|
assert sorted(d["name"] for d in f["dabei"]) == ["Anna", "Ben"]
|
|
assert stand(client, "Anna")["punkte"] == punkte.SCHAUEN
|
|
assert stand(client, "Ben")["level"] == punkte.level(punkte.SCHAUEN)
|
|
|
|
# Der Host berichtigt: Ben kam doch nicht
|
|
anna = stand(client, "Anna")["id"]
|
|
zuschauer.post(f"/api/watched/{watched_id}/dabei", json={"user_ids": [anna]})
|
|
f = next(x for x in client.get("/api/watched").json() if x["id"] == watched_id)
|
|
assert [d["name"] for d in f["dabei"]] == ["Anna"]
|
|
|
|
# Reset leert auch die Eingetragenen
|
|
zuschauer.delete("/api/suggestions/alle")
|
|
assert client2.get("/api/suggestions").json()["dabei"] == []
|
|
assert client2.post("/api/dabei").json()["dabei"] is True
|
|
assert client2.post("/api/dabei").json()["dabei"] is False
|
|
|
|
|
|
def test_wertungen_und_herzen_sieht_nur_der_host(client, client2, zuschauer, hostmodus, film):
|
|
watched_id = abend(client, film)
|
|
client.post(f"/api/watched/{watched_id}/rating", json={"stars": 5})
|
|
note_id = client.post(f"/api/watched/{watched_id}/notes", json={"text": "x"}).json()["id"]
|
|
client2.post("/api/watched/hearts", json={"note_id": note_id})
|
|
|
|
def film_von(c):
|
|
return next(x for x in c.get("/api/watched").json() if x["id"] == watched_id)
|
|
|
|
# Ben sieht Schnitt und Herzzahl, aber keine Namen
|
|
f = film_von(client2)
|
|
assert f["ratings"] == [] and f["average"] == 5.0 and f["count"] == 1
|
|
assert f["notes"][0]["hearts"] == 1 and f["notes"][0]["hearted"] is True
|
|
assert f["notes"][0]["hearted_by"] == []
|
|
# Anna sieht ihre eigenen Sterne trotzdem
|
|
assert film_von(client)["mine"] == 5
|
|
# Der Host sieht alles
|
|
hostmodus(zuschauer)
|
|
f = film_von(zuschauer)
|
|
assert f["ratings"][0]["name"] == "Anna"
|
|
assert f["notes"][0]["hearted_by"] == ["Ben"]
|
|
# Herz zurück, Zähler runter; Zuschauer ohne Namen darf kein Herz geben
|
|
assert client2.post("/api/watched/hearts", json={"note_id": note_id}).json()["hearted"] is False
|
|
assert film_von(client)["notes"][0]["hearts"] == 0
|
|
assert client.post("/api/watched/hearts", json={"note_id": 999}).status_code == 404
|