mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
add TUVoteInfo.is_running() method
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
07c4be0afb
commit
4927a61378
2 changed files with 21 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey, Integer
|
from sqlalchemy import Column, ForeignKey, Integer
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy.orm import backref, relationship
|
from sqlalchemy.orm import backref, relationship
|
||||||
|
@ -85,3 +87,6 @@ class TUVoteInfo(Base):
|
||||||
""" Customize getattr to floatify any fetched Quorum values. """
|
""" Customize getattr to floatify any fetched Quorum values. """
|
||||||
attr = super().__getattribute__(key)
|
attr = super().__getattribute__(key)
|
||||||
return float(attr) if key == "Quorum" else attr
|
return float(attr) if key == "Quorum" else attr
|
||||||
|
|
||||||
|
def is_running(self):
|
||||||
|
return self.End > int(datetime.utcnow().timestamp())
|
||||||
|
|
|
@ -4,7 +4,7 @@ import pytest
|
||||||
|
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
from aurweb.db import create, query, rollback
|
from aurweb.db import commit, create, query, rollback
|
||||||
from aurweb.models.account_type import AccountType
|
from aurweb.models.account_type import AccountType
|
||||||
from aurweb.models.tu_voteinfo import TUVoteInfo
|
from aurweb.models.tu_voteinfo import TUVoteInfo
|
||||||
from aurweb.models.user import User
|
from aurweb.models.user import User
|
||||||
|
@ -49,6 +49,21 @@ def test_tu_voteinfo_creation():
|
||||||
assert tu_voteinfo in user.tu_voteinfo_set
|
assert tu_voteinfo in user.tu_voteinfo_set
|
||||||
|
|
||||||
|
|
||||||
|
def test_tu_voteinfo_is_running():
|
||||||
|
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)
|
||||||
|
assert tu_voteinfo.is_running() is True
|
||||||
|
|
||||||
|
tu_voteinfo.End = ts - 5
|
||||||
|
commit()
|
||||||
|
assert tu_voteinfo.is_running() is False
|
||||||
|
|
||||||
|
|
||||||
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,
|
||||||
|
|
Loading…
Add table
Reference in a new issue