write patches via gitremote push trigger

This commit is contained in:
2022-12-15 01:34:52 +02:00
parent b0b37e8169
commit 72dec54c0d
5 changed files with 52 additions and 18 deletions

View File

@ -5,48 +5,65 @@ from pytest_mock import MockerFixture
from unittest.mock import call as MockCall
from ahriman.core.configuration import Configuration
from ahriman.core.database import SQLite
from ahriman.core.exceptions import GitRemoteError
from ahriman.core.gitremote.remote_push import RemotePush
from ahriman.models.package import Package
from ahriman.models.pkgbuild_patch import PkgbuildPatch
from ahriman.models.result import Result
def test_package_update(package_ahriman: Package, mocker: MockerFixture) -> None:
def test_package_update(database: SQLite, configuration: Configuration, package_ahriman: Package,
mocker: MockerFixture) -> None:
"""
must update single package
"""
patch1 = PkgbuildPatch(None, "patch")
patch2 = PkgbuildPatch("key", "value")
rmtree_mock = mocker.patch("shutil.rmtree")
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
patches_mock = mocker.patch("ahriman.core.database.SQLite.patches_get", return_value=[patch1, patch2])
patches_write_mock = mocker.patch("ahriman.models.pkgbuild_patch.PkgbuildPatch.write")
runner = RemotePush(configuration, database, "gitremote")
local = Path("local")
RemotePush.package_update(package_ahriman, local)
assert runner.package_update(package_ahriman, local) == package_ahriman.base
rmtree_mock.assert_has_calls([
MockCall(local / package_ahriman.base, ignore_errors=True),
MockCall(local / package_ahriman.base / ".git", ignore_errors=True),
])
fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), package_ahriman.remote)
patches_mock.assert_called_once_with(package_ahriman.base)
patches_write_mock.assert_has_calls([
MockCall(local / package_ahriman.base / f"ahriman-{package_ahriman.base}.patch"),
MockCall(local / package_ahriman.base / f"ahriman-{patch2.key}.patch"),
])
def test_packages_update(result: Result, package_ahriman: Package, mocker: MockerFixture) -> None:
def test_packages_update(database: SQLite, configuration: Configuration, 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])
runner = RemotePush(configuration, database, "gitremote")
local = Path("local")
assert list(RemotePush.packages_update(result, local))
assert list(runner.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:
def test_run(database: SQLite, 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 = RemotePush(configuration, database, "gitremote")
runner.run(result)
fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), runner.remote_source)
@ -55,12 +72,12 @@ def test_run(configuration: Configuration, result: Result, package_ahriman: Pack
)
def test_run_failed(configuration: Configuration, result: Result, mocker: MockerFixture) -> None:
def test_run_failed(database: SQLite, 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")
runner = RemotePush(configuration, database, "gitremote")
with pytest.raises(GitRemoteError):
runner.run(result)

View File

@ -1,16 +1,18 @@
from pytest_mock import MockerFixture
from ahriman.core.configuration import Configuration
from ahriman.core.database import SQLite
from ahriman.core.gitremote import RemotePushTrigger
from ahriman.models.package import Package
from ahriman.models.result import Result
def test_on_result(configuration: Configuration, result: Result, package_ahriman: Package,
mocker: MockerFixture) -> None:
database: SQLite, mocker: MockerFixture) -> None:
"""
must push changes on result
"""
mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
run_mock = mocker.patch("ahriman.core.gitremote.remote_push.RemotePush.run")
trigger = RemotePushTrigger("x86_64", configuration)