mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix: TUVote inner join TUVoteInfo for "Last Votes by TU" listing
By implicitly joining, sqlalchemy joined on `TUVote.UsersID = TUVoteInfo.SubmitterID`. This should be joining on `TUVote.VoteID = TUVoteInfo.ID` instead to include all TUVote instances found in the database. Closes #266 Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
957803a70b
commit
660d57340a
2 changed files with 28 additions and 12 deletions
|
@ -81,17 +81,18 @@ async def trusted_user(request: Request,
|
|||
context["past_off"] = past_off
|
||||
|
||||
last_vote = func.max(models.TUVote.VoteID).label("LastVote")
|
||||
last_votes_by_tu = db.query(models.TUVote).join(
|
||||
models.User
|
||||
).join(models.TUVoteInfo).filter(
|
||||
last_votes_by_tu = db.query(models.TUVote).join(models.User).join(
|
||||
models.TUVoteInfo,
|
||||
models.TUVoteInfo.ID == models.TUVote.VoteID
|
||||
).filter(
|
||||
and_(models.TUVote.VoteID == models.TUVoteInfo.ID,
|
||||
models.User.ID == models.TUVote.UserID,
|
||||
models.TUVoteInfo.End <= ts,
|
||||
models.TUVoteInfo.End < ts,
|
||||
or_(models.User.AccountTypeID == 2,
|
||||
models.User.AccountTypeID == 4))
|
||||
).with_entities(
|
||||
models.TUVote.UserID,
|
||||
func.max(models.TUVote.VoteID).label("LastVote"),
|
||||
last_vote,
|
||||
models.User.Username
|
||||
).group_by(models.TUVote.UserID).order_by(
|
||||
last_vote.desc(), models.User.Username.asc())
|
||||
|
|
|
@ -10,7 +10,7 @@ import pytest
|
|||
from fastapi.testclient import TestClient
|
||||
|
||||
from aurweb import config, db, filters, time
|
||||
from aurweb.models.account_type import DEVELOPER_ID, AccountType
|
||||
from aurweb.models.account_type import DEVELOPER_ID, TRUSTED_USER_ID, AccountType
|
||||
from aurweb.models.tu_vote import TUVote
|
||||
from aurweb.models.tu_voteinfo import TUVoteInfo
|
||||
from aurweb.models.user import User
|
||||
|
@ -97,6 +97,16 @@ def tu_user():
|
|||
yield tu_user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tu_user2():
|
||||
with db.begin():
|
||||
tu_user2 = db.create(User, Username="test_tu2",
|
||||
Email="test_tu2@example.org",
|
||||
RealName="Test TU 2", Passwd="testPassword",
|
||||
AccountTypeID=TRUSTED_USER_ID)
|
||||
yield tu_user2
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user():
|
||||
user_type = db.query(AccountType,
|
||||
|
@ -435,7 +445,8 @@ def test_tu_index_sorting(client, tu_user):
|
|||
])
|
||||
|
||||
|
||||
def test_tu_index_last_votes(client, tu_user, user):
|
||||
def test_tu_index_last_votes(client: TestClient, tu_user: User, tu_user2: User,
|
||||
user: User):
|
||||
ts = time.utcnow()
|
||||
|
||||
with db.begin():
|
||||
|
@ -445,12 +456,14 @@ def test_tu_index_last_votes(client, tu_user, user):
|
|||
Submitted=(ts - 1000),
|
||||
End=(ts - 5),
|
||||
Yes=1,
|
||||
No=1,
|
||||
ActiveTUs=1,
|
||||
Quorum=0.0,
|
||||
Submitter=tu_user)
|
||||
|
||||
# Create a vote on it from tu_user.
|
||||
db.create(TUVote, VoteInfo=voteinfo, User=tu_user)
|
||||
db.create(TUVote, VoteInfo=voteinfo, User=tu_user2)
|
||||
|
||||
# Now, check that tu_user got populated in the .last-votes table.
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
|
@ -461,16 +474,18 @@ def test_tu_index_last_votes(client, tu_user, user):
|
|||
root = parse_root(response.text)
|
||||
table = get_table(root, "last-votes")
|
||||
rows = get_table_rows(table)
|
||||
assert len(rows) == 1
|
||||
assert len(rows) == 2
|
||||
|
||||
last_vote = rows[0]
|
||||
user, vote_id = last_vote.xpath("./td")
|
||||
user = user.xpath("./a")[0]
|
||||
vote_id = vote_id.xpath("./a")[0]
|
||||
|
||||
user, vote_id = last_vote.xpath("./td/a")
|
||||
assert user.text.strip() == tu_user.Username
|
||||
assert int(vote_id.text.strip()) == voteinfo.ID
|
||||
|
||||
last_vote = rows[1]
|
||||
user, vote_id = last_vote.xpath("./td/a")
|
||||
assert int(vote_id.text.strip()) == voteinfo.ID
|
||||
assert user.text.strip() == tu_user2.Username
|
||||
|
||||
|
||||
def test_tu_proposal_not_found(client, tu_user):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
|
|
Loading…
Add table
Reference in a new issue