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])
|
foreign_keys=[__table__.c.SubmitterID])
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
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)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
if self.Agenda is None:
|
if self.Agenda is None:
|
||||||
|
@ -46,12 +51,6 @@ class TUVoteInfo(Base):
|
||||||
orig="TU_VoteInfo.End",
|
orig="TU_VoteInfo.End",
|
||||||
params=("NULL"))
|
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:
|
if not self.Submitter:
|
||||||
raise IntegrityError(
|
raise IntegrityError(
|
||||||
statement="Foreign key SubmitterID cannot be null.",
|
statement="Foreign key SubmitterID cannot be null.",
|
||||||
|
@ -67,9 +66,7 @@ class TUVoteInfo(Base):
|
||||||
def __getattribute__(self, key: str):
|
def __getattribute__(self, key: str):
|
||||||
""" Customize getattr to floatify any fetched Quorum values. """
|
""" Customize getattr to floatify any fetched Quorum values. """
|
||||||
attr = super().__getattribute__(key)
|
attr = super().__getattribute__(key)
|
||||||
if attr is None:
|
if key == "Quorum":
|
||||||
return attr
|
|
||||||
elif key == "Quorum":
|
|
||||||
return float(attr)
|
return float(attr)
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
|
|
|
@ -140,12 +140,11 @@ def test_tu_voteinfo_null_end_raises(user: User):
|
||||||
rollback()
|
rollback()
|
||||||
|
|
||||||
|
|
||||||
def test_tu_voteinfo_null_quorum_raises(user: User):
|
def test_tu_voteinfo_null_quorum_default(user: User):
|
||||||
with pytest.raises(IntegrityError):
|
with db.begin():
|
||||||
with db.begin():
|
vi = create(TUVoteInfo,
|
||||||
create(TUVoteInfo,
|
Agenda="Blah blah.",
|
||||||
Agenda="Blah blah.",
|
User=user.Username,
|
||||||
User=user.Username,
|
Submitted=0, End=0,
|
||||||
Submitted=0, End=0,
|
Submitter=user)
|
||||||
Submitter=user)
|
assert vi.Quorum == 0
|
||||||
rollback()
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue