Commit 408300ef authored by Kevin Morris's avatar Kevin Morris
Browse files

add PackageKeyword SQLAlchemy ORM model


Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 950659f2
Pipeline #7870 passed with stage
in 2 minutes and 49 seconds
from sqlalchemy.orm import mapper
from aurweb.db import make_relationship
from aurweb.models.package_base import PackageBase
from aurweb.schema import PackageKeywords
class PackageKeyword:
def __init__(self,
PackageBase: PackageBase = None,
Keyword: str = None):
self.PackageBase = PackageBase
self.Keyword = Keyword
mapper(PackageKeyword, PackageKeywords, properties={
"PackageBase": make_relationship(PackageBase,
PackageKeywords.c.PackageBaseID,
"keywords")
})
import pytest
from sqlalchemy.exc import IntegrityError
from aurweb.db import create, query
from aurweb.models.account_type import AccountType
from aurweb.models.package_base import PackageBase
from aurweb.models.package_keyword import PackageKeyword
from aurweb.testing import setup_test_db
from aurweb.testing.models import make_user
user, pkgbase = None, None
@pytest.fixture(autouse=True)
def setup():
global user, pkgbase
setup_test_db("Users", "PackageBases", "PackageKeywords")
account_type = query(AccountType,
AccountType.AccountType == "User").first()
user = make_user(Username="test", Email="test@example.org",
RealName="Test User", Passwd="testPassword",
AccountType=account_type)
pkgbase = create(PackageBase,
Name="beautiful-package",
Maintainer=user)
yield pkgbase
from aurweb.db import session
session.delete(pkgbase)
session.commit()
def test_package_keyword():
from aurweb.db import session
pkg_keyword = create(PackageKeyword,
PackageBase=pkgbase,
Keyword="test")
assert pkg_keyword in pkgbase.keywords
assert pkgbase == pkg_keyword.PackageBase
session.delete(pkg_keyword)
session.commit()
def test_package_keyword_null_pkgbase_raises_exception():
from aurweb.db import session
with pytest.raises(IntegrityError):
create(PackageKeyword,
Keyword="test")
session.rollback()
Markdown is supported
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