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"