mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-09-17 22:29:55 +00:00
Complete official repository support (#59)
This commit is contained in:
@ -1,14 +1,18 @@
|
||||
import datetime
|
||||
import pytest
|
||||
import time
|
||||
|
||||
from unittest.mock import MagicMock, PropertyMock
|
||||
|
||||
from ahriman import version
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
from ahriman.models.counters import Counters
|
||||
from ahriman.models.internal_status import InternalStatus
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.remote_source import RemoteSource
|
||||
from ahriman.models.user_identity import UserIdentity
|
||||
|
||||
|
||||
@ -67,7 +71,7 @@ def package_tpacpi_bat_git() -> Package:
|
||||
return Package(
|
||||
base="tpacpi-bat-git",
|
||||
version="3.1.r12.g4959b52-1",
|
||||
aur_url="https://aur.archlinux.org",
|
||||
remote=RemoteSource.from_remote(PackageSource.AUR, "tpacpi-bat-git", "aur"),
|
||||
packages={"tpacpi-bat-git": PackageDescription()})
|
||||
|
||||
|
||||
@ -88,22 +92,34 @@ def pyalpm_handle(pyalpm_package_ahriman: MagicMock) -> MagicMock:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pyalpm_package_ahriman(package_ahriman: Package) -> MagicMock:
|
||||
def pyalpm_package_ahriman(aur_package_ahriman: AURPackage) -> MagicMock:
|
||||
"""
|
||||
mock object for pyalpm package
|
||||
|
||||
Args:
|
||||
package_ahriman(Package): package fixture
|
||||
aur_package_ahriman(AURPackage): package fixture
|
||||
|
||||
Returns:
|
||||
MagicMock: pyalpm package mock
|
||||
"""
|
||||
mock = MagicMock()
|
||||
type(mock).base = PropertyMock(return_value=package_ahriman.base)
|
||||
type(mock).depends = PropertyMock(return_value=["python-aur"])
|
||||
type(mock).name = PropertyMock(return_value=package_ahriman.base)
|
||||
type(mock).provides = PropertyMock(return_value=["python-ahriman"])
|
||||
type(mock).version = PropertyMock(return_value=package_ahriman.version)
|
||||
db = type(mock).db = MagicMock()
|
||||
|
||||
type(mock).base = PropertyMock(return_value=aur_package_ahriman.package_base)
|
||||
type(mock).builddate = PropertyMock(
|
||||
return_value=aur_package_ahriman.last_modified.replace(tzinfo=datetime.timezone.utc).timestamp())
|
||||
type(mock).conflicts = PropertyMock(return_value=aur_package_ahriman.conflicts)
|
||||
type(db).name = PropertyMock(return_value="aur")
|
||||
type(mock).depends = PropertyMock(return_value=aur_package_ahriman.depends)
|
||||
type(mock).desc = PropertyMock(return_value=aur_package_ahriman.description)
|
||||
type(mock).licenses = PropertyMock(return_value=aur_package_ahriman.license)
|
||||
type(mock).makedepends = PropertyMock(return_value=aur_package_ahriman.make_depends)
|
||||
type(mock).name = PropertyMock(return_value=aur_package_ahriman.name)
|
||||
type(mock).optdepends = PropertyMock(return_value=aur_package_ahriman.opt_depends)
|
||||
type(mock).provides = PropertyMock(return_value=aur_package_ahriman.provides)
|
||||
type(mock).version = PropertyMock(return_value=aur_package_ahriman.version)
|
||||
type(mock).url = PropertyMock(return_value=aur_package_ahriman.url)
|
||||
|
||||
return mock
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import datetime
|
||||
import json
|
||||
import pyalpm # typing: ignore
|
||||
|
||||
from dataclasses import asdict, fields
|
||||
from pathlib import Path
|
||||
@ -53,6 +54,22 @@ def test_from_json_2(aur_package_ahriman: AURPackage, mocker: MockerFixture) ->
|
||||
assert AURPackage.from_json(asdict(aur_package_ahriman)) == aur_package_ahriman
|
||||
|
||||
|
||||
def test_from_pacman(pyalpm_package_ahriman: pyalpm.Package, aur_package_ahriman: AURPackage,
|
||||
resource_path_root: Path) -> None:
|
||||
"""
|
||||
must load package from repository database
|
||||
"""
|
||||
model = AURPackage.from_pacman(pyalpm_package_ahriman)
|
||||
# some fields are missing so we are changing them
|
||||
model.id = aur_package_ahriman.id
|
||||
model.package_base_id = aur_package_ahriman.package_base_id
|
||||
model.first_submitted = aur_package_ahriman.first_submitted
|
||||
model.url_path = aur_package_ahriman.url_path
|
||||
model.maintainer = aur_package_ahriman.maintainer
|
||||
|
||||
assert model == aur_package_ahriman
|
||||
|
||||
|
||||
def test_from_repo(aur_package_akonadi: AURPackage, resource_path_root: Path) -> None:
|
||||
"""
|
||||
must load package from repository api json
|
||||
|
@ -4,10 +4,10 @@ from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.alpm.pacman import Pacman
|
||||
from ahriman.core.exceptions import InvalidPackageInfo
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
@ -21,15 +21,6 @@ def test_depends(package_python_schedule: Package) -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_git_url(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must generate valid git url
|
||||
"""
|
||||
assert package_ahriman.git_url.endswith(".git")
|
||||
assert package_ahriman.git_url.startswith(package_ahriman.aur_url)
|
||||
assert package_ahriman.base in package_ahriman.git_url
|
||||
|
||||
|
||||
def test_groups(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return list of groups for each package
|
||||
@ -80,30 +71,23 @@ def test_licenses(package_ahriman: Package) -> None:
|
||||
assert sorted(package_ahriman.licenses) == package_ahriman.licenses
|
||||
|
||||
|
||||
def test_web_url(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must generate valid web url
|
||||
"""
|
||||
assert package_ahriman.web_url.startswith(package_ahriman.aur_url)
|
||||
assert package_ahriman.base in package_ahriman.web_url
|
||||
|
||||
|
||||
def test_from_archive(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must construct package from alpm library
|
||||
"""
|
||||
mocker.patch("ahriman.models.package_description.PackageDescription.from_package",
|
||||
return_value=package_ahriman.packages[package_ahriman.base])
|
||||
assert Package.from_archive(Path("path"), pyalpm_handle, package_ahriman.aur_url) == package_ahriman
|
||||
assert Package.from_archive(Path("path"), pyalpm_handle, package_ahriman.remote) == package_ahriman
|
||||
|
||||
|
||||
def test_from_aur(package_ahriman: Package, aur_package_ahriman: AURPackage, mocker: MockerFixture) -> None:
|
||||
def test_from_aur(package_ahriman: Package, aur_package_ahriman: AURPackage, pacman: Pacman,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must construct package from aur
|
||||
"""
|
||||
mocker.patch("ahriman.core.alpm.remote.aur.AUR.info", return_value=aur_package_ahriman)
|
||||
|
||||
package = Package.from_aur(package_ahriman.base, package_ahriman.aur_url)
|
||||
package = Package.from_aur(package_ahriman.base, pacman)
|
||||
assert package_ahriman.base == package.base
|
||||
assert package_ahriman.version == package.version
|
||||
assert package_ahriman.packages.keys() == package.packages.keys()
|
||||
@ -114,11 +98,12 @@ def test_from_build(package_ahriman: Package, mocker: MockerFixture, resource_pa
|
||||
must construct package from srcinfo
|
||||
"""
|
||||
srcinfo = (resource_path_root / "models" / "package_ahriman_srcinfo").read_text()
|
||||
mocker.patch("pathlib.Path.read_text", return_value=srcinfo)
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
package = Package.from_build(Path("path"), package_ahriman.aur_url)
|
||||
package = Package.from_build(Path("path"))
|
||||
assert package_ahriman.packages.keys() == package.packages.keys()
|
||||
package_ahriman.packages = package.packages # we are not going to test PackageDescription here
|
||||
package_ahriman.remote = None
|
||||
assert package_ahriman == package
|
||||
|
||||
|
||||
@ -126,11 +111,11 @@ def test_from_build_failed(package_ahriman: Package, mocker: MockerFixture) -> N
|
||||
"""
|
||||
must raise exception if there are errors during srcinfo load
|
||||
"""
|
||||
mocker.patch("pathlib.Path.read_text", return_value="")
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value="")
|
||||
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
|
||||
|
||||
with pytest.raises(InvalidPackageInfo):
|
||||
Package.from_build(Path("path"), package_ahriman.aur_url)
|
||||
Package.from_build(Path("path"))
|
||||
|
||||
|
||||
def test_from_json_view_1(package_ahriman: Package) -> None:
|
||||
@ -154,97 +139,24 @@ def test_from_json_view_3(package_tpacpi_bat_git: Package) -> None:
|
||||
assert Package.from_json(package_tpacpi_bat_git.view()) == package_tpacpi_bat_git
|
||||
|
||||
|
||||
def test_from_official(package_ahriman: Package, aur_package_ahriman: AURPackage, mocker: MockerFixture) -> None:
|
||||
def test_from_official(package_ahriman: Package, aur_package_ahriman: AURPackage, pacman: Pacman,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must construct package from official repository
|
||||
"""
|
||||
mocker.patch("ahriman.core.alpm.remote.official.Official.info", return_value=aur_package_ahriman)
|
||||
|
||||
package = Package.from_official(package_ahriman.base, package_ahriman.aur_url)
|
||||
package = Package.from_official(package_ahriman.base, pacman)
|
||||
assert package_ahriman.base == package.base
|
||||
assert package_ahriman.version == package.version
|
||||
assert package_ahriman.packages.keys() == package.packages.keys()
|
||||
|
||||
|
||||
def test_load_resolve(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve source before package loading
|
||||
"""
|
||||
resolve_mock = mocker.patch("ahriman.models.package_source.PackageSource.resolve",
|
||||
return_value=PackageSource.Archive)
|
||||
mocker.patch("ahriman.models.package.Package.from_archive")
|
||||
|
||||
Package.load("path", PackageSource.Archive, pyalpm_handle, package_ahriman.aur_url)
|
||||
resolve_mock.assert_called_once_with("path")
|
||||
|
||||
|
||||
def test_load_from_archive(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load package from package archive
|
||||
"""
|
||||
load_mock = mocker.patch("ahriman.models.package.Package.from_archive")
|
||||
Package.load("path", PackageSource.Archive, pyalpm_handle, package_ahriman.aur_url)
|
||||
load_mock.assert_called_once_with(Path("path"), pyalpm_handle, package_ahriman.aur_url)
|
||||
|
||||
|
||||
def test_load_from_aur(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load package from AUR
|
||||
"""
|
||||
load_mock = mocker.patch("ahriman.models.package.Package.from_aur")
|
||||
Package.load("path", PackageSource.AUR, pyalpm_handle, package_ahriman.aur_url)
|
||||
load_mock.assert_called_once_with("path", package_ahriman.aur_url)
|
||||
|
||||
|
||||
def test_load_from_build(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load package from build directory
|
||||
"""
|
||||
load_mock = mocker.patch("ahriman.models.package.Package.from_build")
|
||||
Package.load("path", PackageSource.Local, pyalpm_handle, package_ahriman.aur_url)
|
||||
load_mock.assert_called_once_with(Path("path"), package_ahriman.aur_url)
|
||||
|
||||
|
||||
def test_load_from_official(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load package from AUR
|
||||
"""
|
||||
load_mock = mocker.patch("ahriman.models.package.Package.from_official")
|
||||
Package.load("path", PackageSource.Repository, pyalpm_handle, package_ahriman.aur_url)
|
||||
load_mock.assert_called_once_with("path", package_ahriman.aur_url)
|
||||
|
||||
|
||||
def test_load_failure(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise InvalidPackageInfo on exception
|
||||
"""
|
||||
mocker.patch("ahriman.models.package.Package.from_aur", side_effect=InvalidPackageInfo("exception!"))
|
||||
with pytest.raises(InvalidPackageInfo):
|
||||
Package.load("path", PackageSource.AUR, pyalpm_handle, package_ahriman.aur_url)
|
||||
|
||||
|
||||
def test_load_failure_exception(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise InvalidPackageInfo on random eexception
|
||||
"""
|
||||
mocker.patch("ahriman.models.package.Package.from_aur", side_effect=Exception())
|
||||
with pytest.raises(InvalidPackageInfo):
|
||||
Package.load("path", PackageSource.AUR, pyalpm_handle, package_ahriman.aur_url)
|
||||
|
||||
|
||||
def test_load_invalid_source(package_ahriman: Package, pyalpm_handle: MagicMock) -> None:
|
||||
"""
|
||||
must raise InvalidPackageInfo on unsupported source
|
||||
"""
|
||||
with pytest.raises(InvalidPackageInfo):
|
||||
Package.load("path", PackageSource.Remote, pyalpm_handle, package_ahriman.aur_url)
|
||||
|
||||
|
||||
def test_dependencies_failed(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise exception if there are errors during srcinfo load
|
||||
"""
|
||||
mocker.patch("pathlib.Path.read_text", return_value="")
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value="")
|
||||
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
|
||||
|
||||
with pytest.raises(InvalidPackageInfo):
|
||||
@ -256,7 +168,7 @@ def test_dependencies_with_version(mocker: MockerFixture, resource_path_root: Pa
|
||||
must load correct list of dependencies with version
|
||||
"""
|
||||
srcinfo = (resource_path_root / "models" / "package_yay_srcinfo").read_text()
|
||||
mocker.patch("pathlib.Path.read_text", return_value=srcinfo)
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
assert Package.dependencies(Path("path")) == {"git", "go", "pacman"}
|
||||
|
||||
@ -266,7 +178,7 @@ def test_dependencies_with_version_and_overlap(mocker: MockerFixture, resource_p
|
||||
must load correct list of dependencies with version
|
||||
"""
|
||||
srcinfo = (resource_path_root / "models" / "package_gcc10_srcinfo").read_text()
|
||||
mocker.patch("pathlib.Path.read_text", return_value=srcinfo)
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
assert Package.dependencies(Path("path")) == {"glibc", "doxygen", "binutils", "git", "libmpc", "python", "zstd"}
|
||||
|
||||
@ -328,7 +240,7 @@ def test_full_depends(package_ahriman: Package, package_python_schedule: Package
|
||||
assert package_ahriman.full_depends(pyalpm_handle, [package_python_schedule]) == package_ahriman.depends
|
||||
|
||||
package_python_schedule.packages[package_python_schedule.base].depends = [package_ahriman.base]
|
||||
expected = sorted(set(package_python_schedule.depends + ["python-aur"]))
|
||||
expected = sorted(set(package_python_schedule.depends + package_ahriman.depends))
|
||||
assert package_python_schedule.full_depends(pyalpm_handle, [package_python_schedule]) == expected
|
||||
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
from dataclasses import asdict
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
@ -24,14 +23,14 @@ def test_from_json(package_description_ahriman: PackageDescription) -> None:
|
||||
"""
|
||||
must construct description from json object
|
||||
"""
|
||||
assert PackageDescription.from_json(asdict(package_description_ahriman)) == package_description_ahriman
|
||||
assert PackageDescription.from_json(package_description_ahriman.view()) == package_description_ahriman
|
||||
|
||||
|
||||
def test_from_json_with_unknown_fields(package_description_ahriman: PackageDescription) -> None:
|
||||
"""
|
||||
must construct description from json object containing unknown fields
|
||||
"""
|
||||
dump = asdict(package_description_ahriman)
|
||||
dump = package_description_ahriman.view()
|
||||
dump.update(unknown_field="value")
|
||||
assert PackageDescription.from_json(dump) == package_description_ahriman
|
||||
|
||||
|
82
tests/ahriman/models/test_remote_source.py
Normal file
82
tests/ahriman/models/test_remote_source.py
Normal file
@ -0,0 +1,82 @@
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.remote_source import RemoteSource
|
||||
|
||||
|
||||
def test_post_init(remote_source: RemoteSource) -> None:
|
||||
"""
|
||||
must convert string source to enum
|
||||
"""
|
||||
remote = RemoteSource(
|
||||
git_url=remote_source.git_url,
|
||||
web_url=remote_source.web_url,
|
||||
path=remote_source.path,
|
||||
branch=remote_source.branch,
|
||||
source=remote_source.source.value,
|
||||
)
|
||||
assert remote == remote_source
|
||||
|
||||
|
||||
def test_pkgbuild_dir(remote_source: RemoteSource) -> None:
|
||||
"""
|
||||
must return path as is in `path` property
|
||||
"""
|
||||
assert isinstance(remote_source.pkgbuild_dir, Path)
|
||||
assert remote_source.pkgbuild_dir.name == ""
|
||||
|
||||
|
||||
def test_from_json(remote_source: RemoteSource) -> None:
|
||||
"""
|
||||
must construct remote source from json
|
||||
"""
|
||||
assert RemoteSource.from_json(remote_source.view()) == remote_source
|
||||
|
||||
|
||||
def test_from_json_empty() -> None:
|
||||
"""
|
||||
must return None in case of empty dictionary, which is required by the database wrapper
|
||||
"""
|
||||
assert RemoteSource.from_json({}) is None
|
||||
|
||||
|
||||
def test_from_remote_aur(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must construct remote from AUR source
|
||||
"""
|
||||
remote_git_url_mock = mocker.patch("ahriman.core.alpm.remote.aur.AUR.remote_git_url")
|
||||
remote_web_url_mock = mocker.patch("ahriman.core.alpm.remote.aur.AUR.remote_web_url")
|
||||
|
||||
remote = RemoteSource.from_remote(PackageSource.AUR, package_ahriman.base, "aur")
|
||||
remote_git_url_mock.assert_called_once_with(package_ahriman.base, "aur")
|
||||
remote_web_url_mock.assert_called_once_with(package_ahriman.base)
|
||||
assert remote.pkgbuild_dir == Path(".")
|
||||
assert remote.branch == "master"
|
||||
assert remote.source == PackageSource.AUR
|
||||
|
||||
|
||||
def test_from_remote_official(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must construct remote from official repository source
|
||||
"""
|
||||
remote_git_url_mock = mocker.patch("ahriman.core.alpm.remote.official.Official.remote_git_url")
|
||||
remote_web_url_mock = mocker.patch("ahriman.core.alpm.remote.official.Official.remote_web_url")
|
||||
|
||||
remote = RemoteSource.from_remote(PackageSource.Repository, package_ahriman.base, "community")
|
||||
remote_git_url_mock.assert_called_once_with(package_ahriman.base, "community")
|
||||
remote_web_url_mock.assert_called_once_with(package_ahriman.base)
|
||||
assert remote.pkgbuild_dir == Path("trunk")
|
||||
assert remote.branch.endswith(package_ahriman.base)
|
||||
assert remote.source == PackageSource.Repository
|
||||
|
||||
|
||||
def test_from_remote_other() -> None:
|
||||
"""
|
||||
must return None in case if source is not one of AUR or Repository
|
||||
"""
|
||||
assert RemoteSource.from_remote(PackageSource.Archive, "package", "repository") is None
|
||||
assert RemoteSource.from_remote(PackageSource.Directory, "package", "repository") is None
|
||||
assert RemoteSource.from_remote(PackageSource.Local, "package", "repository") is None
|
||||
assert RemoteSource.from_remote(PackageSource.Remote, "package", "repository") is None
|
Reference in New Issue
Block a user