add TUVoteInfo.total_votes()

Returns the sum of TUVoteInfo.Yes, TUVoteInfo.No and
TUVoteInfo.Abstain.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-06-19 01:18:40 -07:00
parent ac1779b705
commit 83c038a42a
2 changed files with 21 additions and 0 deletions

View file

@ -90,3 +90,6 @@ class TUVoteInfo(Base):
def is_running(self): def is_running(self):
return self.End > int(datetime.utcnow().timestamp()) return self.End > int(datetime.utcnow().timestamp())
def total_votes(self):
return self.Yes + self.No + self.Abstain

View file

@ -64,6 +64,24 @@ def test_tu_voteinfo_is_running():
assert tu_voteinfo.is_running() is False assert tu_voteinfo.is_running() is False
def test_tu_voteinfo_total_votes():
ts = int(datetime.utcnow().timestamp())
tu_voteinfo = create(TUVoteInfo,
Agenda="Blah blah.",
User=user.Username,
Submitted=ts, End=ts + 1000,
Quorum=0.5,
Submitter=user)
tu_voteinfo.Yes = 1
tu_voteinfo.No = 3
tu_voteinfo.Abstain = 5
commit()
# total_votes() should be the sum of Yes, No and Abstain: 1 + 3 + 5 = 9.
assert tu_voteinfo.total_votes() == 9
def test_tu_voteinfo_null_submitter_raises_exception(): def test_tu_voteinfo_null_submitter_raises_exception():
with pytest.raises(IntegrityError): with pytest.raises(IntegrityError):
create(TUVoteInfo, create(TUVoteInfo,