Skip to content
Snippets Groups Projects
Commit 511f174c authored by Kevin Morris's avatar Kevin Morris
Browse files

add PackageBlacklist SQLAlchemy ORM model


Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 163e4d73
No related branches found
No related tags found
1 merge request!75add PackageBlacklist SQLAlchemy ORM model
Pipeline #8421 passed
from sqlalchemy import Column, Integer
from sqlalchemy.exc import IntegrityError
from aurweb.models.declarative import Base
class PackageBlacklist(Base):
__tablename__ = "PackageBlacklist"
ID = Column(Integer, primary_key=True)
__mapper_args__ = {"primary_key": [ID]}
def __init__(self, Name: str = None):
self.Name = Name
if not self.Name:
raise IntegrityError(
statement="Column Name cannot be null.",
orig="PackageBlacklist.Name",
params=("NULL"))
import pytest
from sqlalchemy.exc import IntegrityError
from aurweb.db import create, rollback
from aurweb.models.package_base import PackageBase
from aurweb.models.package_blacklist import PackageBlacklist
from aurweb.models.user import User
from aurweb.testing import setup_test_db
user = pkgbase = None
@pytest.fixture(autouse=True)
def setup():
global user, pkgbase
setup_test_db("PackageBlacklist", "PackageBases", "Users")
user = create(User, Username="test", Email="test@example.org",
RealName="Test User", Passwd="testPassword")
pkgbase = create(PackageBase, Name="test-package", Maintainer=user)
def test_package_blacklist_creation():
package_blacklist = create(PackageBlacklist, Name="evil-package")
assert bool(package_blacklist.ID)
assert package_blacklist.Name == "evil-package"
def test_package_blacklist_null_name_raises_exception():
with pytest.raises(IntegrityError):
create(PackageBlacklist)
rollback()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment