forked from retoor/devplacepy
42 lines
2.1 KiB
Python
42 lines
2.1 KiB
Python
# retoor <retoor@molodetz.nl>
|
|||
|
|
|
||
|
|
from devplacepy.database import get_table
|
||
|
|
from tests.api.sync.conftest import poll_record, poll_vote_record, seed_world, sync_ok
|
||
|
|
|
||
|
|
|
||
|
|
def setup(client, admin, origin):
|
||
|
|
seed_world(client, admin, origin)
|
||
|
|
return sync_ok(client, admin, "polls", origin, [poll_record()])["results"][0]["local_uid"]
|
||
|
|
|
||
|
|
|
||
|
|
def test_a_ballot_changes_option_without_duplicating(client, admin, origin):
|
||
|
|
poll = setup(client, admin, origin)
|
||
|
|
first = sync_ok(client, admin, "poll_votes", origin, [poll_vote_record("pv1", option="a")])["results"][0]
|
||
|
|
assert first["status"] == "created"
|
||
|
|
sync_ok(client, admin, "poll_votes", origin, [poll_vote_record("pv1", option="b", updated_at="2025-02-01T00:00:00Z")])
|
||
|
|
rows = list(get_table("poll_votes").find(poll_uid=poll))
|
||
|
|
assert len(rows) == 1
|
||
|
|
option = get_table("poll_options").find_one(uid=rows[0]["option_uid"])
|
||
|
|
assert option["label"] == "Spaces"
|
||
|
|
|
||
|
|
|
||
|
|
def test_unknown_poll_waits_but_an_unknown_option_is_final(client, admin, origin):
|
||
|
|
setup(client, admin, origin)
|
||
|
|
body = sync_ok(client, admin, "poll_votes", origin, [poll_vote_record("pv1", poll="ghost"), poll_vote_record("pv2", option="zzz")])
|
||
|
|
assert (body["results"][0]["status"], body["results"][0]["reason"]) == ("deferred", "unknown_poll")
|
||
|
|
assert (body["results"][1]["status"], body["results"][1]["reason"]) == ("rejected", "unknown_option")
|
||
|
|
|
||
|
|
|
||
|
|
def test_one_ballot_per_voter_even_with_a_second_origin_id(client, admin, origin):
|
||
|
|
poll = setup(client, admin, origin)
|
||
|
|
sync_ok(client, admin, "poll_votes", origin, [poll_vote_record("pv1", option="a")])
|
||
|
|
sync_ok(client, admin, "poll_votes", origin, [poll_vote_record("pv7", option="b")])
|
||
|
|
assert get_table("poll_votes").count(poll_uid=poll) == 1
|
||
|
|
|
||
|
|
|
||
|
|
def test_clearing_a_ballot(client, admin, origin):
|
||
|
|
poll = setup(client, admin, origin)
|
||
|
|
sync_ok(client, admin, "poll_votes", origin, [poll_vote_record("pv1")])
|
||
|
|
sync_ok(client, admin, "poll_votes", origin, [poll_vote_record("pv1", updated_at="2025-02-01T00:00:00Z", deleted=True)])
|
||
|
|
assert get_table("poll_votes").find_one(poll_uid=poll)["deleted_by"] == "sync"
|