use own aur wrapper (#49)

This commit is contained in:
2022-02-06 03:44:57 +03:00
committed by GitHub
parent f54a2fe740
commit 9197b416e6
25 changed files with 673 additions and 132 deletions

View File

@ -0,0 +1,47 @@
import datetime
import json
from dataclasses import asdict, fields
from pathlib import Path
from pytest_mock import MockerFixture
from typing import Any, Dict
from ahriman.models.aur_package import AURPackage
def _get_data(resource_path_root: Path) -> Dict[str, Any]:
"""
load package description from resource file
:param resource_path_root: path to resource root
:return: json descriptor
"""
response = (resource_path_root / "models" / "package_ahriman_aur").read_text()
return json.loads(response)["results"][0]
def test_from_json(aur_package_ahriman: AURPackage, resource_path_root: Path) -> None:
"""
must load package from json
"""
model = _get_data(resource_path_root)
assert AURPackage.from_json(model) == aur_package_ahriman
def test_from_json_2(aur_package_ahriman: AURPackage, mocker: MockerFixture) -> None:
"""
must load the same package from json
"""
mocker.patch("ahriman.models.aur_package.AURPackage.convert", side_effect=lambda v: v)
assert AURPackage.from_json(asdict(aur_package_ahriman)) == aur_package_ahriman
def test_convert(aur_package_ahriman: AURPackage, resource_path_root: Path) -> None:
"""
must convert fields to snakecase and also apply converters
"""
model = _get_data(resource_path_root)
converted = AURPackage.convert(model)
known_fields = [pair.name for pair in fields(AURPackage)]
assert all(field in known_fields for field in converted)
assert isinstance(converted.get("first_submitted"), datetime.datetime)
assert isinstance(converted.get("last_modified"), datetime.datetime)

View File

@ -2,9 +2,10 @@ import pytest
from pathlib import Path
from pytest_mock import MockerFixture
from unittest.mock import MagicMock, PropertyMock
from unittest.mock import MagicMock
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
@ -96,15 +97,11 @@ def test_from_archive(package_ahriman: Package, pyalpm_handle: MagicMock, mocker
assert Package.from_archive(Path("path"), pyalpm_handle, package_ahriman.aur_url) == package_ahriman
def test_from_aur(package_ahriman: Package, mocker: MockerFixture) -> None:
def test_from_aur(package_ahriman: Package, aur_package_ahriman: AURPackage, mocker: MockerFixture) -> None:
"""
must construct package from aur
"""
mock = MagicMock()
type(mock).name = PropertyMock(return_value=package_ahriman.base)
type(mock).package_base = PropertyMock(return_value=package_ahriman.base)
type(mock).version = PropertyMock(return_value=package_ahriman.version)
mocker.patch("aur.info", return_value=mock)
mocker.patch("ahriman.core.alpm.aur.AUR.info", return_value=aur_package_ahriman)
package = Package.from_aur(package_ahriman.base, package_ahriman.aur_url)
assert package_ahriman.base == package.base