mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
housekeep(fastapi): rewrite test_package_vote with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
150c944758
commit
05bd6e9076
1 changed files with 18 additions and 8 deletions
|
@ -5,24 +5,34 @@ import pytest
|
|||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from aurweb import db
|
||||
from aurweb.models.account_type import USER_ID
|
||||
from aurweb.models.package_base import PackageBase
|
||||
from aurweb.models.package_vote import PackageVote
|
||||
from aurweb.models.user import User
|
||||
|
||||
user = pkgbase = None
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup(db_test):
|
||||
global user, pkgbase
|
||||
return
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user() -> User:
|
||||
with db.begin():
|
||||
user = db.create(User, Username="test", Email="test@example.org",
|
||||
RealName="Test User", Passwd="testPassword")
|
||||
RealName="Test User", Passwd=str(),
|
||||
AccountTypeID=USER_ID)
|
||||
yield user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pkgbase(user: User) -> PackageBase:
|
||||
with db.begin():
|
||||
pkgbase = db.create(PackageBase, Name="test-package", Maintainer=user)
|
||||
yield pkgbase
|
||||
|
||||
|
||||
def test_package_vote_creation():
|
||||
def test_package_vote_creation(user: User, pkgbase: PackageBase):
|
||||
ts = int(datetime.utcnow().timestamp())
|
||||
|
||||
with db.begin():
|
||||
|
@ -34,16 +44,16 @@ def test_package_vote_creation():
|
|||
assert package_vote.VoteTS == ts
|
||||
|
||||
|
||||
def test_package_vote_null_user_raises_exception():
|
||||
def test_package_vote_null_user_raises(pkgbase: PackageBase):
|
||||
with pytest.raises(IntegrityError):
|
||||
PackageVote(PackageBase=pkgbase, VoteTS=1)
|
||||
|
||||
|
||||
def test_package_vote_null_pkgbase_raises_exception():
|
||||
def test_package_vote_null_pkgbase_raises(user: User):
|
||||
with pytest.raises(IntegrityError):
|
||||
PackageVote(User=user, VoteTS=1)
|
||||
|
||||
|
||||
def test_package_vote_null_votets_raises_exception():
|
||||
def test_package_vote_null_votets_raises(user: User, pkgbase: PackageBase):
|
||||
with pytest.raises(IntegrityError):
|
||||
PackageVote(User=user, PackageBase=pkgbase)
|
||||
|
|
Loading…
Add table
Reference in a new issue