Commit e401b92a authored by Kevin Morris's avatar Kevin Morris
Browse files

add PackageDependency (PackageDepends) ORM model


Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 068c8ba6
from sqlalchemy.orm import mapper
from aurweb.db import make_relationship
from aurweb.models.dependency_type import DependencyType
from aurweb.models.package import Package
from aurweb.schema import PackageDepends
class PackageDependency:
def __init__(self, Package: Package = None,
DependencyType: DependencyType = None,
DepName: str = None, DepDesc: str = None,
DepCondition: str = None, DepArch: str = None):
self.Package = Package
self.DependencyType = DependencyType
self.DepName = DepName # nullable=False
self.DepDesc = DepDesc
self.DepCondition = DepCondition
self.DepArch = DepArch
properties = {
"Package": make_relationship(Package, PackageDepends.c.PackageID,
"package_dependencies"),
"DependencyType": make_relationship(DependencyType,
PackageDepends.c.DepTypeID,
"package_dependencies")
}
mapper(PackageDependency, PackageDepends, properties=properties,
primary_key=[PackageDepends.c.PackageID, PackageDepends.c.DepTypeID])
import pytest
from sqlalchemy.exc import IntegrityError
from aurweb.db import create, query
from aurweb.models.account_type import AccountType
from aurweb.models.dependency_type import DependencyType
from aurweb.models.package import Package
from aurweb.models.package_base import PackageBase
from aurweb.models.package_dependency import PackageDependency
from aurweb.models.user import User
from aurweb.testing import setup_test_db
user = pkgbase = package = None
@pytest.fixture(autouse=True)
def setup():
global user, pkgbase, package
setup_test_db("Users", "PackageBases", "Packages", "PackageDepends")
account_type = query(AccountType,
AccountType.AccountType == "User").first()
user = create(User, Username="test", Email="test@example.org",
RealName="Test User", Passwd="testPassword",
AccountType=account_type)
pkgbase = create(PackageBase,
Name="test-package",
Maintainer=user)
package = create(Package,
PackageBase=pkgbase,
Name=pkgbase.Name,
Description="Test description.",
URL="https://test.package")
def test_package_dependencies():
depends = query(DependencyType, DependencyType.Name == "depends").first()
pkgdep = create(PackageDependency, Package=package,
DependencyType=depends,
DepName="test-dep")
assert pkgdep.DepName == "test-dep"
assert pkgdep.Package == package
assert pkgdep.DependencyType == depends
assert pkgdep in depends.package_dependencies
assert pkgdep in package.package_dependencies
makedepends = query(DependencyType,
DependencyType.Name == "makedepends").first()
pkgdep = create(PackageDependency, Package=package,
DependencyType=makedepends,
DepName="test-dep")
assert pkgdep.DepName == "test-dep"
assert pkgdep.Package == package
assert pkgdep.DependencyType == makedepends
assert pkgdep in makedepends.package_dependencies
assert pkgdep in package.package_dependencies
checkdepends = query(DependencyType,
DependencyType.Name == "checkdepends").first()
pkgdep = create(PackageDependency, Package=package,
DependencyType=checkdepends,
DepName="test-dep")
assert pkgdep.DepName == "test-dep"
assert pkgdep.Package == package
assert pkgdep.DependencyType == checkdepends
assert pkgdep in checkdepends.package_dependencies
assert pkgdep in package.package_dependencies
optdepends = query(DependencyType,
DependencyType.Name == "optdepends").first()
pkgdep = create(PackageDependency, Package=package,
DependencyType=optdepends,
DepName="test-dep")
assert pkgdep.DepName == "test-dep"
assert pkgdep.Package == package
assert pkgdep.DependencyType == optdepends
assert pkgdep in optdepends.package_dependencies
assert pkgdep in package.package_dependencies
def test_package_dependencies_null_package_raises_exception():
from aurweb.db import session
depends = query(DependencyType, DependencyType.Name == "depends").first()
with pytest.raises(IntegrityError):
create(PackageDependency,
DependencyType=depends,
DepName="test-dep")
session.rollback()
def test_package_dependencies_null_dependency_type_raises_exception():
from aurweb.db import session
with pytest.raises(IntegrityError):
create(PackageDependency,
Package=package,
DepName="test-dep")
session.rollback()
def test_package_dependencies_null_depname_raises_exception():
from aurweb.db import session
depends = query(DependencyType, DependencyType.Name == "depends").first()
with pytest.raises(IntegrityError):
create(PackageDependency,
Package=package,
DependencyType=depends)
session.rollback()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment