mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
This change utilizes pytest-xdist to perform a multiproc test run and reworks aurweb.db's code. We no longer use a global engine, session or Session, but we now use a memo of engines and sessions as they are requested, based on the PYTEST_CURRENT_TEST environment variable, which is available during testing. Additionally, this change strips several SQLite components out of the Python code-base. SQLite is still compatible with PHP and sharness tests, but not with our FastAPI implementation. More changes: ------------ - Remove use of aurweb.db.session global in other code. - Use new aurweb.db.name() dynamic db name function in env.py. - Added 'addopts' to pytest.ini which utilizes multiprocessing. - Highly recommended to leave this be or modify `-n auto` to `-n {cpu_threads}` where cpu_threads is at least 2. Signed-off-by: Kevin Morris <kevr@0cost.org>
63 lines
2 KiB
Python
63 lines
2 KiB
Python
import pytest
|
|
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
|
from aurweb import db
|
|
from aurweb.models.account_type import USER_ID
|
|
from aurweb.models.package import Package
|
|
from aurweb.models.package_base import PackageBase
|
|
from aurweb.models.package_relation import PackageRelation
|
|
from aurweb.models.relation_type import CONFLICTS_ID, PROVIDES_ID, REPLACES_ID
|
|
from aurweb.models.user import User
|
|
|
|
user = pkgbase = package = None
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def setup(db_test):
|
|
global user, pkgbase, package
|
|
|
|
with db.begin():
|
|
user = db.create(User, Username="test", Email="test@example.org",
|
|
RealName="Test User", Passwd="testPassword",
|
|
AccountTypeID=USER_ID)
|
|
pkgbase = db.create(PackageBase,
|
|
Name="test-package",
|
|
Maintainer=user)
|
|
package = db.create(Package,
|
|
PackageBase=pkgbase,
|
|
Name=pkgbase.Name,
|
|
Description="Test description.",
|
|
URL="https://test.package")
|
|
|
|
|
|
def test_package_relation():
|
|
with db.begin():
|
|
pkgrel = db.create(PackageRelation, Package=package,
|
|
RelTypeID=CONFLICTS_ID,
|
|
RelName="test-relation")
|
|
|
|
assert pkgrel.RelName == "test-relation"
|
|
assert pkgrel.Package == package
|
|
assert pkgrel in package.package_relations
|
|
|
|
with db.begin():
|
|
pkgrel.RelTypeID = PROVIDES_ID
|
|
|
|
with db.begin():
|
|
pkgrel.RelTypeID = REPLACES_ID
|
|
|
|
|
|
def test_package_relation_null_package_raises_exception():
|
|
with pytest.raises(IntegrityError):
|
|
PackageRelation(RelTypeID=CONFLICTS_ID, RelName="test-relation")
|
|
|
|
|
|
def test_package_relation_null_relation_type_raises_exception():
|
|
with pytest.raises(IntegrityError):
|
|
PackageRelation(Package=package, RelName="test-relation")
|
|
|
|
|
|
def test_package_relation_null_relname_raises_exception():
|
|
with pytest.raises(IntegrityError):
|
|
PackageRelation(Package=package, RelTypeID=CONFLICTS_ID)
|