mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
Add gitremote triggers (#68)
* add gitremote pull trigger * add push gitremote trigger * docs update
This commit is contained in:
@ -5,16 +5,6 @@ from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_finalize(application: Application, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must report and sync at the last
|
||||
"""
|
||||
triggers_mock = mocker.patch("ahriman.core.repository.Repository.process_triggers")
|
||||
|
||||
application._finalize(Result())
|
||||
triggers_mock.assert_called_once_with(Result())
|
||||
|
||||
|
||||
def test_known_packages(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return not empty list of known packages
|
||||
@ -23,3 +13,34 @@ def test_known_packages(application: Application, package_ahriman: Package, mock
|
||||
packages = application._known_packages()
|
||||
assert len(packages) > 1
|
||||
assert package_ahriman.base in packages
|
||||
|
||||
|
||||
def test_on_result(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call on_result trigger function
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.Repository.packages", return_value=[package_ahriman])
|
||||
triggers_mock = mocker.patch("ahriman.core.triggers.TriggerLoader.on_result")
|
||||
|
||||
application.on_result(Result())
|
||||
triggers_mock.assert_called_once_with(Result(), [package_ahriman])
|
||||
|
||||
|
||||
def test_on_start(application: Application, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call on_start trigger function
|
||||
"""
|
||||
triggers_mock = mocker.patch("ahriman.core.triggers.TriggerLoader.on_start")
|
||||
|
||||
application.on_start()
|
||||
triggers_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_on_stop(application: Application, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call on_stop trigger function
|
||||
"""
|
||||
triggers_mock = mocker.patch("ahriman.core.triggers.TriggerLoader.on_stop")
|
||||
|
||||
application.on_stop()
|
||||
triggers_mock.assert_called_once_with()
|
||||
|
@ -11,12 +11,12 @@ from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_finalize(application_packages: ApplicationPackages) -> None:
|
||||
def test_on_result(application_packages: ApplicationPackages) -> None:
|
||||
"""
|
||||
must raise NotImplemented for missing finalize method
|
||||
"""
|
||||
with pytest.raises(NotImplementedError):
|
||||
application_packages._finalize([])
|
||||
application_packages.on_result(Result())
|
||||
|
||||
|
||||
def test_known_packages(application_packages: ApplicationPackages) -> None:
|
||||
@ -242,8 +242,8 @@ def test_remove(application_packages: ApplicationPackages, mocker: MockerFixture
|
||||
must remove package
|
||||
"""
|
||||
executor_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_remove")
|
||||
finalize_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._finalize")
|
||||
on_result_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages.on_result")
|
||||
|
||||
application_packages.remove([])
|
||||
executor_mock.assert_called_once_with([])
|
||||
finalize_mock.assert_called_once_with(Result())
|
||||
on_result_mock.assert_called_once_with(Result())
|
||||
|
@ -9,12 +9,12 @@ from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_finalize(application_repository: ApplicationRepository) -> None:
|
||||
def test_on_result(application_repository: ApplicationRepository) -> None:
|
||||
"""
|
||||
must raise NotImplemented for missing finalize method
|
||||
"""
|
||||
with pytest.raises(NotImplementedError):
|
||||
application_repository._finalize(Result())
|
||||
application_repository.on_result(Result())
|
||||
|
||||
|
||||
def test_clean_cache(application_repository: ApplicationRepository, mocker: MockerFixture) -> None:
|
||||
@ -63,8 +63,8 @@ def test_sign(application_repository: ApplicationRepository, package_ahriman: Pa
|
||||
copy_mock = mocker.patch("shutil.copy")
|
||||
update_mock = mocker.patch("ahriman.application.application.application_repository.ApplicationRepository.update")
|
||||
sign_repository_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process_sign_repository")
|
||||
finalize_mock = mocker.patch(
|
||||
"ahriman.application.application.application_repository.ApplicationRepository._finalize")
|
||||
on_result_mock = mocker.patch(
|
||||
"ahriman.application.application.application_repository.ApplicationRepository.on_result")
|
||||
|
||||
application_repository.sign([])
|
||||
copy_mock.assert_has_calls([
|
||||
@ -73,7 +73,7 @@ def test_sign(application_repository: ApplicationRepository, package_ahriman: Pa
|
||||
])
|
||||
update_mock.assert_called_once_with([])
|
||||
sign_repository_mock.assert_called_once_with(application_repository.repository.repo.repo_path)
|
||||
finalize_mock.assert_called_once_with(Result())
|
||||
on_result_mock.assert_called_once_with(Result())
|
||||
|
||||
|
||||
def test_sign_skip(application_repository: ApplicationRepository, package_ahriman: Package,
|
||||
@ -84,7 +84,7 @@ def test_sign_skip(application_repository: ApplicationRepository, package_ahrima
|
||||
package_ahriman.packages[package_ahriman.base].filename = None
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.application.application.application_repository.ApplicationRepository.update")
|
||||
mocker.patch("ahriman.application.application.application_repository.ApplicationRepository._finalize")
|
||||
mocker.patch("ahriman.application.application.application_repository.ApplicationRepository.on_result")
|
||||
|
||||
application_repository.sign([])
|
||||
|
||||
@ -99,8 +99,8 @@ def test_sign_specific(application_repository: ApplicationRepository, package_ah
|
||||
copy_mock = mocker.patch("shutil.copy")
|
||||
update_mock = mocker.patch("ahriman.application.application.application_repository.ApplicationRepository.update")
|
||||
sign_repository_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process_sign_repository")
|
||||
finalize_mock = mocker.patch(
|
||||
"ahriman.application.application.application_repository.ApplicationRepository._finalize")
|
||||
on_result_mock = mocker.patch(
|
||||
"ahriman.application.application.application_repository.ApplicationRepository.on_result")
|
||||
|
||||
filename = package_ahriman.packages[package_ahriman.base].filepath
|
||||
application_repository.sign([package_ahriman.base])
|
||||
@ -109,7 +109,7 @@ def test_sign_specific(application_repository: ApplicationRepository, package_ah
|
||||
application_repository.repository.paths.packages / filename.name)
|
||||
update_mock.assert_called_once_with([])
|
||||
sign_repository_mock.assert_called_once_with(application_repository.repository.repo.repo_path)
|
||||
finalize_mock.assert_called_once_with(Result())
|
||||
on_result_mock.assert_called_once_with(Result())
|
||||
|
||||
|
||||
def test_unknown_no_aur(application_repository: ApplicationRepository, package_ahriman: Package,
|
||||
@ -163,13 +163,13 @@ def test_update(application_repository: ApplicationRepository, package_ahriman:
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_built", return_value=paths)
|
||||
build_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_build", return_value=result)
|
||||
update_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_update", return_value=result)
|
||||
finalize_mock = mocker.patch(
|
||||
"ahriman.application.application.application_repository.ApplicationRepository._finalize")
|
||||
on_result_mock = mocker.patch(
|
||||
"ahriman.application.application.application_repository.ApplicationRepository.on_result")
|
||||
|
||||
application_repository.update([package_ahriman])
|
||||
build_mock.assert_called_once_with([package_ahriman])
|
||||
update_mock.assert_has_calls([mock.call(paths), mock.call(paths)])
|
||||
finalize_mock.assert_has_calls([mock.call(result), mock.call(result)])
|
||||
on_result_mock.assert_has_calls([mock.call(result), mock.call(result)])
|
||||
|
||||
|
||||
def test_update_empty(application_repository: ApplicationRepository, package_ahriman: Package,
|
||||
|
@ -35,9 +35,11 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
args = _default_args(args)
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.add")
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
Add.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with(args.package, args.source, args.without_dependencies)
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_run_with_updates(args: argparse.Namespace, configuration: Configuration,
|
||||
|
@ -30,6 +30,8 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
args = _default_args(args)
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.clean")
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
Clean.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with(False, False, False, False)
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
@ -36,9 +36,11 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
args.action = Action.Update
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
application_mock = mocker.patch("ahriman.application.handlers.Patch.patch_set_create")
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
Patch.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), Path(args.package), args.track)
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_run_list(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
|
@ -41,11 +41,13 @@ def test_run(args: argparse.Namespace, package_ahriman: Package,
|
||||
return_value=[package_ahriman])
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.update", return_value=result)
|
||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
Rebuild.run(args, "x86_64", configuration, True, False)
|
||||
application_packages_mock.assert_called_once_with(None)
|
||||
application_mock.assert_called_once_with([package_ahriman])
|
||||
check_mock.assert_has_calls([mock.call(False, False), mock.call(False, False)])
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_run_extract_packages(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
|
@ -27,6 +27,8 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
args = _default_args(args)
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.remove")
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
Remove.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with([])
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
@ -32,10 +32,12 @@ def test_run(args: argparse.Namespace, package_ahriman: Package,
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.unknown",
|
||||
return_value=[package_ahriman])
|
||||
remove_mock = mocker.patch("ahriman.application.application.Application.remove")
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
RemoveUnknown.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with()
|
||||
remove_mock.assert_called_once_with([package_ahriman])
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, package_ahriman: Package,
|
||||
|
@ -28,10 +28,12 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
"""
|
||||
args = _default_args(args)
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
application_mock = mocker.patch("ahriman.core.repository.Repository.process_triggers")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.on_result")
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
Triggers.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with(Result())
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_run_trigger(args: argparse.Namespace, configuration: Configuration, package_ahriman: Package,
|
||||
|
@ -43,12 +43,14 @@ def test_run(args: argparse.Namespace, package_ahriman: Package,
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.update", return_value=result)
|
||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
Update.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with([package_ahriman])
|
||||
updates_mock.assert_called_once_with(args.package, args.no_aur, args.no_local, args.no_manual, args.no_vcs,
|
||||
pytest.helpers.anyvar(int))
|
||||
check_mock.assert_has_calls([mock.call(False, False), mock.call(False, False)])
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_run_empty_exception(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
|
@ -223,6 +223,23 @@ def test_patch_create_with_newline(mocker: MockerFixture) -> None:
|
||||
assert Sources.patch_create(Path("local"), "glob").endswith("\n")
|
||||
|
||||
|
||||
def test_push(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must correctly push files to remote repository
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.add")
|
||||
commit_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.commit")
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
Sources.push(Path("local"), package_ahriman.remote, "glob")
|
||||
add_mock.assert_called_once_with(local, "glob")
|
||||
commit_mock.assert_called_once_with(local)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "push", package_ahriman.remote.git_url, package_ahriman.remote.branch,
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_add(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must add files to git
|
||||
@ -249,6 +266,35 @@ def test_add_skip(sources: Sources, mocker: MockerFixture) -> None:
|
||||
check_output_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_commit(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must commit changes
|
||||
"""
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
commit_message = "Commit message"
|
||||
sources.commit(local, commit_message=commit_message)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "commit", "--all", "--message", commit_message,
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int)
|
||||
)
|
||||
|
||||
|
||||
def test_commit_autogenerated(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must commit changes with autogenerated commit message
|
||||
"""
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
sources.commit(Path("local"))
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "commit", "--all", "--message", pytest.helpers.anyvar(str, strict=True),
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int)
|
||||
)
|
||||
|
||||
|
||||
def test_diff(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must calculate diff
|
||||
|
58
tests/ahriman/core/gitremote/test_remote_pull_trigger.py
Normal file
58
tests/ahriman/core/gitremote/test_remote_pull_trigger.py
Normal file
@ -0,0 +1,58 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.gitremote import RemotePullTrigger
|
||||
|
||||
|
||||
def test_on_start(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must clone repo on start
|
||||
"""
|
||||
clone_mock = mocker.patch("ahriman.core.gitremote.RemotePullTrigger.repo_clone")
|
||||
trigger = RemotePullTrigger("x86_64", configuration)
|
||||
|
||||
trigger.on_start()
|
||||
clone_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_repo_clone(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must clone repository locally and copy its content
|
||||
"""
|
||||
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
copy_mock = mocker.patch("ahriman.core.gitremote.RemotePullTrigger.repo_copy")
|
||||
trigger = RemotePullTrigger("x86_64", configuration)
|
||||
|
||||
trigger.repo_clone()
|
||||
fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), trigger.remote_source)
|
||||
copy_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_repo_copy(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must copy repository tree from temporary directory to the local cache
|
||||
"""
|
||||
mocker.patch("ahriman.core.gitremote.remote_pull_trigger.walk", return_value=[
|
||||
Path("local") / "package1" / "PKGBUILD",
|
||||
Path("local") / "package1" / ".SRCINFO",
|
||||
Path("local") / "package2" / ".SRCINFO",
|
||||
Path("local") / "package3" / "PKGBUILD",
|
||||
Path("local") / "package3" / ".SRCINFO",
|
||||
])
|
||||
copytree_mock = mocker.patch("shutil.copytree")
|
||||
init_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.init")
|
||||
trigger = RemotePullTrigger("x86_64", configuration)
|
||||
|
||||
trigger.repo_copy(Path("local"))
|
||||
copytree_mock.assert_has_calls([
|
||||
mock.call(Path("local") / "package1", configuration.repository_paths.cache_for("package1"), dirs_exist_ok=True),
|
||||
mock.call(Path("local") / "package3", configuration.repository_paths.cache_for("package3"), dirs_exist_ok=True),
|
||||
])
|
||||
init_mock.assert_has_calls([
|
||||
mock.call(configuration.repository_paths.cache_for("package1")),
|
||||
mock.call(configuration.repository_paths.cache_for("package3")),
|
||||
])
|
56
tests/ahriman/core/gitremote/test_remote_push_trigger.py
Normal file
56
tests/ahriman/core/gitremote/test_remote_push_trigger.py
Normal file
@ -0,0 +1,56 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.gitremote import RemotePushTrigger
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_package_update(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must update single package
|
||||
"""
|
||||
rmtree_mock = mocker.patch("shutil.rmtree")
|
||||
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
copytree_mock = mocker.patch("shutil.copytree")
|
||||
|
||||
local = Path("local")
|
||||
RemotePushTrigger.package_update(package_ahriman, local)
|
||||
rmtree_mock.assert_has_calls([
|
||||
mock.call(local / package_ahriman.base, ignore_errors=True),
|
||||
mock.call(pytest.helpers.anyvar(int), onerror=pytest.helpers.anyvar(int)), # removal of the TemporaryDirectory
|
||||
mock.call(local / package_ahriman.base / ".git", ignore_errors=True),
|
||||
])
|
||||
fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), package_ahriman.remote)
|
||||
copytree_mock.assert_called_once_with(pytest.helpers.anyvar(int), local / package_ahriman.base)
|
||||
|
||||
|
||||
def test_packages_update(result: Result, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate packages update
|
||||
"""
|
||||
update_mock = mocker.patch("ahriman.core.gitremote.RemotePushTrigger.package_update",
|
||||
return_value=[package_ahriman.base])
|
||||
|
||||
local = Path("local")
|
||||
assert list(RemotePushTrigger.packages_update(result, local))
|
||||
update_mock.assert_called_once_with(package_ahriman, local)
|
||||
|
||||
|
||||
def test_on_result(configuration: Configuration, result: Result, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must push changes on result
|
||||
"""
|
||||
mocker.patch("ahriman.core.gitremote.RemotePushTrigger.packages_update", return_value=[package_ahriman.base])
|
||||
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
push_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.push")
|
||||
trigger = RemotePushTrigger("x86_64", configuration)
|
||||
|
||||
trigger.on_result(result, [package_ahriman])
|
||||
fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), trigger.remote_source)
|
||||
push_mock.assert_called_once_with(pytest.helpers.anyvar(int), trigger.remote_source, package_ahriman.base)
|
@ -4,7 +4,7 @@ from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import ReportFailed
|
||||
from ahriman.core.report import Report
|
||||
from ahriman.core.report.report import Report
|
||||
from ahriman.models.report_settings import ReportSettings
|
||||
from ahriman.models.result import Result
|
||||
|
||||
@ -23,7 +23,7 @@ def test_report_dummy(configuration: Configuration, result: Result, mocker: Mock
|
||||
must construct dummy report class
|
||||
"""
|
||||
mocker.patch("ahriman.models.report_settings.ReportSettings.from_option", return_value=ReportSettings.Disabled)
|
||||
report_mock = mocker.patch("ahriman.core.report.Report.generate")
|
||||
report_mock = mocker.patch("ahriman.core.report.report.Report.generate")
|
||||
Report.load("x86_64", configuration, "disabled").run(result, [])
|
||||
report_mock.assert_called_once_with([], result)
|
||||
|
||||
|
@ -10,7 +10,7 @@ def test_on_result(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
must run report for specified targets
|
||||
"""
|
||||
configuration.set_option("report", "target", "email")
|
||||
run_mock = mocker.patch("ahriman.core.report.Report.run")
|
||||
run_mock = mocker.patch("ahriman.core.report.report.Report.run")
|
||||
|
||||
trigger = ReportTrigger("x86_64", configuration)
|
||||
trigger.on_result(Result(), [])
|
||||
|
@ -4,10 +4,8 @@ from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.report import Report
|
||||
from ahriman.core.repository.executor import Executor
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_load_archives(executor: Executor) -> None:
|
||||
@ -144,17 +142,6 @@ def test_process_remove_nothing(executor: Executor, package_ahriman: Package, pa
|
||||
repo_remove_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_process_triggers(executor: Executor, package_ahriman: Package, result: Result, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process report
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.executor.Executor.packages", return_value=[package_ahriman])
|
||||
triggers_mock = mocker.patch("ahriman.core.triggers.TriggerLoader.on_result")
|
||||
|
||||
executor.process_triggers(result)
|
||||
triggers_mock.assert_called_once_with(result, [package_ahriman])
|
||||
|
||||
|
||||
def test_process_update(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run update process
|
||||
|
@ -10,19 +10,6 @@ from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_init_at_exit(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call on_start on init and on_stop on exit
|
||||
"""
|
||||
on_start_mock = mocker.patch("ahriman.core.triggers.trigger_loader.TriggerLoader.on_start")
|
||||
on_stop_mock = mocker.patch("ahriman.core.triggers.trigger_loader.TriggerLoader.on_stop")
|
||||
|
||||
trigger_loader = TriggerLoader("x86_64", configuration)
|
||||
on_start_mock.assert_called_once_with()
|
||||
del trigger_loader
|
||||
on_stop_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_load_trigger_package(trigger_loader: TriggerLoader) -> None:
|
||||
"""
|
||||
must load trigger from package
|
||||
@ -123,10 +110,34 @@ def test_on_start(trigger_loader: TriggerLoader, package_ahriman: Package, mocke
|
||||
report_mock = mocker.patch("ahriman.core.report.ReportTrigger.on_start")
|
||||
|
||||
trigger_loader.on_start()
|
||||
assert trigger_loader._on_stop_requested
|
||||
report_mock.assert_called_once_with()
|
||||
upload_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_on_stop_with_on_start(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call on_stop on exit if on_start was called
|
||||
"""
|
||||
on_stop_mock = mocker.patch("ahriman.core.triggers.trigger_loader.TriggerLoader.on_stop")
|
||||
|
||||
trigger_loader = TriggerLoader("x86_64", configuration)
|
||||
trigger_loader.on_start()
|
||||
del trigger_loader
|
||||
on_stop_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_on_stop_without_on_start(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call not on_stop on exit if on_start wasn't called
|
||||
"""
|
||||
on_stop_mock = mocker.patch("ahriman.core.triggers.trigger_loader.TriggerLoader.on_stop")
|
||||
|
||||
trigger_loader = TriggerLoader("x86_64", configuration)
|
||||
del trigger_loader
|
||||
on_stop_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_on_stop(trigger_loader: TriggerLoader, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run triggers on stop
|
||||
|
@ -5,7 +5,7 @@ from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import SyncFailed
|
||||
from ahriman.core.upload import Upload
|
||||
from ahriman.core.upload.upload import Upload
|
||||
from ahriman.models.upload_settings import UploadSettings
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ def test_report_dummy(configuration: Configuration, mocker: MockerFixture) -> No
|
||||
must construct dummy upload class
|
||||
"""
|
||||
mocker.patch("ahriman.models.upload_settings.UploadSettings.from_option", return_value=UploadSettings.Disabled)
|
||||
upload_mock = mocker.patch("ahriman.core.upload.Upload.sync")
|
||||
upload_mock = mocker.patch("ahriman.core.upload.upload.Upload.sync")
|
||||
Upload.load("x86_64", configuration, "disabled").run(Path("path"), [])
|
||||
upload_mock.assert_called_once_with(Path("path"), [])
|
||||
|
||||
|
@ -10,7 +10,7 @@ def test_on_result(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
must run report for specified targets
|
||||
"""
|
||||
configuration.set_option("upload", "target", "rsync")
|
||||
run_mock = mocker.patch("ahriman.core.upload.Upload.run")
|
||||
run_mock = mocker.patch("ahriman.core.upload.upload.Upload.run")
|
||||
|
||||
trigger = UploadTrigger("x86_64", configuration)
|
||||
trigger.on_result(Result(), [])
|
||||
|
@ -31,6 +31,10 @@ root = ../../../
|
||||
[sign]
|
||||
target =
|
||||
|
||||
[gitremote]
|
||||
pull_url = https://github.com/arcan1s/repository.git
|
||||
push_url = https://github.com/arcan1s/repository.git
|
||||
|
||||
[report]
|
||||
target =
|
||||
|
||||
|
Reference in New Issue
Block a user