housekeep(fastapi): rewrite test_package_notification with fixtures

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-30 18:10:40 -08:00
parent 655b98d19e
commit ff3931e435
No known key found for this signature in database
GPG key ID: F7E46DED420788F3

View file

@ -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)