update
This commit is contained in:
74
backend/tests/test_features.py
Normal file
74
backend/tests/test_features.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""Wünsche: Stimmen, Abhaken, Anmerkungen."""
|
||||
|
||||
from app import db
|
||||
|
||||
|
||||
def wunsch(client, text="Dunkles Design"):
|
||||
liste = client.post("/api/features", json={"text": text}).json()
|
||||
return next(w for w in liste if w["text"] == text)
|
||||
|
||||
|
||||
def test_leerer_wunsch_wird_abgelehnt(client):
|
||||
assert client.post("/api/features", json={"text": " "}).status_code == 400
|
||||
|
||||
|
||||
def test_stimme_toggelt(client):
|
||||
w = wunsch(client)
|
||||
assert w["mine"] is True
|
||||
assert w["votes"] == 0
|
||||
assert w["voted"] is False
|
||||
|
||||
assert client.post(f"/api/features/{w['id']}/vote").json() == {"voted": True}
|
||||
[w] = client.get("/api/features").json()
|
||||
assert w["votes"] == 1
|
||||
assert w["voted"] is True
|
||||
|
||||
assert client.post(f"/api/features/{w['id']}/vote").json() == {"voted": False}
|
||||
[w] = client.get("/api/features").json()
|
||||
assert w["votes"] == 0
|
||||
assert w["voted"] is False
|
||||
|
||||
|
||||
def test_erledigt_rutscht_ans_ende(client):
|
||||
erster = wunsch(client, "A")
|
||||
wunsch(client, "B")
|
||||
# Mit Stimme steht A vorn
|
||||
client.post(f"/api/features/{erster['id']}/vote")
|
||||
assert [w["text"] for w in client.get("/api/features").json()] == ["A", "B"]
|
||||
|
||||
antwort = client.patch(f"/api/features/{erster['id']}/done", json={"done": True})
|
||||
assert antwort.json() == {"ok": True}
|
||||
liste = client.get("/api/features").json()
|
||||
assert [w["text"] for w in liste] == ["B", "A"]
|
||||
assert liste[1]["done_at"] is not None
|
||||
|
||||
client.patch(f"/api/features/{erster['id']}/done", json={"done": False})
|
||||
assert [w["text"] for w in client.get("/api/features").json()] == ["A", "B"]
|
||||
|
||||
|
||||
def test_anmerkungen_anlegen_und_loeschen(client, client2):
|
||||
w = wunsch(client)
|
||||
antwort = client.post(f"/api/features/{w['id']}/notes", json={"text": "Mit Kontrast"})
|
||||
assert antwort.json() == {"ok": True}
|
||||
|
||||
[w] = client.get("/api/features").json()
|
||||
[notiz] = w["notes"]
|
||||
assert notiz["text"] == "Mit Kontrast"
|
||||
assert notiz["mine"] is True
|
||||
[fremd] = client2.get("/api/features").json()
|
||||
assert fremd["notes"][0]["mine"] is False
|
||||
|
||||
assert client.delete(f"/api/feature-notes/{notiz['id']}").json() == {"removed": 1}
|
||||
assert client.get("/api/features").json()[0]["notes"] == []
|
||||
|
||||
|
||||
def test_loeschen_raeumt_stimmen_und_anmerkungen_mit(client):
|
||||
w = wunsch(client)
|
||||
client.post(f"/api/features/{w['id']}/vote")
|
||||
client.post(f"/api/features/{w['id']}/notes", json={"text": "Anmerkung"})
|
||||
|
||||
assert client.delete(f"/api/features/{w['id']}").json() == {"removed": 1}
|
||||
assert client.get("/api/features").json() == []
|
||||
with db.connect() as conn:
|
||||
for tabelle in ("feature_votes", "feature_notes"):
|
||||
assert conn.execute(f"SELECT COUNT(*) FROM {tabelle}").fetchone()[0] == 0
|
||||
Reference in New Issue
Block a user