Commit 4201348d authored by Kevin Morris's avatar Kevin Morris
Browse files

add PackageGroup SQLAlchemy ORM model


Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent a8a9c287
from sqlalchemy.orm import mapper
from aurweb.db import make_relationship
from aurweb.models.group import Group
from aurweb.models.package import Package
from aurweb.schema import PackageGroups
class PackageGroup:
def __init__(self, Package: Package = None, Group: Group = None):
self.Package = Package
self.Group = Group
properties = {
"Package": make_relationship(Package,
PackageGroups.c.PackageID,
"package_group",
uselist=False),
"Group": make_relationship(Group,
PackageGroups.c.GroupID,
"package_group",
uselist=False)
}
mapper(PackageGroup, PackageGroups, properties=properties,
primary_key=[PackageGroups.c.PackageID, PackageGroups.c.GroupID])
import pytest
from sqlalchemy.exc import IntegrityError
from aurweb.db import create, query
from aurweb.models.account_type import AccountType
from aurweb.models.group import Group
from aurweb.models.package import Package
from aurweb.models.package_base import PackageBase
from aurweb.models.package_group import PackageGroup
from aurweb.models.user import User
from aurweb.testing import setup_test_db
user = group = pkgbase = package = None
@pytest.fixture(autouse=True)
def setup():
global user, group, pkgbase, package
setup_test_db("Users", "PackageBases", "Packages",
"Groups", "PackageGroups")
account_type = query(AccountType,
AccountType.AccountType == "User").first()
user = create(User, Username="test", Email="test@example.org",
RealName="Test User", Passwd="testPassword",
account_type=account_type)
group = create(Group, Name="Test Group")
pkgbase = create(PackageBase, Name="test-package", Maintainer=user)
package = create(Package, PackageBase=pkgbase, Name=pkgbase.Name)
def test_package_group():
package_group = create(PackageGroup, Package=package, Group=group)
assert package_group.Group == group
assert package_group.Package == package
def test_package_group_null_package_raises_exception():
from aurweb.db import session
with pytest.raises(IntegrityError):
create(PackageGroup, Group=group)
session.rollback()
def test_package_group_null_group_raises_exception():
from aurweb.db import session
with pytest.raises(IntegrityError):
create(PackageGroup, Package=package)
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