Hand-added votes: pad per-answer counts to the option count; test covers it
This commit is contained in:
+1
-1
@@ -275,7 +275,7 @@ class DB:
|
|||||||
"""votes added by hand (paper, show of hands), kept apart from the phone ballots"""
|
"""votes added by hand (paper, show of hands), kept apart from the phone ballots"""
|
||||||
n = len(json.loads(q["options"]))
|
n = len(json.loads(q["options"]))
|
||||||
e = json.loads(q["extra"]) if q["extra"] else {}
|
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)
|
blank = e.get("blank", 0)
|
||||||
return {"counts": counts, "blank": blank, "ballots": e.get("ballots", sum(counts) + blank)}
|
return {"counts": counts, "blank": blank, "ballots": e.get("ballots", sum(counts) + blank)}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -168,7 +168,8 @@ def test_full_flow_and_anonymity(server):
|
|||||||
|
|
||||||
assert admin(server, p, "POST", f"/questions/{qid}/close").status_code == 200
|
assert admin(server, p, "POST", f"/questions/{qid}/close").status_code == 200
|
||||||
q = admin(server, p, "GET", "").json()["questions"][0]
|
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]})
|
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"
|
assert r.status_code == 409 and r.json()["error"] == "not_open"
|
||||||
|
|||||||
Reference in New Issue
Block a user