feat: add package copy subcommand

This commit is contained in:
2024-09-27 17:23:04 +03:00
parent 7bc4810377
commit 1e7d4daf18
10 changed files with 300 additions and 12 deletions

View File

@ -1,5 +1,6 @@
import pytest
from pathlib import Path
from pytest_mock import MockerFixture
from unittest.mock import call as MockCall
@ -213,6 +214,9 @@ def test_updates_all(application_repository: ApplicationRepository, package_ahri
"""
must get updates for all
"""
path = Path("local")
mocker.patch("ahriman.core.repository.package_info.PackageInfo.packages_built", return_value=[path])
updates_built_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives")
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur",
return_value=[package_ahriman])
updates_local_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_local")
@ -220,6 +224,7 @@ def test_updates_all(application_repository: ApplicationRepository, package_ahri
updates_deps_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_dependencies")
application_repository.updates([], aur=True, local=True, manual=True, vcs=True, check_files=True)
updates_built_mock.assert_called_once_with([path])
updates_aur_mock.assert_called_once_with([], vcs=True)
updates_local_mock.assert_called_once_with(vcs=True)
updates_manual_mock.assert_called_once_with()
@ -230,12 +235,16 @@ def test_updates_disabled(application_repository: ApplicationRepository, mocker:
"""
must get updates without anything
"""
path = Path("local")
mocker.patch("ahriman.core.repository.package_info.PackageInfo.packages_built", return_value=[path])
updates_built_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives")
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur")
updates_local_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_local")
updates_manual_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_manual")
updates_deps_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_dependencies")
application_repository.updates([], aur=False, local=False, manual=False, vcs=True, check_files=False)
updates_built_mock.assert_called_once_with([path])
updates_aur_mock.assert_not_called()
updates_local_mock.assert_not_called()
updates_manual_mock.assert_not_called()
@ -246,12 +255,16 @@ def test_updates_no_aur(application_repository: ApplicationRepository, mocker: M
"""
must get updates without aur
"""
path = Path("local")
mocker.patch("ahriman.core.repository.package_info.PackageInfo.packages_built", return_value=[path])
updates_built_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives")
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur")
updates_local_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_local")
updates_manual_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_manual")
updates_deps_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_dependencies")
application_repository.updates([], aur=False, local=True, manual=True, vcs=True, check_files=True)
updates_built_mock.assert_called_once_with([path])
updates_aur_mock.assert_not_called()
updates_local_mock.assert_called_once_with(vcs=True)
updates_manual_mock.assert_called_once_with()
@ -262,12 +275,16 @@ def test_updates_no_local(application_repository: ApplicationRepository, mocker:
"""
must get updates without local packages
"""
path = Path("local")
mocker.patch("ahriman.core.repository.package_info.PackageInfo.packages_built", return_value=[path])
updates_built_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives")
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur")
updates_local_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_local")
updates_manual_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_manual")
updates_deps_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_dependencies")
application_repository.updates([], aur=True, local=False, manual=True, vcs=True, check_files=True)
updates_built_mock.assert_called_once_with([path])
updates_aur_mock.assert_called_once_with([], vcs=True)
updates_local_mock.assert_not_called()
updates_manual_mock.assert_called_once_with()
@ -278,12 +295,16 @@ def test_updates_no_manual(application_repository: ApplicationRepository, mocker
"""
must get updates without manual
"""
path = Path("local")
mocker.patch("ahriman.core.repository.package_info.PackageInfo.packages_built", return_value=[path])
updates_built_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives")
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur")
updates_local_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_local")
updates_manual_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_manual")
updates_deps_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_dependencies")
application_repository.updates([], aur=True, local=True, manual=False, vcs=True, check_files=True)
updates_built_mock.assert_called_once_with([path])
updates_aur_mock.assert_called_once_with([], vcs=True)
updates_local_mock.assert_called_once_with(vcs=True)
updates_manual_mock.assert_not_called()
@ -294,12 +315,16 @@ def test_updates_no_vcs(application_repository: ApplicationRepository, mocker: M
"""
must get updates without VCS
"""
path = Path("local")
mocker.patch("ahriman.core.repository.package_info.PackageInfo.packages_built", return_value=[path])
updates_built_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives")
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur")
updates_local_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_local")
updates_manual_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_manual")
updates_deps_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_dependencies")
application_repository.updates([], aur=True, local=True, manual=True, vcs=False, check_files=True)
updates_built_mock.assert_called_once_with([path])
updates_aur_mock.assert_called_once_with([], vcs=False)
updates_local_mock.assert_called_once_with(vcs=False)
updates_manual_mock.assert_called_once_with()
@ -310,12 +335,16 @@ def test_updates_no_check_files(application_repository: ApplicationRepository, m
"""
must get updates without checking broken links
"""
path = Path("local")
mocker.patch("ahriman.core.repository.package_info.PackageInfo.packages_built", return_value=[path])
updates_built_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives")
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur")
updates_local_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_local")
updates_manual_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_manual")
updates_deps_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_dependencies")
application_repository.updates([], aur=True, local=True, manual=True, vcs=True, check_files=False)
updates_built_mock.assert_called_once_with([path])
updates_aur_mock.assert_called_once_with([], vcs=True)
updates_local_mock.assert_called_once_with(vcs=True)
updates_manual_mock.assert_called_once_with()
@ -326,12 +355,16 @@ def test_updates_with_filter(application_repository: ApplicationRepository, mock
"""
must get updates with filter
"""
path = Path("local")
mocker.patch("ahriman.core.repository.package_info.PackageInfo.packages_built", return_value=[path])
updates_built_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives")
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur")
updates_local_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_local")
updates_manual_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_manual")
updates_deps_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_dependencies")
application_repository.updates(["filter"], aur=True, local=True, manual=True, vcs=True, check_files=True)
updates_built_mock.assert_called_once_with([path])
updates_aur_mock.assert_called_once_with(["filter"], vcs=True)
updates_local_mock.assert_called_once_with(vcs=True)
updates_manual_mock.assert_called_once_with()

View File

@ -0,0 +1,105 @@
import argparse
import pytest
from pytest_mock import MockerFixture
from ahriman.application.application import Application
from ahriman.application.handlers import Copy
from ahriman.core.configuration import Configuration
from ahriman.core.repository import Repository
from ahriman.models.build_status import BuildStatusEnum
from ahriman.models.package import Package
from ahriman.models.package_source import PackageSource
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
"""
default arguments for these test cases
Args:
args(argparse.Namespace): command line arguments fixture
Returns:
argparse.Namespace: generated arguments for these test cases
"""
args.source = "source"
args.package = ["ahriman"]
args.exit_code = False
args.remove = False
return args
def test_run(args: argparse.Namespace, configuration: Configuration, repository: Repository,
package_ahriman: Package, mocker: MockerFixture) -> None:
"""
must run command
"""
args = _default_args(args)
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
mocker.patch("ahriman.core.repository.Repository.packages", return_value=[package_ahriman])
application_mock = mocker.patch("ahriman.application.handlers.Copy.copy_package")
update_mock = mocker.patch("ahriman.application.application.Application.update")
remove_mock = mocker.patch("ahriman.application.application.Application.remove")
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
_, repository_id = configuration.check_loaded()
Copy.run(args, repository_id, configuration, report=False)
application_mock.assert_called_once_with(package_ahriman, pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
update_mock.assert_called_once_with([])
remove_mock.assert_not_called()
on_start_mock.assert_called_once_with()
def test_run_remove(args: argparse.Namespace, configuration: Configuration, repository: Repository,
package_ahriman: Package, mocker: MockerFixture) -> None:
"""
must run command and remove packages afterwards
"""
args = _default_args(args)
args.remove = True
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
mocker.patch("ahriman.core.repository.Repository.packages", return_value=[package_ahriman])
mocker.patch("ahriman.application.handlers.Copy.copy_package")
mocker.patch("ahriman.application.application.Application.update")
remove_mock = mocker.patch("ahriman.application.application.Application.remove")
_, repository_id = configuration.check_loaded()
Copy.run(args, repository_id, configuration, report=False)
remove_mock.assert_called_once_with(args.package)
def test_run_empty_exception(args: argparse.Namespace, configuration: Configuration, repository: Repository,
mocker: MockerFixture) -> None:
"""
must raise ExitCode exception on empty result
"""
args = _default_args(args)
args.exit_code = True
mocker.patch("ahriman.core.repository.Repository.packages", return_value=[])
mocker.patch("ahriman.application.application.Application.update")
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_status")
_, repository_id = configuration.check_loaded()
Copy.run(args, repository_id, configuration, report=False)
check_mock.assert_called_once_with(True, [])
def test_copy_package(package_ahriman: Package, application: Application, mocker: MockerFixture) -> None:
"""
must copy package between repositories and its metadata
"""
add_mock = mocker.patch("ahriman.application.application.Application.add")
changes_get_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get")
changes_update_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_update")
deps_get_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_dependencies_get")
deps_update_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_dependencies_update")
package_update_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_update")
path = application.repository.paths.repository / package_ahriman.packages[package_ahriman.base].filename
Copy.copy_package(package_ahriman, application, application)
add_mock.assert_called_once_with([str(path)], PackageSource.Archive)
changes_get_mock.assert_called_once_with(package_ahriman.base)
changes_update_mock.assert_called_once_with(package_ahriman.base, changes_get_mock.return_value)
deps_get_mock.assert_called_once_with(package_ahriman.base)
deps_update_mock.assert_called_once_with(package_ahriman.base, deps_get_mock.return_value)
package_update_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.Pending)

View File

@ -309,6 +309,26 @@ def test_subparsers_package_changes_remove_package_changes(parser: argparse.Argu
assert dir(args) == dir(reference_args)
def test_subparsers_package_copy_option_architecture(parser: argparse.ArgumentParser) -> None:
"""
package-copy command must correctly parse architecture list
"""
args = parser.parse_args(["package-copy", "source", "ahriman"])
assert args.architecture is None
args = parser.parse_args(["-a", "x86_64", "package-copy", "source", "ahriman"])
assert args.architecture == "x86_64"
def test_subparsers_package_copy_option_repository(parser: argparse.ArgumentParser) -> None:
"""
package-copy command must correctly parse repository list
"""
args = parser.parse_args(["package-copy", "source", "ahriman"])
assert args.repository is None
args = parser.parse_args(["-r", "repo", "package-copy", "source", "ahriman"])
assert args.repository == "repo"
def test_subparsers_package_remove_option_architecture(parser: argparse.ArgumentParser) -> None:
"""
package-remove command must correctly parse architecture list