mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
calculate dependencies based on package information (#89)
This commit is contained in:
@ -2,7 +2,7 @@ import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, call as MockCall
|
||||
|
||||
from ahriman.application.application.application_packages import ApplicationPackages
|
||||
from ahriman.models.package import Package
|
||||
@ -29,18 +29,12 @@ def test_add_aur(application_packages: ApplicationPackages, package_ahriman: Pac
|
||||
must add package from AUR
|
||||
"""
|
||||
mocker.patch("ahriman.models.package.Package.from_aur", return_value=package_ahriman)
|
||||
load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load")
|
||||
dependencies_mock = mocker.patch(
|
||||
"ahriman.application.application.application_packages.ApplicationPackages._process_dependencies")
|
||||
build_queue_mock = mocker.patch("ahriman.core.database.SQLite.build_queue_insert")
|
||||
update_remote_mock = mocker.patch("ahriman.core.database.SQLite.remote_update")
|
||||
|
||||
application_packages._add_aur(package_ahriman.base, set(), False)
|
||||
load_mock.assert_called_once_with(
|
||||
pytest.helpers.anyvar(int),
|
||||
package_ahriman,
|
||||
pytest.helpers.anyvar(int),
|
||||
application_packages.repository.paths)
|
||||
dependencies_mock.assert_called_once_with(pytest.helpers.anyvar(int), set(), False)
|
||||
build_queue_mock.assert_called_once_with(package_ahriman)
|
||||
update_remote_mock.assert_called_once_with(package_ahriman)
|
||||
@ -121,43 +115,37 @@ def test_known_packages(application_packages: ApplicationPackages) -> None:
|
||||
application_packages._known_packages()
|
||||
|
||||
|
||||
def test_process_dependencies(application_packages: ApplicationPackages, mocker: MockerFixture) -> None:
|
||||
def test_process_dependencies(application_packages: ApplicationPackages, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process dependencies addition
|
||||
"""
|
||||
missing = {"python"}
|
||||
path = Path("local")
|
||||
dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies", return_value=missing)
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages.add")
|
||||
|
||||
application_packages._process_dependencies(path, set(), False)
|
||||
dependencies_mock.assert_called_once_with(path)
|
||||
add_mock.assert_called_once_with(missing, PackageSource.AUR, False)
|
||||
application_packages._process_dependencies(package_ahriman, set(), False)
|
||||
add_mock.assert_called_once_with(package_ahriman.depends_build, PackageSource.AUR, False)
|
||||
|
||||
|
||||
def test_process_dependencies_missing(application_packages: ApplicationPackages, mocker: MockerFixture) -> None:
|
||||
def test_process_dependencies_missing(application_packages: ApplicationPackages, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process dependencies addition only for missing packages
|
||||
"""
|
||||
path = Path("local")
|
||||
dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies",
|
||||
return_value={"python", "python-aiohttp"})
|
||||
missing = {"devtools"}
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages.add")
|
||||
|
||||
application_packages._process_dependencies(path, {"python"}, False)
|
||||
dependencies_mock.assert_called_once_with(path)
|
||||
add_mock.assert_called_once_with({"python-aiohttp"}, PackageSource.AUR, False)
|
||||
application_packages._process_dependencies(
|
||||
package_ahriman, package_ahriman.depends_build.difference(missing), False)
|
||||
add_mock.assert_called_once_with(missing, PackageSource.AUR, False)
|
||||
|
||||
|
||||
def test_process_dependencies_skip(application_packages: ApplicationPackages, mocker: MockerFixture) -> None:
|
||||
def test_process_dependencies_skip(application_packages: ApplicationPackages, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip dependencies processing
|
||||
"""
|
||||
dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies")
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages.add")
|
||||
|
||||
application_packages._process_dependencies(Path("local"), set(), True)
|
||||
dependencies_mock.assert_not_called()
|
||||
application_packages._process_dependencies(package_ahriman, set(), True)
|
||||
add_mock.assert_not_called()
|
||||
|
||||
|
||||
|
@ -161,7 +161,7 @@ def test_update(application_repository: ApplicationRepository, package_ahriman:
|
||||
must process package updates
|
||||
"""
|
||||
paths = [package.filepath for package in package_ahriman.packages.values()]
|
||||
tree = Tree([Leaf(package_ahriman, set())])
|
||||
tree = Tree([Leaf(package_ahriman)])
|
||||
|
||||
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_built", return_value=paths)
|
||||
@ -181,7 +181,7 @@ def test_update_empty(application_repository: ApplicationRepository, package_ahr
|
||||
"""
|
||||
must skip updating repository if no packages supplied
|
||||
"""
|
||||
tree = Tree([Leaf(package_ahriman, set())])
|
||||
tree = Tree([Leaf(package_ahriman)])
|
||||
|
||||
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_built", return_value=[])
|
||||
@ -197,7 +197,7 @@ def test_updates_all(application_repository: ApplicationRepository, package_ahri
|
||||
"""
|
||||
must get updates for all
|
||||
"""
|
||||
tree = Tree([Leaf(package_ahriman, set())])
|
||||
tree = Tree([Leaf(package_ahriman)])
|
||||
|
||||
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[])
|
||||
|
@ -56,4 +56,4 @@ def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, rep
|
||||
RemoveUnknown.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
application_mock.assert_called_once_with()
|
||||
remove_mock.assert_not_called()
|
||||
print_mock.assert_called_once_with(False)
|
||||
print_mock.assert_called_once_with(verbose=False)
|
||||
|
@ -46,7 +46,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
aur_search_mock.assert_called_once_with("ahriman", pacman=pytest.helpers.anyvar(int))
|
||||
official_search_mock.assert_called_once_with("ahriman", pacman=pytest.helpers.anyvar(int))
|
||||
check_mock.assert_called_once_with(False, False)
|
||||
print_mock.assert_has_calls([MockCall(False), MockCall(False)])
|
||||
print_mock.assert_has_calls([MockCall(verbose=False), MockCall(verbose=False)])
|
||||
|
||||
|
||||
def test_run_empty_exception(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
|
@ -47,7 +47,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
application_mock.assert_called_once_with()
|
||||
packages_mock.assert_called_once_with(None)
|
||||
check_mock.assert_called_once_with(False, False)
|
||||
print_mock.assert_has_calls([MockCall(False) for _ in range(3)])
|
||||
print_mock.assert_has_calls([MockCall(verbose=False) for _ in range(3)])
|
||||
|
||||
|
||||
def test_run_empty_exception(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
@ -79,7 +79,7 @@ def test_run_verbose(args: argparse.Namespace, configuration: Configuration, rep
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
|
||||
Status.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
print_mock.assert_has_calls([MockCall(True) for _ in range(2)])
|
||||
print_mock.assert_has_calls([MockCall(verbose=True) for _ in range(2)])
|
||||
|
||||
|
||||
def test_run_with_package_filter(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
@ -111,7 +111,7 @@ def test_run_by_status(args: argparse.Namespace, configuration: Configuration, r
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
|
||||
Status.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
print_mock.assert_has_calls([MockCall(False) for _ in range(2)])
|
||||
print_mock.assert_has_calls([MockCall(verbose=False) for _ in range(2)])
|
||||
|
||||
|
||||
def test_imply_with_report(args: argparse.Namespace, configuration: Configuration, database: SQLite,
|
||||
|
@ -1,5 +1,4 @@
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
@ -20,7 +19,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
|
||||
Structure.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
application_mock.assert_called_once_with([package_ahriman], repository.paths, pytest.helpers.anyvar(int))
|
||||
application_mock.assert_called_once_with([package_ahriman])
|
||||
print_mock.assert_called_once_with(verbose=True, separator=" ")
|
||||
|
||||
|
||||
|
@ -98,29 +98,37 @@ def aur_package_ahriman() -> AURPackage:
|
||||
AURPackage: AUR package test instance
|
||||
"""
|
||||
return AURPackage(
|
||||
id=1009791,
|
||||
id=1197565,
|
||||
name="ahriman",
|
||||
package_base_id=165427,
|
||||
package_base="ahriman",
|
||||
version="1.7.0-1",
|
||||
version="2.6.0-1",
|
||||
description="ArcH linux ReposItory MANager",
|
||||
num_votes=0,
|
||||
popularity=0,
|
||||
first_submitted=datetime.datetime.utcfromtimestamp(1618008285),
|
||||
last_modified=datetime.datetime.utcfromtimestamp(1640473871),
|
||||
last_modified=datetime.datetime.utcfromtimestamp(1673826351),
|
||||
url_path="/cgit/aur.git/snapshot/ahriman.tar.gz",
|
||||
url="https://github.com/arcan1s/ahriman",
|
||||
out_of_date=None,
|
||||
maintainer="arcanis",
|
||||
submitter="arcanis",
|
||||
depends=[
|
||||
"devtools",
|
||||
"git",
|
||||
"pyalpm",
|
||||
"python-aur",
|
||||
"python-cerberus",
|
||||
"python-inflection",
|
||||
"python-passlib",
|
||||
"python-requests",
|
||||
"python-setuptools",
|
||||
"python-srcinfo",
|
||||
],
|
||||
make_depends=["python-pip"],
|
||||
make_depends=[
|
||||
"python-build",
|
||||
"python-installer",
|
||||
"python-wheel",
|
||||
],
|
||||
opt_depends=[
|
||||
"breezy",
|
||||
"darcs",
|
||||
@ -133,6 +141,7 @@ def aur_package_ahriman() -> AURPackage:
|
||||
"python-aiohttp-session",
|
||||
"python-boto3",
|
||||
"python-cryptography",
|
||||
"python-requests-unixsocket",
|
||||
"python-jinja",
|
||||
"rsync",
|
||||
"subversion",
|
||||
@ -251,7 +260,7 @@ def package_ahriman(package_description_ahriman: PackageDescription, remote_sour
|
||||
packages = {"ahriman": package_description_ahriman}
|
||||
return Package(
|
||||
base="ahriman",
|
||||
version="1.7.0-1",
|
||||
version="2.6.0-1",
|
||||
remote=remote_source,
|
||||
packages=packages)
|
||||
|
||||
@ -297,12 +306,37 @@ def package_description_ahriman() -> PackageDescription:
|
||||
"devtools",
|
||||
"git",
|
||||
"pyalpm",
|
||||
"python-aur",
|
||||
"python-cerberus",
|
||||
"python-inflection",
|
||||
"python-passlib",
|
||||
"python-requests",
|
||||
"python-setuptools",
|
||||
"python-srcinfo",
|
||||
],
|
||||
make_depends=[
|
||||
"python-build",
|
||||
"python-installer",
|
||||
"python-wheel",
|
||||
],
|
||||
opt_depends=[
|
||||
"breezy",
|
||||
"darcs",
|
||||
"mercurial",
|
||||
"python-aioauth-client",
|
||||
"python-aiohttp",
|
||||
"python-aiohttp-debugtoolbar",
|
||||
"python-aiohttp-jinja2",
|
||||
"python-aiohttp-security",
|
||||
"python-aiohttp-session",
|
||||
"python-boto3",
|
||||
"python-cryptography",
|
||||
"python-requests-unixsocket",
|
||||
"python-jinja",
|
||||
"rsync",
|
||||
"subversion",
|
||||
],
|
||||
description="ArcH linux ReposItory MANager",
|
||||
filename="ahriman-1.7.0-1-any.pkg.tar.zst",
|
||||
filename="ahriman-2.6.0-1-any.pkg.tar.zst",
|
||||
groups=[],
|
||||
installed_size=4200000,
|
||||
licenses=["GPL3"],
|
||||
|
@ -20,7 +20,7 @@ def leaf_ahriman(package_ahriman: Package) -> Leaf:
|
||||
Returns:
|
||||
Leaf: tree leaf test instance
|
||||
"""
|
||||
return Leaf(package_ahriman, set())
|
||||
return Leaf(package_ahriman)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -34,7 +34,7 @@ def leaf_python_schedule(package_python_schedule: Package) -> Leaf:
|
||||
Returns:
|
||||
Leaf: tree leaf test instance
|
||||
"""
|
||||
return Leaf(package_python_schedule, set())
|
||||
return Leaf(package_python_schedule)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -1,47 +0,0 @@
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.data import migrate_data
|
||||
from ahriman.models.migration_result import MigrationResult
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migrate_data_initial(connection: Connection, configuration: Configuration,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform initial migration
|
||||
"""
|
||||
packages = mocker.patch("ahriman.core.database.data.migrate_package_statuses")
|
||||
patches = mocker.patch("ahriman.core.database.data.migrate_patches")
|
||||
users = mocker.patch("ahriman.core.database.data.migrate_users_data")
|
||||
remotes = mocker.patch("ahriman.core.database.data.migrate_package_remotes")
|
||||
|
||||
migrate_data(MigrationResult(old_version=0, new_version=900), connection, configuration)
|
||||
packages.assert_called_once_with(connection, repository_paths)
|
||||
patches.assert_called_once_with(connection, repository_paths)
|
||||
users.assert_called_once_with(connection, configuration)
|
||||
remotes.assert_called_once_with(connection, repository_paths)
|
||||
|
||||
|
||||
def test_migrate_data_remotes(connection: Connection, configuration: Configuration,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform initial migration
|
||||
"""
|
||||
remotes = mocker.patch("ahriman.core.database.data.migrate_package_remotes")
|
||||
|
||||
migrate_data(MigrationResult(old_version=1, new_version=900), connection, configuration)
|
||||
remotes.assert_called_once_with(connection, repository_paths)
|
||||
|
||||
|
||||
def test_migrate_data_skip(connection: Connection, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not migrate data if version is up-to-date
|
||||
"""
|
||||
packages = mocker.patch("ahriman.core.database.data.migrate_package_statuses")
|
||||
users = mocker.patch("ahriman.core.database.data.migrate_users_data")
|
||||
|
||||
migrate_data(MigrationResult(old_version=900, new_version=900), connection, configuration)
|
||||
packages.assert_not_called()
|
||||
users.assert_not_called()
|
@ -1,66 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
|
||||
from ahriman.core.database.data import migrate_package_remotes
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migrate_package_remotes(package_ahriman: Package, connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must put package remotes to database
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_package_remotes_has_local(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip processing for packages which have local cache
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=True)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_not_called()
|
||||
|
||||
|
||||
def test_migrate_package_remotes_vcs(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process VCS packages with local cache
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=True)
|
||||
mocker.patch.object(Package, "is_vcs", True)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_package_remotes_no_remotes(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip processing in case if no remotes generated (should never happen)
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
mocker.patch("ahriman.models.remote_source.RemoteSource.from_source", return_value=None)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_not_called()
|
@ -1,39 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.database.data import migrate_package_statuses
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migrate_package_statuses(connection: Connection, package_ahriman: Package, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must migrate packages to database
|
||||
"""
|
||||
response = {"packages": [pytest.helpers.get_package_status_extended(package_ahriman)]}
|
||||
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
mocker.patch("pathlib.Path.open")
|
||||
mocker.patch("json.load", return_value=response)
|
||||
|
||||
migrate_package_statuses(connection, repository_paths)
|
||||
connection.execute.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
||||
connection.executemany.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
||||
|
||||
|
||||
def test_migrate_package_statuses_skip(connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip packages migration if no cache file found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
migrate_package_statuses(connection, repository_paths)
|
@ -1,52 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
|
||||
from ahriman.core.database.data import migrate_patches
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migrate_patches(connection: Connection, repository_paths: RepositoryPaths,
|
||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform migration for patches
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir", return_value=[Path(package_ahriman.base)])
|
||||
read_mock = mocker.patch("pathlib.Path.read_text", return_value="patch")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_called_once_with()
|
||||
read_mock.assert_called_once_with(encoding="utf8")
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_patches_skip(connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip patches migration in case if no root found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_migrate_patches_no_patch(connection: Connection, repository_paths: RepositoryPaths,
|
||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip package if no match found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir", return_value=[Path(package_ahriman.base)])
|
||||
read_mock = mocker.patch("pathlib.Path.read_text")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_called_once_with()
|
||||
read_mock.assert_not_called()
|
@ -1,21 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from sqlite3 import Connection
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.data import migrate_users_data
|
||||
|
||||
|
||||
def test_migrate_users_data(connection: Connection, configuration: Configuration) -> None:
|
||||
"""
|
||||
must put users to database
|
||||
"""
|
||||
configuration.set_option("auth:read", "user1", "password1")
|
||||
configuration.set_option("auth:write", "user2", "password2")
|
||||
|
||||
migrate_users_data(connection, configuration)
|
||||
connection.execute.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
@ -1,4 +1,15 @@
|
||||
from ahriman.core.database.migrations.m000_initial import steps
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.migrations.m000_initial import migrate_data, migrate_package_statuses, migrate_patches, \
|
||||
migrate_users_data, steps
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migration_initial() -> None:
|
||||
@ -6,3 +17,104 @@ def test_migration_initial() -> None:
|
||||
migration must not be empty
|
||||
"""
|
||||
assert steps
|
||||
|
||||
|
||||
def test_migrate_data(connection: Connection, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform data migration
|
||||
"""
|
||||
packages = mocker.patch("ahriman.core.database.migrations.m000_initial.migrate_package_statuses")
|
||||
patches = mocker.patch("ahriman.core.database.migrations.m000_initial.migrate_patches")
|
||||
users = mocker.patch("ahriman.core.database.migrations.m000_initial.migrate_users_data")
|
||||
|
||||
migrate_data(connection, configuration)
|
||||
packages.assert_called_once_with(connection, configuration.repository_paths)
|
||||
patches.assert_called_once_with(connection, configuration.repository_paths)
|
||||
users.assert_called_once_with(connection, configuration)
|
||||
|
||||
|
||||
def test_migrate_package_statuses(connection: Connection, package_ahriman: Package, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must migrate packages to database
|
||||
"""
|
||||
response = {"packages": [pytest.helpers.get_package_status_extended(package_ahriman)]}
|
||||
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
mocker.patch("pathlib.Path.open")
|
||||
mocker.patch("json.load", return_value=response)
|
||||
|
||||
migrate_package_statuses(connection, repository_paths)
|
||||
connection.execute.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
||||
connection.executemany.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
||||
|
||||
|
||||
def test_migrate_package_statuses_skip(connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip packages migration if no cache file found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
migrate_package_statuses(connection, repository_paths)
|
||||
|
||||
|
||||
def test_migrate_patches(connection: Connection, repository_paths: RepositoryPaths,
|
||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform migration for patches
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir", return_value=[Path(package_ahriman.base)])
|
||||
read_mock = mocker.patch("pathlib.Path.read_text", return_value="patch")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_called_once_with()
|
||||
read_mock.assert_called_once_with(encoding="utf8")
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_patches_skip(connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip patches migration in case if no root found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_migrate_patches_no_patch(connection: Connection, repository_paths: RepositoryPaths,
|
||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip package if no match found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir", return_value=[Path(package_ahriman.base)])
|
||||
read_mock = mocker.patch("pathlib.Path.read_text")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_called_once_with()
|
||||
read_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_migrate_users_data(connection: Connection, configuration: Configuration) -> None:
|
||||
"""
|
||||
must put users to database
|
||||
"""
|
||||
configuration.set_option("auth:read", "user1", "password1")
|
||||
configuration.set_option("auth:write", "user2", "password2")
|
||||
|
||||
migrate_users_data(connection, configuration)
|
||||
connection.execute.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
||||
|
@ -1,4 +1,12 @@
|
||||
from ahriman.core.database.migrations.m001_package_source import steps
|
||||
import pytest
|
||||
|
||||
from sqlite3 import Connection
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.migrations.m001_package_source import migrate_data, migrate_package_remotes, steps
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migration_package_source() -> None:
|
||||
@ -6,3 +14,70 @@ def test_migration_package_source() -> None:
|
||||
migration must not be empty
|
||||
"""
|
||||
assert steps
|
||||
|
||||
|
||||
def test_migrate_data(connection: Connection, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform data migration
|
||||
"""
|
||||
remotes = mocker.patch("ahriman.core.database.migrations.m001_package_source.migrate_package_remotes")
|
||||
migrate_data(connection, configuration)
|
||||
remotes.assert_called_once_with(connection, configuration.repository_paths)
|
||||
|
||||
|
||||
def test_migrate_package_remotes(package_ahriman: Package, connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must put package remotes to database
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_package_remotes_has_local(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip processing for packages which have local cache
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=True)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_not_called()
|
||||
|
||||
|
||||
def test_migrate_package_remotes_vcs(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process VCS packages with local cache
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=True)
|
||||
mocker.patch.object(Package, "is_vcs", True)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_package_remotes_no_remotes(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip processing in case if no remotes generated (should never happen)
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
mocker.patch("ahriman.models.remote_source.RemoteSource.from_source", return_value=None)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_not_called()
|
||||
|
@ -0,0 +1,53 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.migrations.m005_make_opt_depends import migrate_data, migrate_package_depends, steps
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def test_migration_make_opt_depends() -> None:
|
||||
"""
|
||||
migration must not be empty
|
||||
"""
|
||||
assert steps
|
||||
|
||||
|
||||
def test_migrate_data(connection: Connection, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform data migration
|
||||
"""
|
||||
depends_mock = mocker.patch("ahriman.core.database.migrations.m005_make_opt_depends.migrate_package_depends")
|
||||
migrate_data(connection, configuration)
|
||||
depends_mock.assert_called_once_with(connection, configuration)
|
||||
|
||||
|
||||
def test_migrate_package_depends(connection: Connection, configuration: Configuration, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must update make and opt depends list
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.iterdir", return_value=[package_ahriman.packages[package_ahriman.base].filepath])
|
||||
package_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
|
||||
|
||||
migrate_package_depends(connection, configuration)
|
||||
package_mock.assert_called_once_with(
|
||||
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int), remote=None)
|
||||
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
||||
"make_depends": package_ahriman.packages[package_ahriman.base].make_depends,
|
||||
"opt_depends": package_ahriman.packages[package_ahriman.base].opt_depends,
|
||||
"package": package_ahriman.base,
|
||||
}])
|
||||
|
||||
|
||||
def test_migrate_package_depends_skip(connection: Connection, configuration: Configuration,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip update make and opt depends list if no repository directory found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
migrate_package_depends(connection, configuration)
|
||||
connection.executemany.assert_not_called()
|
@ -19,6 +19,19 @@ def test_migrate(connection: Connection, configuration: Configuration, mocker: M
|
||||
run_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_migration(migrations: Migrations, connection: Connection) -> None:
|
||||
"""
|
||||
must perform single migration
|
||||
"""
|
||||
migrate_data_mock = MagicMock()
|
||||
cursor = MagicMock()
|
||||
migration = Migration(index=0, name="test", steps=["select 1"], migrate_data=migrate_data_mock)
|
||||
|
||||
migrations.migration(cursor, migration)
|
||||
cursor.execute.assert_called_once_with("select 1")
|
||||
migrate_data_mock.assert_called_once_with(migrations.connection, migrations.configuration)
|
||||
|
||||
|
||||
def test_migrations(migrations: Migrations) -> None:
|
||||
"""
|
||||
must retrieve migrations
|
||||
@ -40,25 +53,23 @@ def test_run(migrations: Migrations, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run migration
|
||||
"""
|
||||
migration = Migration(index=0, name="test", steps=["select 1"], migrate_data=MagicMock())
|
||||
cursor = MagicMock()
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.user_version", return_value=0)
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.migrations",
|
||||
return_value=[Migration(index=0, name="test", steps=["select 1"])])
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.migrations", return_value=[migration])
|
||||
migrations.connection.cursor.return_value = cursor
|
||||
migration_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migration")
|
||||
validate_mock = mocker.patch("ahriman.models.migration_result.MigrationResult.validate")
|
||||
migrate_data_mock = mocker.patch("ahriman.core.database.migrations.migrate_data")
|
||||
|
||||
migrations.run()
|
||||
validate_mock.assert_called_once_with()
|
||||
cursor.execute.assert_has_calls([
|
||||
MockCall("begin exclusive"),
|
||||
MockCall("select 1"),
|
||||
MockCall("pragma user_version = 1"),
|
||||
MockCall("commit"),
|
||||
])
|
||||
cursor.close.assert_called_once_with()
|
||||
migrate_data_mock.assert_called_once_with(
|
||||
MigrationResult(old_version=0, new_version=1), migrations.connection, migrations.configuration)
|
||||
migration_mock.assert_called_once_with(cursor, migration)
|
||||
|
||||
|
||||
def test_run_migration_exception(migrations: Migrations, mocker: MockerFixture) -> None:
|
||||
@ -69,7 +80,7 @@ def test_run_migration_exception(migrations: Migrations, mocker: MockerFixture)
|
||||
mocker.patch("logging.Logger.info", side_effect=Exception())
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.user_version", return_value=0)
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.migrations",
|
||||
return_value=[Migration(index=0, name="test", steps=["select 1"])])
|
||||
return_value=[Migration(index=0, name="test", steps=["select 1"], migrate_data=MagicMock())])
|
||||
mocker.patch("ahriman.models.migration_result.MigrationResult.validate")
|
||||
migrations.connection.cursor.return_value = cursor
|
||||
|
||||
@ -90,7 +101,7 @@ def test_run_sql_exception(migrations: Migrations, mocker: MockerFixture) -> Non
|
||||
cursor.execute.side_effect = Exception()
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.user_version", return_value=0)
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.migrations",
|
||||
return_value=[Migration(index=0, name="test", steps=["select 1"])])
|
||||
return_value=[Migration(index=0, name="test", steps=["select 1"], migrate_data=MagicMock())])
|
||||
mocker.patch("ahriman.models.migration_result.MigrationResult.validate")
|
||||
migrations.connection.cursor.return_value = cursor
|
||||
|
||||
|
@ -125,7 +125,7 @@ def test_packages_depend_on(repository: Repository, package_ahriman: Package, pa
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages",
|
||||
return_value=[package_ahriman, package_python_schedule])
|
||||
assert repository.packages_depend_on([package_ahriman], ["python-aur"]) == [package_ahriman]
|
||||
assert repository.packages_depend_on([package_ahriman], ["python-srcinfo"]) == [package_ahriman]
|
||||
|
||||
|
||||
def test_packages_depend_on_empty(repository: Repository, package_ahriman: Package, package_python_schedule: Package,
|
||||
|
@ -1,12 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.database import SQLite
|
||||
from ahriman.core.tree import Leaf, Tree
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_leaf_is_root_empty(leaf_ahriman: Leaf) -> None:
|
||||
@ -39,29 +33,11 @@ def test_leaf_is_root_true(leaf_ahriman: Leaf, leaf_python_schedule: Leaf) -> No
|
||||
assert not leaf_ahriman.is_root([leaf_python_schedule])
|
||||
|
||||
|
||||
def test_leaf_load(package_ahriman: Package, repository_paths: RepositoryPaths,
|
||||
database: SQLite, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load with dependencies
|
||||
"""
|
||||
load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load")
|
||||
dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies", return_value={"ahriman-dependency"})
|
||||
|
||||
leaf = Leaf.load(package_ahriman, repository_paths, database)
|
||||
assert leaf.package == package_ahriman
|
||||
assert leaf.dependencies == {"ahriman-dependency"}
|
||||
load_mock.assert_called_once_with(pytest.helpers.anyvar(int), package_ahriman, [], repository_paths)
|
||||
dependencies_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_tree_resolve(package_ahriman: Package, package_python_schedule: Package, repository_paths: RepositoryPaths,
|
||||
database: SQLite, mocker: MockerFixture) -> None:
|
||||
def test_tree_resolve(package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must resolve denendecnies tree
|
||||
"""
|
||||
mocker.patch("ahriman.core.tree.Leaf.load", side_effect=lambda package, p, d: Leaf(package, set(package.depends)))
|
||||
|
||||
tree = Tree.resolve([package_ahriman, package_python_schedule], repository_paths, database)
|
||||
tree = Tree.resolve([package_ahriman, package_python_schedule])
|
||||
assert len(tree) == 1
|
||||
assert len(tree[0]) == 2
|
||||
|
||||
@ -87,36 +63,32 @@ def test_tree_levels_sorted() -> None:
|
||||
base="package1",
|
||||
version="1.0.0",
|
||||
remote=None,
|
||||
packages={"package1": PackageDescription()}
|
||||
),
|
||||
dependencies=set()
|
||||
packages={"package1": PackageDescription(depends=[])}
|
||||
)
|
||||
)
|
||||
leaf2 = Leaf(
|
||||
Package(
|
||||
base="package2",
|
||||
version="1.0.0",
|
||||
remote=None,
|
||||
packages={"package2": PackageDescription()}
|
||||
),
|
||||
dependencies={"package1"}
|
||||
packages={"package2": PackageDescription(depends=["package1"])}
|
||||
)
|
||||
)
|
||||
leaf3 = Leaf(
|
||||
Package(
|
||||
base="package3",
|
||||
version="1.0.0",
|
||||
remote=None,
|
||||
packages={"package3": PackageDescription()}
|
||||
),
|
||||
dependencies={"package1"}
|
||||
packages={"package3": PackageDescription(depends=["package1"])}
|
||||
)
|
||||
)
|
||||
leaf4 = Leaf(
|
||||
Package(
|
||||
base="package4",
|
||||
version="1.0.0",
|
||||
remote=None,
|
||||
packages={"package4": PackageDescription()}
|
||||
),
|
||||
dependencies={"package3"}
|
||||
packages={"package4": PackageDescription(depends=["package3"])}
|
||||
)
|
||||
)
|
||||
|
||||
tree = Tree([leaf1, leaf2, leaf3, leaf4])
|
||||
|
@ -12,7 +12,7 @@ from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.exceptions import BuildError, OptionError, UnsafeRunError
|
||||
from ahriman.core.util import check_output, check_user, enum_values, exception_response_text, filter_json, \
|
||||
full_version, package_like, pretty_datetime, pretty_size, safe_filename, utcnow, walk
|
||||
full_version, package_like, pretty_datetime, pretty_size, safe_filename, trim_package, utcnow, walk
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
@ -322,6 +322,18 @@ def test_safe_filename() -> None:
|
||||
assert safe_filename("tolua++-1.0.93-4-x86_64.pkg.tar.zst") == "tolua---1.0.93-4-x86_64.pkg.tar.zst"
|
||||
|
||||
|
||||
def test_trim_package() -> None:
|
||||
"""
|
||||
must trim package version
|
||||
"""
|
||||
assert trim_package("package=1") == "package"
|
||||
assert trim_package("package>=1") == "package"
|
||||
assert trim_package("package>1") == "package"
|
||||
assert trim_package("package<1") == "package"
|
||||
assert trim_package("package<=1") == "package"
|
||||
assert trim_package("package: a description") == "package"
|
||||
|
||||
|
||||
def test_utcnow() -> None:
|
||||
"""
|
||||
must generate correct timestamp
|
||||
|
@ -22,7 +22,7 @@ def test_calculate_hash_small(resource_path_root: Path) -> None:
|
||||
must calculate checksum for path which is single chunk
|
||||
"""
|
||||
path = resource_path_root / "models" / "package_ahriman_srcinfo"
|
||||
assert HttpUpload.calculate_hash(path) == "fcfc0f2522b0ee92de89fcedc7e56010"
|
||||
assert HttpUpload.calculate_hash(path) == "79b0f84e0232ed34fd191a85c383ecc5"
|
||||
|
||||
|
||||
def test_get_body_get_hashes() -> None:
|
||||
|
@ -30,7 +30,7 @@ def test_calculate_etag_small(resource_path_root: Path) -> None:
|
||||
must calculate checksum for path which is single chunk
|
||||
"""
|
||||
path = resource_path_root / "models" / "package_ahriman_srcinfo"
|
||||
assert S3.calculate_etag(path, _chunk_size) == "fcfc0f2522b0ee92de89fcedc7e56010"
|
||||
assert S3.calculate_etag(path, _chunk_size) == "79b0f84e0232ed34fd191a85c383ecc5"
|
||||
|
||||
|
||||
def test_files_remove(s3_remote_objects: List[Any]) -> None:
|
||||
|
@ -139,6 +139,8 @@ def pyalpm_package_description_ahriman(package_description_ahriman: PackageDescr
|
||||
type(mock).arch = PropertyMock(return_value=package_description_ahriman.architecture)
|
||||
type(mock).builddate = PropertyMock(return_value=package_description_ahriman.build_date)
|
||||
type(mock).depends = PropertyMock(return_value=package_description_ahriman.depends)
|
||||
type(mock).makedepends = PropertyMock(return_value=package_description_ahriman.make_depends)
|
||||
type(mock).optdepends = PropertyMock(return_value=package_description_ahriman.opt_depends)
|
||||
type(mock).desc = PropertyMock(return_value=package_description_ahriman.description)
|
||||
type(mock).groups = PropertyMock(return_value=package_description_ahriman.groups)
|
||||
type(mock).isize = PropertyMock(return_value=package_description_ahriman.installed_size)
|
||||
|
@ -66,6 +66,7 @@ def test_from_pacman(pyalpm_package_ahriman: pyalpm.Package, aur_package_ahriman
|
||||
object.__setattr__(model, "first_submitted", aur_package_ahriman.first_submitted)
|
||||
object.__setattr__(model, "url_path", aur_package_ahriman.url_path)
|
||||
object.__setattr__(model, "maintainer", aur_package_ahriman.maintainer)
|
||||
object.__setattr__(model, "submitter", aur_package_ahriman.submitter)
|
||||
|
||||
assert model == aur_package_ahriman
|
||||
|
||||
|
@ -9,6 +9,7 @@ from ahriman.core.exceptions import PackageInfoError
|
||||
from ahriman.core.util import utcnow
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
@ -22,6 +23,58 @@ def test_depends(package_python_schedule: Package) -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_depends_build(package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must return full list of packages required for build
|
||||
"""
|
||||
assert all(
|
||||
set(package_ahriman.depends_build).intersection(package.depends)
|
||||
for package in package_ahriman.packages.values()
|
||||
)
|
||||
assert all(
|
||||
set(package_ahriman.depends_build).intersection(package.make_depends)
|
||||
for package in package_ahriman.packages.values()
|
||||
)
|
||||
|
||||
assert all(
|
||||
set(package_python_schedule.depends_build).intersection(package.depends)
|
||||
for package in package_python_schedule.packages.values()
|
||||
)
|
||||
# there is no make dependencies for python-schedule
|
||||
|
||||
|
||||
def test_depends_build_with_version_and_overlap(mocker: MockerFixture, resource_path_root: Path) -> None:
|
||||
"""
|
||||
must load correct list of dependencies with version
|
||||
"""
|
||||
|
||||
srcinfo = (resource_path_root / "models" / "package_gcc10_srcinfo").read_text()
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
package_gcc10 = Package.from_build(Path("local"))
|
||||
assert package_gcc10.depends_build == {"glibc", "doxygen", "binutils", "git", "libmpc", "python", "zstd"}
|
||||
|
||||
|
||||
def test_depends_make(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return list of make dependencies
|
||||
"""
|
||||
assert all(
|
||||
set(package_ahriman.depends_make).intersection(package.make_depends)
|
||||
for package in package_ahriman.packages.values()
|
||||
)
|
||||
|
||||
|
||||
def test_depends_opt(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return list of optional dependencies
|
||||
"""
|
||||
assert all(
|
||||
set(package_ahriman.depends_opt).intersection(package.opt_depends)
|
||||
for package in package_ahriman.packages.values()
|
||||
)
|
||||
|
||||
|
||||
def test_groups(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return list of groups for each package
|
||||
@ -108,6 +161,33 @@ def test_from_build(package_ahriman: Package, mocker: MockerFixture, resource_pa
|
||||
assert package_ahriman == package
|
||||
|
||||
|
||||
def test_from_build_multiple_packages(mocker: MockerFixture, resource_path_root: Path) -> None:
|
||||
"""
|
||||
must construct package from srcinfo with dependencies per-package overrides
|
||||
"""
|
||||
srcinfo = (resource_path_root / "models" / "package_gcc10_srcinfo").read_text()
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
package = Package.from_build(Path("path"))
|
||||
assert package.packages == {
|
||||
"gcc10": PackageDescription(
|
||||
depends=["gcc10-libs=10.3.0-2", "binutils>=2.28", "libmpc", "zstd"],
|
||||
make_depends=["binutils", "doxygen", "git", "libmpc", "python"],
|
||||
opt_depends=[],
|
||||
),
|
||||
"gcc10-libs": PackageDescription(
|
||||
depends=["glibc>=2.27"],
|
||||
make_depends=["binutils", "doxygen", "git", "libmpc", "python"],
|
||||
opt_depends=[],
|
||||
),
|
||||
"gcc10-fortran": PackageDescription(
|
||||
depends=["gcc10=10.3.0-2"],
|
||||
make_depends=["binutils", "doxygen", "git", "libmpc", "python"],
|
||||
opt_depends=[],
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def test_from_build_failed(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise exception if there are errors during srcinfo load
|
||||
@ -153,37 +233,6 @@ def test_from_official(package_ahriman: Package, aur_package_ahriman: AURPackage
|
||||
assert package_ahriman.packages.keys() == package.packages.keys()
|
||||
|
||||
|
||||
def test_dependencies_failed(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise exception if there are errors during srcinfo load for dependencies
|
||||
"""
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value="")
|
||||
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
|
||||
|
||||
with pytest.raises(PackageInfoError):
|
||||
Package.dependencies(Path("path"))
|
||||
|
||||
|
||||
def test_dependencies_with_version(mocker: MockerFixture, resource_path_root: Path) -> None:
|
||||
"""
|
||||
must load correct list of dependencies with version
|
||||
"""
|
||||
srcinfo = (resource_path_root / "models" / "package_yay_srcinfo").read_text()
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
assert Package.dependencies(Path("path")) == {"git", "go", "pacman"}
|
||||
|
||||
|
||||
def test_dependencies_with_version_and_overlap(mocker: MockerFixture, resource_path_root: Path) -> None:
|
||||
"""
|
||||
must load correct list of dependencies with version
|
||||
"""
|
||||
srcinfo = (resource_path_root / "models" / "package_gcc10_srcinfo").read_text()
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
assert Package.dependencies(Path("path")) == {"glibc", "doxygen", "binutils", "git", "libmpc", "python", "zstd"}
|
||||
|
||||
|
||||
def test_supported_architectures(mocker: MockerFixture, resource_path_root: Path) -> None:
|
||||
"""
|
||||
must generate list of available architectures
|
||||
|
@ -1,8 +1,17 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
|
||||
|
||||
def test_post_init() -> None:
|
||||
"""
|
||||
must trim versions and descriptions from dependencies list
|
||||
"""
|
||||
assert PackageDescription(depends=["a=1"], make_depends=["b>=3"], opt_depends=["c: a description"]) == \
|
||||
PackageDescription(depends=["a"], make_depends=["b"], opt_depends=["c"])
|
||||
|
||||
|
||||
def test_filepath(package_description_ahriman: PackageDescription) -> None:
|
||||
"""
|
||||
must generate correct filepath if set
|
||||
@ -19,6 +28,19 @@ def test_filepath_empty(package_description_ahriman: PackageDescription) -> None
|
||||
assert package_description_ahriman.filepath is None
|
||||
|
||||
|
||||
def test_from_aur(package_description_ahriman: PackageDescription, aur_package_ahriman: AURPackage) -> None:
|
||||
"""
|
||||
must construct package description from AUR descriptor
|
||||
"""
|
||||
actual = PackageDescription.from_aur(aur_package_ahriman)
|
||||
# missing attributes
|
||||
actual.architecture = package_description_ahriman.architecture
|
||||
actual.archive_size = package_description_ahriman.archive_size
|
||||
actual.build_date = package_description_ahriman.build_date
|
||||
actual.filename = package_description_ahriman.filename
|
||||
actual.installed_size = package_description_ahriman.installed_size
|
||||
|
||||
|
||||
def test_from_json(package_description_ahriman: PackageDescription) -> None:
|
||||
"""
|
||||
must construct description from json object
|
||||
|
@ -6,21 +6,26 @@
|
||||
"devtools",
|
||||
"git",
|
||||
"pyalpm",
|
||||
"python-aur",
|
||||
"python-cerberus",
|
||||
"python-inflection",
|
||||
"python-passlib",
|
||||
"python-requests",
|
||||
"python-setuptools",
|
||||
"python-srcinfo"
|
||||
],
|
||||
"Description": "ArcH linux ReposItory MANager",
|
||||
"FirstSubmitted": 1618008285,
|
||||
"ID": 1009791,
|
||||
"ID": 1197565,
|
||||
"Keywords": [],
|
||||
"LastModified": 1640473871,
|
||||
"LastModified": 1673826351,
|
||||
"License": [
|
||||
"GPL3"
|
||||
],
|
||||
"Maintainer": "arcanis",
|
||||
"MakeDepends": [
|
||||
"python-pip"
|
||||
"python-build",
|
||||
"python-installer",
|
||||
"python-wheel"
|
||||
],
|
||||
"Name": "ahriman",
|
||||
"NumVotes": 0,
|
||||
@ -36,6 +41,7 @@
|
||||
"python-aiohttp-session",
|
||||
"python-boto3",
|
||||
"python-cryptography",
|
||||
"python-requests-unixsocket",
|
||||
"python-jinja",
|
||||
"rsync",
|
||||
"subversion"
|
||||
@ -44,11 +50,12 @@
|
||||
"PackageBase": "ahriman",
|
||||
"PackageBaseID": 165427,
|
||||
"Popularity": 0,
|
||||
"Submitter": "arcanis",
|
||||
"URL": "https://github.com/arcan1s/ahriman",
|
||||
"URLPath": "/cgit/aur.git/snapshot/ahriman.tar.gz",
|
||||
"Version": "1.7.0-1"
|
||||
"Version": "2.6.0-1"
|
||||
}
|
||||
],
|
||||
"type": "multiinfo",
|
||||
"version": 5
|
||||
}
|
||||
}
|
@ -1,35 +1,44 @@
|
||||
pkgbase = ahriman
|
||||
pkgdesc = ArcH linux ReposItory MANager
|
||||
pkgver = 1.7.0
|
||||
pkgrel = 1
|
||||
url = https://github.com/arcan1s/ahriman
|
||||
arch = any
|
||||
license = GPL3
|
||||
makedepends = python-pip
|
||||
depends = devtools
|
||||
depends = git
|
||||
depends = pyalpm
|
||||
depends = python-aur
|
||||
depends = python-passlib
|
||||
depends = python-srcinfo
|
||||
optdepends = aws-cli: sync to s3
|
||||
optdepends = breezy: -bzr packages support
|
||||
optdepends = darcs: -darcs packages support
|
||||
optdepends = gnupg: package and repository sign
|
||||
optdepends = mercurial: -hg packages support
|
||||
optdepends = python-aiohttp: web server
|
||||
optdepends = python-aiohttp-jinja2: web server
|
||||
optdepends = python-jinja: html report generation
|
||||
optdepends = python-requests: web server
|
||||
optdepends = rsync: sync by using rsync
|
||||
optdepends = subversion: -svn packages support
|
||||
backup = etc/ahriman.ini
|
||||
backup = etc/ahriman.ini.d/logging.ini
|
||||
source = https://github.com/arcan1s/ahriman/releases/download/1.7.0/ahriman-1.7.0-src.tar.xz
|
||||
source = ahriman.sysusers
|
||||
source = ahriman.tmpfiles
|
||||
sha512sums = 8acc57f937d587ca665c29092cadddbaf3ba0b80e870b80d1551e283aba8f21306f9030a26fec8c71ab5863316f5f5f061b7ddc63cdff9e6d5a885f28ef1893d
|
||||
sha512sums = 13718afec2c6786a18f0b223ef8e58dccf0688bca4cdbe203f14071f5031ed20120eb0ce38b52c76cfd6e8b6581a9c9eaa2743eb11abbaca637451a84c33f075
|
||||
sha512sums = 55b20f6da3d66e7bbf2add5d95a3b60632df121717d25a993e56e737d14f51fe063eb6f1b38bd81cc32e05db01c0c1d80aaa720c45cde87f238d8b46cdb8cbc4
|
||||
pkgdesc = ArcH linux ReposItory MANager
|
||||
pkgver = 2.6.0
|
||||
pkgrel = 1
|
||||
url = https://github.com/arcan1s/ahriman
|
||||
arch = any
|
||||
license = GPL3
|
||||
makedepends = python-build
|
||||
makedepends = python-installer
|
||||
makedepends = python-wheel
|
||||
depends = devtools
|
||||
depends = git
|
||||
depends = pyalpm
|
||||
depends = python-cerberus
|
||||
depends = python-inflection
|
||||
depends = python-passlib
|
||||
depends = python-requests
|
||||
depends = python-setuptools
|
||||
depends = python-srcinfo
|
||||
optdepends = breezy: -bzr packages support
|
||||
optdepends = darcs: -darcs packages support
|
||||
optdepends = mercurial: -hg packages support
|
||||
optdepends = python-aioauth-client: web server with OAuth2 authorization
|
||||
optdepends = python-aiohttp: web server
|
||||
optdepends = python-aiohttp-debugtoolbar: web server with enabled debug panel
|
||||
optdepends = python-aiohttp-jinja2: web server
|
||||
optdepends = python-aiohttp-security: web server with authorization
|
||||
optdepends = python-aiohttp-session: web server with authorization
|
||||
optdepends = python-boto3: sync to s3
|
||||
optdepends = python-cryptography: web server with authorization
|
||||
optdepends = python-requests-unixsocket: client report to web server by unix socket
|
||||
optdepends = python-jinja: html report generation
|
||||
optdepends = rsync: sync by using rsync
|
||||
optdepends = subversion: -svn packages support
|
||||
backup = etc/ahriman.ini
|
||||
backup = etc/ahriman.ini.d/logging.ini
|
||||
source = https://github.com/arcan1s/ahriman/releases/download/2.6.0/ahriman-2.6.0-src.tar.xz
|
||||
source = ahriman.sysusers
|
||||
source = ahriman.tmpfiles
|
||||
sha512sums = ec1f64e463455761d72be7f7b8b51b3b4424685c96a2d5eee6afa1c93780c8d7f8a39487a2f2f3bd83d2b58a93279e1392a965a4b905795e58ca686fb21123a1
|
||||
sha512sums = 53d37efec812afebf86281716259f9ea78a307b83897166c72777251c3eebcb587ecee375d907514781fb2a5c808cbb24ef9f3f244f12740155d0603bf213131
|
||||
sha512sums = 62b2eccc352d33853ef243c9cddd63663014aa97b87242f1b5bc5099a7dbd69ff3821f24ffc58e1b7f2387bd4e9e9712cc4c67f661b1724ad99cdf09b3717794
|
||||
|
||||
pkgname = ahriman
|
||||
pkgname = ahriman
|
Reference in New Issue
Block a user