mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-11-16 21:43:41 +00:00
add archive trigger
This commit is contained in:
@ -4,6 +4,7 @@ from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.alpm.repo import Repo
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
@ -56,21 +57,37 @@ def test_repo_init(repo: Repo, mocker: MockerFixture) -> None:
|
||||
assert check_output_mock.call_args[0][0] == "repo-add"
|
||||
|
||||
|
||||
def test_repo_remove(repo: Repo, mocker: MockerFixture) -> None:
|
||||
def test_repo_remove(repo: Repo, package_ahriman: Package,mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call repo-remove on package addition
|
||||
must call repo-remove on package removal
|
||||
"""
|
||||
filepath = package_ahriman.packages[package_ahriman.base].filepath
|
||||
mocker.patch("pathlib.Path.glob", return_value=[])
|
||||
check_output_mock = mocker.patch("ahriman.core.alpm.repo.check_output")
|
||||
|
||||
repo.remove("package", Path("package.pkg.tar.xz"))
|
||||
repo.remove(package_ahriman.base, filepath)
|
||||
check_output_mock.assert_called_once() # it will be checked later
|
||||
assert check_output_mock.call_args[0][0] == "repo-remove"
|
||||
assert package_ahriman.base in check_output_mock.call_args[0]
|
||||
|
||||
|
||||
def test_repo_remove_guess_package(repo: Repo, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call repo-remove on package removal if no package name set
|
||||
"""
|
||||
filepath = package_ahriman.packages[package_ahriman.base].filepath
|
||||
mocker.patch("pathlib.Path.glob", return_value=[])
|
||||
check_output_mock = mocker.patch("ahriman.core.alpm.repo.check_output")
|
||||
|
||||
repo.remove(None, filepath)
|
||||
check_output_mock.assert_called_once() # it will be checked later
|
||||
assert check_output_mock.call_args[0][0] == "repo-remove"
|
||||
assert package_ahriman.base in check_output_mock.call_args[0]
|
||||
|
||||
|
||||
def test_repo_remove_fail_no_file(repo: Repo, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must fail on missing file
|
||||
must fail removal on missing file
|
||||
"""
|
||||
mocker.patch("pathlib.Path.glob", return_value=[Path("package.pkg.tar.xz")])
|
||||
mocker.patch("pathlib.Path.unlink", side_effect=FileNotFoundError)
|
||||
|
||||
25
tests/ahriman/core/archive/conftest.py
Normal file
25
tests/ahriman/core/archive/conftest.py
Normal file
@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.archive import ArchiveTrigger
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.sign.gpg import GPG
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def archive_trigger(configuration: Configuration, gpg: GPG, mocker: MockerFixture) -> ArchiveTrigger:
|
||||
"""
|
||||
archive trigger fixture
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration fixture
|
||||
gpg(GPG): GPG fixture
|
||||
mocker(MockerFixture): mocker object
|
||||
|
||||
Returns:
|
||||
ArchiveTrigger: archive trigger test instance
|
||||
"""
|
||||
mocker.patch("ahriman.core._Context.get", return_value=GPG)
|
||||
_, repository_id = configuration.check_loaded()
|
||||
return ArchiveTrigger(repository_id, configuration)
|
||||
32
tests/ahriman/core/archive/test_archive_trigger.py
Normal file
32
tests/ahriman/core/archive/test_archive_trigger.py
Normal file
@ -0,0 +1,32 @@
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.archive import ArchiveTrigger
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_on_result(archive_trigger: ArchiveTrigger, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create symlinks for actual repository
|
||||
"""
|
||||
symlinks_mock = mocker.patch("ahriman.core.archive.archive_tree.ArchiveTree.symlinks_create")
|
||||
archive_trigger.on_result(Result(), [package_ahriman])
|
||||
symlinks_mock.assert_called_once_with([package_ahriman])
|
||||
|
||||
|
||||
def test_on_start(archive_trigger: ArchiveTrigger, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create repository tree on load
|
||||
"""
|
||||
tree_mock = mocker.patch("ahriman.core.archive.archive_tree.ArchiveTree.tree_create")
|
||||
archive_trigger.on_start()
|
||||
tree_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_on_stop(archive_trigger: ArchiveTrigger, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create repository tree on load
|
||||
"""
|
||||
symlinks_mock = mocker.patch("ahriman.core.archive.archive_tree.ArchiveTree.symlinks_fix")
|
||||
archive_trigger.on_stop()
|
||||
symlinks_mock.assert_called_once_with()
|
||||
Reference in New Issue
Block a user