mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
In preparation for allowing TUs to change their votes on proposals, we need a way to track what users vote for. Without this, the vote decisions are stored within the related TU_VoteInfo record, decoupled from the user who made the vote. That being the case meant we cannot actually change a vote, because we can't figure out what TU_VoteInfo decision columns to decrement when the vote has changed. You may be wondering why we aren't removing the decision columns out of TU_VoteInfo with the advent of this new column. The reason being: previous votes are all calculated off of the TU_VoteInfo columns, so without a manual DB rework, relocating them to the user-related vote records would break outcomes of old proposals. So, the plan is: we'll solely use this column for votes from this point on to track what decision a user made internally, which will open up TUs changing their decision. In addition, this migration resets all running proposals: - all votes are deleted - time is reset to Start when migration is run This was necessary to put running proposals into a state that can take advantage of the new revote system. Signed-off-by: Kevin Morris <kevr@0cost.org>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
import pytest
|
|
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
|
from aurweb import db, time
|
|
from aurweb.models.account_type import TRUSTED_USER_ID
|
|
from aurweb.models.tu_vote import YES_ID, TUVote
|
|
from aurweb.models.tu_voteinfo import TUVoteInfo
|
|
from aurweb.models.user import User
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def setup(db_test):
|
|
return
|
|
|
|
|
|
@pytest.fixture
|
|
def user() -> User:
|
|
with db.begin():
|
|
user = db.create(User, Username="test", Email="test@example.org",
|
|
RealName="Test User", Passwd="testPassword",
|
|
AccountTypeID=TRUSTED_USER_ID)
|
|
yield user
|
|
|
|
|
|
@pytest.fixture
|
|
def tu_voteinfo(user: User) -> TUVoteInfo:
|
|
ts = time.utcnow()
|
|
with db.begin():
|
|
tu_voteinfo = db.create(TUVoteInfo, Agenda="Blah blah.",
|
|
User=user.Username,
|
|
Submitted=ts, End=ts + 5,
|
|
Quorum=0.5, Submitter=user)
|
|
yield tu_voteinfo
|
|
|
|
|
|
def test_tu_vote_creation(user: User, tu_voteinfo: TUVoteInfo):
|
|
with db.begin():
|
|
tu_vote = db.create(TUVote, User=user, VoteInfo=tu_voteinfo,
|
|
Decision=YES_ID)
|
|
|
|
assert tu_vote.VoteInfo == tu_voteinfo
|
|
assert tu_vote.User == user
|
|
assert tu_vote.Decision == YES_ID
|
|
assert tu_vote in user.tu_votes
|
|
assert tu_vote in tu_voteinfo.tu_votes
|
|
|
|
|
|
def test_tu_vote_null_user_raises_exception(tu_voteinfo: TUVoteInfo):
|
|
with pytest.raises(IntegrityError):
|
|
TUVote(VoteInfo=tu_voteinfo)
|
|
|
|
|
|
def test_tu_vote_null_voteinfo_raises_exception(user: User):
|
|
with pytest.raises(IntegrityError):
|
|
TUVote(User=user)
|
|
|
|
|
|
def test_tu_vote_bad_decision_raises_exception(user: User,
|
|
tu_voteinfo: TUVoteInfo):
|
|
with pytest.raises(IntegrityError):
|
|
TUVote(User=user, VoteInfo=tu_voteinfo, Decision=None)
|
|
|
|
with pytest.raises(IntegrityError):
|
|
TUVote(User=user, VoteInfo=tu_voteinfo, Decision=0)
|