mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
housekeep(fastapi): rewrite test_package_notification with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
655b98d19e
commit
ff3931e435
1 changed files with 14 additions and 6 deletions
|
@ -7,20 +7,28 @@ from aurweb.models.package_base import PackageBase
|
||||||
from aurweb.models.package_notification import PackageNotification
|
from aurweb.models.package_notification import PackageNotification
|
||||||
from aurweb.models.user import User
|
from aurweb.models.user import User
|
||||||
|
|
||||||
user = pkgbase = None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def setup(db_test):
|
def setup(db_test):
|
||||||
global user, pkgbase
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def user() -> User:
|
||||||
with db.begin():
|
with db.begin():
|
||||||
user = db.create(User, Username="test", Email="test@example.org",
|
user = db.create(User, Username="test", Email="test@example.org",
|
||||||
RealName="Test User", Passwd="testPassword")
|
RealName="Test User", Passwd="testPassword")
|
||||||
|
yield user
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def pkgbase(user: User) -> PackageBase:
|
||||||
|
with db.begin():
|
||||||
pkgbase = db.create(PackageBase, Name="test-package", Maintainer=user)
|
pkgbase = db.create(PackageBase, Name="test-package", Maintainer=user)
|
||||||
|
yield pkgbase
|
||||||
|
|
||||||
|
|
||||||
def test_package_notification_creation():
|
def test_package_notification_creation(user: User, pkgbase: PackageBase):
|
||||||
with db.begin():
|
with db.begin():
|
||||||
package_notification = db.create(
|
package_notification = db.create(
|
||||||
PackageNotification, User=user, PackageBase=pkgbase)
|
PackageNotification, User=user, PackageBase=pkgbase)
|
||||||
|
@ -29,11 +37,11 @@ def test_package_notification_creation():
|
||||||
assert package_notification.PackageBase == pkgbase
|
assert package_notification.PackageBase == pkgbase
|
||||||
|
|
||||||
|
|
||||||
def test_package_notification_null_user_raises_exception():
|
def test_package_notification_null_user_raises(pkgbase: PackageBase):
|
||||||
with pytest.raises(IntegrityError):
|
with pytest.raises(IntegrityError):
|
||||||
PackageNotification(PackageBase=pkgbase)
|
PackageNotification(PackageBase=pkgbase)
|
||||||
|
|
||||||
|
|
||||||
def test_package_notification_null_pkgbase_raises_exception():
|
def test_package_notification_null_pkgbase_raises(user: User):
|
||||||
with pytest.raises(IntegrityError):
|
with pytest.raises(IntegrityError):
|
||||||
PackageNotification(User=user)
|
PackageNotification(User=user)
|
||||||
|
|
Loading…
Add table
Reference in a new issue