Basic ballot casting

This commit is contained in:
RunasSudo 2017-09-24 01:23:43 +10:00
parent 0755a3d180
commit 1e389f4d65
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 27 additions and 13 deletions

View File

@ -17,15 +17,18 @@
from eos.core.objects import *
from eos.base.workflow import *
class BallotQuestion(EmbeddedObject):
class Answer(EmbeddedObject):
pass
class PlaintextBallotQuestion(BallotQuestion):
choices = ListField(IntField())
class EncryptedAnswer(EmbeddedObject):
pass
class NullEncryptedAnswer(EncryptedAnswer):
answer = EmbeddedObjectField()
class Ballot(EmbeddedObject):
_id = UUIDField()
questions = EmbeddedObjectListField()
encrypted_answers = EmbeddedObjectListField()
class Voter(EmbeddedObject):
_id = UUIDField()
@ -37,6 +40,9 @@ class Question(EmbeddedObject):
class ApprovalQuestion(Question):
choices = ListField(StringField())
class ApprovalAnswer(Answer):
choices = ListField(IntField())
class Election(TopLevelObject):
_id = UUIDField()
workflow = EmbeddedObjectField(Workflow) # Once saved, we don't care what kind of workflow it is

View File

@ -37,17 +37,10 @@ class ElectionTestCase(TestCase):
for i in range(3):
election.voters.append(Voter())
question = ApprovalQuestion()
question.prompt = 'President'
question.choices.append('John Smith')
question.choices.append('Joe Bloggs')
question.choices.append('John Q. Public')
question = ApprovalQuestion(prompt='President', choices=['John Smith', 'Joe Bloggs', 'John Q. Public'])
election.questions.append(question)
question = ApprovalQuestion()
question.prompt = 'Chairman'
question.choices.append('John Doe')
question.choices.append('Andrew Citizen')
question = ApprovalQuestion(prompt='Chairman', choices=['John Doe', 'Andrew Citizen'])
election.questions.append(question)
election.save()
@ -61,3 +54,18 @@ class ElectionTestCase(TestCase):
election.workflow.get_task('eos.base.workflow.TaskConfigureElection').exit()
self.assertEqual(election.workflow.get_task('eos.base.workflow.TaskConfigureElection').status, WorkflowTask.Status.EXITED)
self.assertEqual(election.workflow.get_task('eos.base.workflow.TaskOpenVoting').status, WorkflowTask.Status.READY)
election.save()
# Cast ballots
VOTES = [[[0], [0]], [[0, 1], [1]], [[2], [0]]]
for i in range(3):
ballot = Ballot()
for j in range(2):
answer = ApprovalAnswer(choices=VOTES[i][j])
encrypted_answer = NullEncryptedAnswer(answer=answer)
ballot.encrypted_answers.append(encrypted_answer)
election.voters[i].ballots.append(ballot)
election.save()