mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
housekeep(fastapi): rewrite test_package_license with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
a082de5244
commit
655b98d19e
1 changed files with 19 additions and 7 deletions
|
@ -10,25 +10,37 @@ from aurweb.models.package_base import PackageBase
|
|||
from aurweb.models.package_license import PackageLicense
|
||||
from aurweb.models.user import User
|
||||
|
||||
user = license = pkgbase = package = None
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup(db_test):
|
||||
global user, license, pkgbase, package
|
||||
return
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user() -> User:
|
||||
with db.begin():
|
||||
user = db.create(User, Username="test", Email="test@example.org",
|
||||
RealName="Test User", Passwd="testPassword",
|
||||
AccountTypeID=USER_ID)
|
||||
license = db.create(License, Name="Test License")
|
||||
yield user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def license() -> License:
|
||||
with db.begin():
|
||||
license = db.create(License, Name="Test License")
|
||||
yield license
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def package(user: User, license: License):
|
||||
with db.begin():
|
||||
pkgbase = db.create(PackageBase, Name="test-package", Maintainer=user)
|
||||
package = db.create(Package, PackageBase=pkgbase, Name=pkgbase.Name)
|
||||
yield package
|
||||
|
||||
|
||||
def test_package_license():
|
||||
def test_package_license(license: License, package: Package):
|
||||
with db.begin():
|
||||
package_license = db.create(PackageLicense, Package=package,
|
||||
License=license)
|
||||
|
@ -36,11 +48,11 @@ def test_package_license():
|
|||
assert package_license.Package == package
|
||||
|
||||
|
||||
def test_package_license_null_package_raises_exception():
|
||||
def test_package_license_null_package_raises(license: License):
|
||||
with pytest.raises(IntegrityError):
|
||||
PackageLicense(License=license)
|
||||
|
||||
|
||||
def test_package_license_null_license_raises_exception():
|
||||
def test_package_license_null_license_raises(package: Package):
|
||||
with pytest.raises(IntegrityError):
|
||||
PackageLicense(Package=package)
|
||||
|
|
Loading…
Add table
Reference in a new issue