This is an automated email from the ASF dual-hosted git repository. gstein pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/steve.git
commit ea42278c905aac682710f4e0a30d820ba6781435 Author: Greg Stein <[email protected]> AuthorDate: Tue Jun 7 01:05:23 2022 -0500 Never return decrypted vote strings. Perform the final tally "internally". So: s/gather_issue_votes/tally_issue/ Adjust the coverage test script to add more votes, to exercise all branches of the two vote types. --- v3/steve/election.py | 19 ++++++++++++++++--- v3/test/check_coverage.py | 12 +++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/v3/steve/election.py b/v3/steve/election.py index e9e54ba..9ce9d2c 100644 --- a/v3/steve/election.py +++ b/v3/steve/election.py @@ -256,8 +256,16 @@ class Election: #print('TOKEN:', token) self.c_add_vote.perform((person_token, issue_token, salt, token)) - def gather_issue_votes(self, iid): - "Return a list of votestrings for a given ISSUE-ID." + def tally_issue(self, iid): + """Return the results for a given ISSUE-ID. + + This is a 2-tuple: a human-readable string, and vtype-specific + supporting data. + + Note: it is expected the caller has other details associated + with the issue, and knows the vote type and how to interpret + the supporting data. + """ # The Election should be closed. assert self.is_closed() @@ -276,9 +284,14 @@ class Election: dedup[row.person_token, row.issue_token] = votestring # Make sure the votes are not in database-order. + # Note: we are not returning the votes, so this may be + # superfluous. But it certainly should not hurt. votes = list(dedup.values()) crypto.shuffle(votes) # in-place - return votes + + # Perform the tally, and return the results. + m = vtypes.vtype_module(issue.type) + return m.tally(votes, self.json2kv(issue.kv)) def has_voted_upon(self, pid): "Return {ISSUE-ID: BOOL} stating what has been voted upon." diff --git a/v3/test/check_coverage.py b/v3/test/check_coverage.py index 4eeaeb7..10745b1 100755 --- a/v3/test/check_coverage.py +++ b/v3/test/check_coverage.py @@ -65,9 +65,10 @@ def touch_every_line(): e.add_person('alice', 'Alice', '[email protected]') e.add_person('bob', None, '[email protected]') - e.add_person('Carlos', 'Carlos', '[email protected]') + e.add_person('carlos', 'Carlos', '[email protected]') + e.add_person('david', None, '[email protected]') _ = e.list_persons() - e.delete_person('carlos') + e.delete_person('david') _ = e.get_person('alice') e.add_issue('a', 'issue A', None, 'yna', None) @@ -89,12 +90,17 @@ def touch_every_line(): e.open() _ = e.get_metadata() # while OPEN e.add_vote('alice', 'a', 'y') + e.add_vote('bob', 'a', 'n') + e.add_vote('carlos', 'a', 'a') # use each of Y/N/A + e.add_vote('alice', 'b', 'bc') + e.add_vote('bob', 'b', 'ad') _ = e.has_voted_upon('alice') _ = e.is_tampered() e.close() _ = e.get_metadata() # while CLOSED - _ = e.gather_issue_votes('a') + _ = e.tally_issue('a') + _ = e.tally_issue('b') def main():
