mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
improve VCS packages checks
* Unlike older version, currently service will always try to pull AUR package to check version. Previously if no-vcs flag is set, it would ignore VCS packages completelly * Introduce build.vcs_allowed_age option. If set, it will skip version calculation if package age (now - build_date) is less than this value
This commit is contained in:
@ -17,6 +17,7 @@ def test_load(configuration: Configuration, database: SQLite, mocker: MockerFixt
|
||||
"""
|
||||
must correctly load instance
|
||||
"""
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
context_mock = mocker.patch("ahriman.core.repository.Repository._set_context")
|
||||
Repository.load("x86_64", configuration, database, report=False, unsafe=False)
|
||||
context_mock.assert_called_once_with()
|
||||
@ -26,6 +27,7 @@ def test_set_context(configuration: Configuration, database: SQLite, mocker: Moc
|
||||
"""
|
||||
must set context variables
|
||||
"""
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
set_mock = mocker.patch("ahriman.core._Context.set")
|
||||
|
||||
instance = Repository.load("x86_64", configuration, database, report=False, unsafe=False)
|
||||
|
@ -4,6 +4,7 @@ from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.repository.update_handler import UpdateHandler
|
||||
from ahriman.core.util import utcnow
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.remote_source import RemoteSource
|
||||
@ -82,7 +83,7 @@ def test_updates_aur_ignore(update_handler: UpdateHandler, package_ahriman: Pack
|
||||
mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.packages", return_value=[package_ahriman])
|
||||
package_load_mock = mocker.patch("ahriman.models.package.Package.from_aur")
|
||||
|
||||
update_handler.updates_aur([], vcs=True)
|
||||
assert not update_handler.updates_aur([], vcs=True)
|
||||
package_load_mock.assert_not_called()
|
||||
|
||||
|
||||
@ -92,11 +93,16 @@ def test_updates_aur_ignore_vcs(update_handler: UpdateHandler, package_ahriman:
|
||||
must skip VCS packages check if requested
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.packages", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.models.package.Package.from_aur", return_value=package_ahriman)
|
||||
mocker.patch("ahriman.models.package.Package.is_vcs", return_value=True)
|
||||
package_is_outdated_mock = mocker.patch("ahriman.models.package.Package.is_outdated")
|
||||
package_is_newer_than_mock = mocker.patch("ahriman.models.package.Package.is_newer_than", return_value=True)
|
||||
package_is_outdated_mock = mocker.patch("ahriman.models.package.Package.is_outdated", return_value=False)
|
||||
ts1 = utcnow().timestamp()
|
||||
|
||||
update_handler.updates_aur([], vcs=False)
|
||||
package_is_outdated_mock.assert_not_called()
|
||||
assert not update_handler.updates_aur([], vcs=False)
|
||||
package_is_newer_than_mock.assert_called_once_with(pytest.helpers.anyvar(float, strict=True))
|
||||
assert ts1 < package_is_newer_than_mock.call_args[0][0] < utcnow().timestamp()
|
||||
package_is_outdated_mock.assert_called_once_with(package_ahriman, update_handler.paths, calculate_version=False)
|
||||
|
||||
|
||||
def test_updates_local(update_handler: UpdateHandler, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
|
@ -11,8 +11,8 @@ from typing import Any
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.exceptions import BuildError, OptionError, UnsafeRunError
|
||||
from ahriman.core.util import check_output, check_user, exception_response_text, filter_json, full_version, \
|
||||
enum_values, package_like, pretty_datetime, pretty_size, safe_filename, walk
|
||||
from ahriman.core.util import check_output, check_user, enum_values, exception_response_text, filter_json, \
|
||||
full_version, package_like, pretty_datetime, pretty_size, safe_filename, utcnow, walk
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
@ -322,6 +322,15 @@ def test_safe_filename() -> None:
|
||||
assert safe_filename("tolua++-1.0.93-4-x86_64.pkg.tar.zst") == "tolua---1.0.93-4-x86_64.pkg.tar.zst"
|
||||
|
||||
|
||||
def test_utcnow() -> None:
|
||||
"""
|
||||
must generate correct timestamp
|
||||
"""
|
||||
ts1 = utcnow()
|
||||
ts2 = utcnow()
|
||||
assert 1 > (ts2 - ts1).total_seconds() > 0
|
||||
|
||||
|
||||
def test_walk(resource_path_root: Path) -> None:
|
||||
"""
|
||||
must traverse directory recursively
|
||||
|
@ -265,11 +265,31 @@ def test_full_depends(package_ahriman: Package, package_python_schedule: Package
|
||||
assert package_python_schedule.full_depends(pyalpm_handle, [package_python_schedule]) == expected
|
||||
|
||||
|
||||
def test_is_newer_than(package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must correctly check if package is newer than specified timestamp
|
||||
"""
|
||||
# base checks, true/false
|
||||
assert package_ahriman.is_newer_than(package_ahriman.packages[package_ahriman.base].build_date - 1)
|
||||
assert not package_ahriman.is_newer_than(package_ahriman.packages[package_ahriman.base].build_date + 1)
|
||||
|
||||
# list check
|
||||
min_date = min(package.build_date for package in package_python_schedule.packages.values())
|
||||
assert package_python_schedule.is_newer_than(min_date)
|
||||
|
||||
# null list check
|
||||
package_python_schedule.packages["python-schedule"].build_date = None
|
||||
assert package_python_schedule.is_newer_than(min_date)
|
||||
|
||||
package_python_schedule.packages["python2-schedule"].build_date = None
|
||||
assert not package_python_schedule.is_newer_than(min_date)
|
||||
|
||||
|
||||
def test_is_outdated_false(package_ahriman: Package, repository_paths: RepositoryPaths) -> None:
|
||||
"""
|
||||
must be not outdated for the same package
|
||||
"""
|
||||
assert not package_ahriman.is_outdated(package_ahriman, repository_paths)
|
||||
assert not package_ahriman.is_outdated(package_ahriman, repository_paths, calculate_version=True)
|
||||
|
||||
|
||||
def test_is_outdated_true(package_ahriman: Package, repository_paths: RepositoryPaths) -> None:
|
||||
@ -279,7 +299,7 @@ def test_is_outdated_true(package_ahriman: Package, repository_paths: Repository
|
||||
other = Package.from_json(package_ahriman.view())
|
||||
other.version = other.version.replace("-1", "-2")
|
||||
|
||||
assert package_ahriman.is_outdated(other, repository_paths)
|
||||
assert package_ahriman.is_outdated(other, repository_paths, calculate_version=True)
|
||||
|
||||
|
||||
def test_build_status_pretty_print(package_ahriman: Package) -> None:
|
||||
|
Reference in New Issue
Block a user