Basic ballot casting
This commit is contained in:
parent
0755a3d180
commit
1e389f4d65
@ -17,15 +17,18 @@
|
|||||||
from eos.core.objects import *
|
from eos.core.objects import *
|
||||||
from eos.base.workflow import *
|
from eos.base.workflow import *
|
||||||
|
|
||||||
class BallotQuestion(EmbeddedObject):
|
class Answer(EmbeddedObject):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class PlaintextBallotQuestion(BallotQuestion):
|
class EncryptedAnswer(EmbeddedObject):
|
||||||
choices = ListField(IntField())
|
pass
|
||||||
|
|
||||||
|
class NullEncryptedAnswer(EncryptedAnswer):
|
||||||
|
answer = EmbeddedObjectField()
|
||||||
|
|
||||||
class Ballot(EmbeddedObject):
|
class Ballot(EmbeddedObject):
|
||||||
_id = UUIDField()
|
_id = UUIDField()
|
||||||
questions = EmbeddedObjectListField()
|
encrypted_answers = EmbeddedObjectListField()
|
||||||
|
|
||||||
class Voter(EmbeddedObject):
|
class Voter(EmbeddedObject):
|
||||||
_id = UUIDField()
|
_id = UUIDField()
|
||||||
@ -37,6 +40,9 @@ class Question(EmbeddedObject):
|
|||||||
class ApprovalQuestion(Question):
|
class ApprovalQuestion(Question):
|
||||||
choices = ListField(StringField())
|
choices = ListField(StringField())
|
||||||
|
|
||||||
|
class ApprovalAnswer(Answer):
|
||||||
|
choices = ListField(IntField())
|
||||||
|
|
||||||
class Election(TopLevelObject):
|
class Election(TopLevelObject):
|
||||||
_id = UUIDField()
|
_id = UUIDField()
|
||||||
workflow = EmbeddedObjectField(Workflow) # Once saved, we don't care what kind of workflow it is
|
workflow = EmbeddedObjectField(Workflow) # Once saved, we don't care what kind of workflow it is
|
||||||
|
@ -37,17 +37,10 @@ class ElectionTestCase(TestCase):
|
|||||||
for i in range(3):
|
for i in range(3):
|
||||||
election.voters.append(Voter())
|
election.voters.append(Voter())
|
||||||
|
|
||||||
question = ApprovalQuestion()
|
question = ApprovalQuestion(prompt='President', choices=['John Smith', 'Joe Bloggs', 'John Q. Public'])
|
||||||
question.prompt = 'President'
|
|
||||||
question.choices.append('John Smith')
|
|
||||||
question.choices.append('Joe Bloggs')
|
|
||||||
question.choices.append('John Q. Public')
|
|
||||||
election.questions.append(question)
|
election.questions.append(question)
|
||||||
|
|
||||||
question = ApprovalQuestion()
|
question = ApprovalQuestion(prompt='Chairman', choices=['John Doe', 'Andrew Citizen'])
|
||||||
question.prompt = 'Chairman'
|
|
||||||
question.choices.append('John Doe')
|
|
||||||
question.choices.append('Andrew Citizen')
|
|
||||||
election.questions.append(question)
|
election.questions.append(question)
|
||||||
|
|
||||||
election.save()
|
election.save()
|
||||||
@ -61,3 +54,18 @@ class ElectionTestCase(TestCase):
|
|||||||
election.workflow.get_task('eos.base.workflow.TaskConfigureElection').exit()
|
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.TaskConfigureElection').status, WorkflowTask.Status.EXITED)
|
||||||
self.assertEqual(election.workflow.get_task('eos.base.workflow.TaskOpenVoting').status, WorkflowTask.Status.READY)
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user