mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 14:51:43 +00:00
change gitremote api to be same as report and upload
These changes are keeping fallback to old settings, but will allow to run multiple git targets with different settings
This commit is contained in:
70
tests/ahriman/core/gitremote/test_remote_pull.py
Normal file
70
tests/ahriman/core/gitremote/test_remote_pull.py
Normal file
@ -0,0 +1,70 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import GitRemoteFailed
|
||||
from ahriman.core.gitremote.remote_pull import RemotePull
|
||||
|
||||
|
||||
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.remote_pull.RemotePull.repo_copy")
|
||||
runner = RemotePull(configuration, "gitremote")
|
||||
|
||||
runner.repo_clone()
|
||||
fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), runner.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.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")
|
||||
runner = RemotePull(configuration, "gitremote")
|
||||
|
||||
runner.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")),
|
||||
])
|
||||
|
||||
|
||||
def test_run(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must clone repo on run
|
||||
"""
|
||||
clone_mock = mocker.patch("ahriman.core.gitremote.remote_pull.RemotePull.repo_clone")
|
||||
runner = RemotePull(configuration, "gitremote")
|
||||
|
||||
runner.run()
|
||||
clone_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_run_failed(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must reraise exception on error occurred
|
||||
"""
|
||||
mocker.patch("ahriman.core.gitremote.remote_pull.RemotePull.repo_clone", side_effect=Exception())
|
||||
runner = RemotePull(configuration, "gitremote")
|
||||
|
||||
with pytest.raises(GitRemoteFailed):
|
||||
runner.run()
|
@ -1,8 +1,4 @@
|
||||
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
|
||||
@ -12,47 +8,8 @@ def test_on_start(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must clone repo on start
|
||||
"""
|
||||
clone_mock = mocker.patch("ahriman.core.gitremote.RemotePullTrigger.repo_clone")
|
||||
run_mock = mocker.patch("ahriman.core.gitremote.remote_pull.RemotePull.run")
|
||||
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")),
|
||||
])
|
||||
run_mock.assert_called_once_with()
|
||||
|
67
tests/ahriman/core/gitremote/test_remote_push.py
Normal file
67
tests/ahriman/core/gitremote/test_remote_push.py
Normal file
@ -0,0 +1,67 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import GitRemoteFailed
|
||||
from ahriman.core.gitremote.remote_push import RemotePush
|
||||
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")
|
||||
RemotePush.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.remote_push.RemotePush.package_update",
|
||||
return_value=[package_ahriman.base])
|
||||
|
||||
local = Path("local")
|
||||
assert list(RemotePush.packages_update(result, local))
|
||||
update_mock.assert_called_once_with(package_ahriman, local)
|
||||
|
||||
|
||||
def test_run(configuration: Configuration, result: Result, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must push changes on result
|
||||
"""
|
||||
mocker.patch("ahriman.core.gitremote.remote_push.RemotePush.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")
|
||||
runner = RemotePush(configuration, "gitremote")
|
||||
|
||||
runner.run(result)
|
||||
fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), runner.remote_source)
|
||||
push_mock.assert_called_once_with(pytest.helpers.anyvar(int), runner.remote_source, package_ahriman.base)
|
||||
|
||||
|
||||
def test_run_failed(configuration: Configuration, result: Result, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must reraise exception on error occurred
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.fetch", side_effect=Exception())
|
||||
runner = RemotePush(configuration, "gitremote")
|
||||
|
||||
with pytest.raises(GitRemoteFailed):
|
||||
runner.run(result)
|
@ -1,8 +1,4 @@
|
||||
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
|
||||
@ -10,47 +6,13 @@ 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")
|
||||
run_mock = mocker.patch("ahriman.core.gitremote.remote_push.RemotePush.run")
|
||||
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)
|
||||
run_mock.assert_called_once_with(result)
|
||||
|
@ -15,7 +15,7 @@ def test_report_failure(configuration: Configuration, mocker: MockerFixture) ->
|
||||
"""
|
||||
mocker.patch("ahriman.core.report.html.HTML.generate", side_effect=Exception())
|
||||
with pytest.raises(ReportFailed):
|
||||
Report.load("x86_64", configuration, "html").run([], Result())
|
||||
Report.load("x86_64", configuration, "html").run(Result(), [])
|
||||
|
||||
|
||||
def test_report_dummy(configuration: Configuration, result: Result, mocker: MockerFixture) -> None:
|
||||
|
@ -31,9 +31,15 @@ root = ../../../
|
||||
[sign]
|
||||
target =
|
||||
|
||||
[remote-push]
|
||||
target = gitremote
|
||||
|
||||
[remote-pull]
|
||||
target = gitremote
|
||||
|
||||
[gitremote]
|
||||
pull_url = https://github.com/arcan1s/repository.git
|
||||
push_url = https://github.com/arcan1s/repository.git
|
||||
pull_url = https://github.com/arcan1s/repository.git
|
||||
|
||||
[report]
|
||||
target =
|
||||
|
Reference in New Issue
Block a user