mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(models.tu_voteinfo): default vote-count related columns to 0
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
d49886f44f
commit
efd61979f7
2 changed files with 14 additions and 18 deletions
|
@ -20,6 +20,11 @@ class TUVoteInfo(Base):
|
|||
foreign_keys=[__table__.c.SubmitterID])
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
# Default Quorum, Yes, No and Abstain columns to 0.
|
||||
for col in ("Quorum", "Yes", "No", "Abstain"):
|
||||
if col not in kwargs:
|
||||
kwargs.update({col: 0})
|
||||
|
||||
super().__init__(**kwargs)
|
||||
|
||||
if self.Agenda is None:
|
||||
|
@ -46,12 +51,6 @@ class TUVoteInfo(Base):
|
|||
orig="TU_VoteInfo.End",
|
||||
params=("NULL"))
|
||||
|
||||
if self.Quorum is None:
|
||||
raise IntegrityError(
|
||||
statement="Column Quorum cannot be null.",
|
||||
orig="TU_VoteInfo.Quorum",
|
||||
params=("NULL"))
|
||||
|
||||
if not self.Submitter:
|
||||
raise IntegrityError(
|
||||
statement="Foreign key SubmitterID cannot be null.",
|
||||
|
@ -67,9 +66,7 @@ class TUVoteInfo(Base):
|
|||
def __getattribute__(self, key: str):
|
||||
""" Customize getattr to floatify any fetched Quorum values. """
|
||||
attr = super().__getattribute__(key)
|
||||
if attr is None:
|
||||
return attr
|
||||
elif key == "Quorum":
|
||||
if key == "Quorum":
|
||||
return float(attr)
|
||||
return attr
|
||||
|
||||
|
|
|
@ -140,12 +140,11 @@ def test_tu_voteinfo_null_end_raises(user: User):
|
|||
rollback()
|
||||
|
||||
|
||||
def test_tu_voteinfo_null_quorum_raises(user: User):
|
||||
with pytest.raises(IntegrityError):
|
||||
with db.begin():
|
||||
create(TUVoteInfo,
|
||||
Agenda="Blah blah.",
|
||||
User=user.Username,
|
||||
Submitted=0, End=0,
|
||||
Submitter=user)
|
||||
rollback()
|
||||
def test_tu_voteinfo_null_quorum_default(user: User):
|
||||
with db.begin():
|
||||
vi = create(TUVoteInfo,
|
||||
Agenda="Blah blah.",
|
||||
User=user.Username,
|
||||
Submitted=0, End=0,
|
||||
Submitter=user)
|
||||
assert vi.Quorum == 0
|
||||
|
|
Loading…
Add table
Reference in a new issue