update
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"""Wertungen: Sterne, Text, Schnitt."""
|
||||
|
||||
from app.watched import MAX_TEXT
|
||||
|
||||
|
||||
def gesehen(client, film, movie_id=1):
|
||||
@@ -9,42 +8,47 @@ def gesehen(client, film, movie_id=1):
|
||||
return client.post("/api/watched", json={"movie_id": movie_id}).json()["id"]
|
||||
|
||||
|
||||
def test_wertung_mit_text(client, film):
|
||||
wid = gesehen(client, film)
|
||||
|
||||
antwort = client.post(f"/api/watched/{wid}/rating", json={"stars": 4, "text": "Gruselig"})
|
||||
assert antwort.json() == {"watched_id": wid, "stars": 4, "text": "Gruselig"}
|
||||
|
||||
[eintrag] = client.get("/api/watched").json()
|
||||
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 eintrag["mine"] == 4
|
||||
assert eintrag["mine_text"] == "Gruselig"
|
||||
assert eintrag["ratings"][0]["mine"] is True
|
||||
assert "text" not in eintrag["ratings"][0]
|
||||
assert "mine_text" not in eintrag
|
||||
|
||||
|
||||
def test_text_none_behaelt_leer_loescht(client, film):
|
||||
wid = gesehen(client, film)
|
||||
client.post(f"/api/watched/{wid}/rating", json={"stars": 4, "text": "Gruselig"})
|
||||
|
||||
# Nur die Sterne nachjustiert: der Satz bleibt, es bleibt eine Stimme
|
||||
client.post(f"/api/watched/{wid}/rating", json={"stars": 3})
|
||||
[eintrag] = client.get("/api/watched").json()
|
||||
assert eintrag["mine"] == 3
|
||||
assert eintrag["mine_text"] == "Gruselig"
|
||||
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
|
||||
|
||||
client.post(f"/api/watched/{wid}/rating", json={"stars": 3, "text": ""})
|
||||
[eintrag] = client.get("/api/watched").json()
|
||||
assert eintrag["mine_text"] is None
|
||||
|
||||
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
|
||||
|
||||
def test_text_wird_gekuerzt(client, film):
|
||||
wid = gesehen(client, film)
|
||||
client.post(f"/api/watched/{wid}/rating", json={"stars": 5, "text": "x" * (MAX_TEXT + 100)})
|
||||
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()
|
||||
|
||||
[eintrag] = client.get("/api/watched").json()
|
||||
assert len(eintrag["mine_text"]) == MAX_TEXT
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user