diff --git a/test/test_package_notification.py b/test/test_package_notification.py index 2e505dd8..e7a72a43 100644 --- a/test/test_package_notification.py +++ b/test/test_package_notification.py @@ -7,20 +7,28 @@ from aurweb.models.package_base import PackageBase from aurweb.models.package_notification import PackageNotification 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") + 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_notification_creation(): +def test_package_notification_creation(user: User, pkgbase: PackageBase): with db.begin(): package_notification = db.create( PackageNotification, User=user, PackageBase=pkgbase) @@ -29,11 +37,11 @@ def test_package_notification_creation(): 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): PackageNotification(PackageBase=pkgbase) -def test_package_notification_null_pkgbase_raises_exception(): +def test_package_notification_null_pkgbase_raises(user: User): with pytest.raises(IntegrityError): PackageNotification(User=user)