From 85ff0d650715ab7aa61ec3becf1e3dd02626c7f7 Mon Sep 17 00:00:00 2001 From: Showdown76py Date: Tue, 17 Nov 2026 14:46:46 +0100 Subject: [PATCH] Hand-added votes: pad per-answer counts to the option count; test covers it --- rotatyvote/db.py | 2 +- tests/test_e2e.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rotatyvote/db.py b/rotatyvote/db.py index 3659c19..d14ffa2 100644 --- a/rotatyvote/db.py +++ b/rotatyvote/db.py @@ -275,7 +275,7 @@ class DB: """votes added by hand (paper, show of hands), kept apart from the phone ballots""" n = len(json.loads(q["options"])) e = json.loads(q["extra"]) if q["extra"] else {} - counts = (e.get("counts") or [0] * n)[:n] + [0] * max(0, n - len(e.get("counts") or [])) + counts = (list(e.get("counts") or []) + [0] * n)[:n] blank = e.get("blank", 0) return {"counts": counts, "blank": blank, "ballots": e.get("ballots", sum(counts) + blank)} diff --git a/tests/test_e2e.py b/tests/test_e2e.py index ebd53d2..dbad40b 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -168,7 +168,8 @@ def test_full_flow_and_anonymity(server): assert admin(server, p, "POST", f"/questions/{qid}/close").status_code == 200 q = admin(server, p, "GET", "").json()["questions"][0] - assert q["results"] == {"counts": [1, 0], "blank": 1, "ballots": 2} + assert q["results"] == {"counts": [1, 0], "blank": 1, "ballots": 2, + "extra": {"counts": [0, 0], "blank": 0, "ballots": 0}} r = await a.post(f"/api/v/{p['id']}/vote", json={"question_id": qid, "choices": [0]}) assert r.status_code == 409 and r.json()["error"] == "not_open"