68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
"""Wertungen: Sterne, Text, Schnitt."""
|
|
|
|
|
|
|
|
def gesehen(client, film, movie_id=1):
|
|
"""Film anlegen und als gesehen eintragen. Gibt die watched-id zurück."""
|
|
film(movie_id)
|
|
return client.post("/api/watched", json={"movie_id": movie_id}).json()["id"]
|
|
|
|
|
|
def test_wertung_ist_nur_sterne(client, film):
|
|
wid = client.post("/api/watched", json={"movie_id": film(1)}).json()["id"]
|
|
antwort = client.post(f"/api/watched/{wid}/rating", json={"stars": 4})
|
|
assert antwort.json() == {"watched_id": wid, "stars": 4}
|
|
eintrag = client.get("/api/watched").json()[0]
|
|
assert eintrag["mine"] == 4
|
|
assert eintrag["average"] == 4.0
|
|
assert eintrag["count"] == 1
|
|
assert "text" not in eintrag["ratings"][0]
|
|
assert "mine_text" not in eintrag
|
|
|
|
|
|
def test_neue_sterne_ersetzen_die_alten(client, film):
|
|
wid = client.post("/api/watched", json={"movie_id": film(1)}).json()["id"]
|
|
client.post(f"/api/watched/{wid}/rating", json={"stars": 4})
|
|
client.post(f"/api/watched/{wid}/rating", json={"stars": 2})
|
|
eintrag = client.get("/api/watched").json()[0]
|
|
assert eintrag["mine"] == 2
|
|
assert eintrag["count"] == 1
|
|
|
|
|
|
def test_alter_wertungstext_zieht_in_die_diskussion(client, film):
|
|
"""Vor dem Umbau hing ein Text an den Sternen. Beim Start wandert er
|
|
als Kommentar in die Diskussion, mit Verfasser und Datum."""
|
|
from app import db, watched
|
|
|
|
wid = client.post("/api/watched", json={"movie_id": film(1)}).json()["id"]
|
|
client.post(f"/api/watched/{wid}/rating", json={"stars": 5})
|
|
with db.connect() as conn:
|
|
conn.execute("UPDATE ratings SET text = 'Alte Rezension'")
|
|
watched.init()
|
|
|
|
f = client.get("/api/watched").json()[0]
|
|
assert [n["text"] for n in f["notes"]] == ["Alte Rezension"]
|
|
assert f["notes"][0]["name"] == "Anna"
|
|
assert f["notes"][0]["mine"] is True
|
|
with db.connect() as conn:
|
|
assert conn.execute("SELECT COUNT(*) FROM ratings WHERE text IS NOT NULL").fetchone()[0] == 0
|
|
# Ein zweiter Start zieht nichts doppelt um
|
|
watched.init()
|
|
assert len(client.get("/api/watched").json()[0]["notes"]) == 1
|
|
|
|
|
|
def test_fremde_wertung_ist_nicht_meine(client, client2, film):
|
|
wid = gesehen(client, film)
|
|
client.post(f"/api/watched/{wid}/rating", json={"stars": 4})
|
|
|
|
[eintrag] = client2.get("/api/watched").json()
|
|
assert eintrag["mine"] is None
|
|
assert eintrag["count"] == 1
|
|
assert eintrag["ratings"][0]["mine"] is False
|
|
|
|
client2.post(f"/api/watched/{wid}/rating", json={"stars": 2})
|
|
[eintrag] = client2.get("/api/watched").json()
|
|
assert eintrag["average"] == 3.0
|
|
assert eintrag["count"] == 2
|
|
assert eintrag["mine"] == 2
|