mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-29 21:59:55 +00:00
add support of officiall repositories api
This commit is contained in:
@ -1,12 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.alpm.aur import AUR
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def aur() -> AUR:
|
||||
"""
|
||||
aur helper fixture
|
||||
:return: aur helper instance
|
||||
"""
|
||||
return AUR()
|
32
tests/ahriman/core/alpm/remote/conftest.py
Normal file
32
tests/ahriman/core/alpm/remote/conftest.py
Normal file
@ -0,0 +1,32 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.alpm.remote.aur import AUR
|
||||
from ahriman.core.alpm.remote.official import Official
|
||||
from ahriman.core.alpm.remote.remote import Remote
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def aur() -> AUR:
|
||||
"""
|
||||
aur helper fixture
|
||||
:return: aur helper instance
|
||||
"""
|
||||
return AUR()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def official() -> Official:
|
||||
"""
|
||||
official repository fixture
|
||||
:return: official repository helper instance
|
||||
"""
|
||||
return Official()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def remote() -> Remote:
|
||||
"""
|
||||
official repository fixture
|
||||
:return: official repository helper instance
|
||||
"""
|
||||
return Remote()
|
@ -4,10 +4,9 @@ import requests
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.alpm.aur import AUR
|
||||
from ahriman.core.alpm.remote.aur import AUR
|
||||
from ahriman.core.exceptions import InvalidPackageInfo
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
|
||||
@ -21,55 +20,6 @@ def _get_response(resource_path_root: Path) -> str:
|
||||
return (resource_path_root / "models" / "package_ahriman_aur").read_text()
|
||||
|
||||
|
||||
def test_info(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call info method
|
||||
"""
|
||||
info_mock = mocker.patch("ahriman.core.alpm.aur.AUR.package_info")
|
||||
AUR.info("ahriman")
|
||||
info_mock.assert_called_once_with("ahriman")
|
||||
|
||||
|
||||
def test_multisearch(aur_package_ahriman: AURPackage, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must search in AUR with multiple words
|
||||
"""
|
||||
terms = ["ahriman", "is", "cool"]
|
||||
search_mock = mocker.patch("ahriman.core.alpm.aur.AUR.search", return_value=[aur_package_ahriman])
|
||||
|
||||
assert AUR.multisearch(*terms) == [aur_package_ahriman]
|
||||
search_mock.assert_has_calls([mock.call("ahriman"), mock.call("cool")])
|
||||
|
||||
|
||||
def test_multisearch_empty(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return empty list if no long terms supplied
|
||||
"""
|
||||
terms = ["it", "is"]
|
||||
search_mock = mocker.patch("ahriman.core.alpm.aur.AUR.search")
|
||||
|
||||
assert AUR.multisearch(*terms) == []
|
||||
search_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_multisearch_single(aur_package_ahriman: AURPackage, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must search in AUR with one word
|
||||
"""
|
||||
search_mock = mocker.patch("ahriman.core.alpm.aur.AUR.search", return_value=[aur_package_ahriman])
|
||||
assert AUR.multisearch("ahriman") == [aur_package_ahriman]
|
||||
search_mock.assert_called_once_with("ahriman")
|
||||
|
||||
|
||||
def test_search(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call search method
|
||||
"""
|
||||
search_mock = mocker.patch("ahriman.core.alpm.aur.AUR.package_search")
|
||||
AUR.search("ahriman")
|
||||
search_mock.assert_called_once_with("ahriman")
|
||||
|
||||
|
||||
def test_parse_response(aur_package_ahriman: AURPackage, resource_path_root: Path) -> None:
|
||||
"""
|
||||
must parse success response
|
||||
@ -87,7 +37,7 @@ def test_parse_response_error(resource_path_root: Path) -> None:
|
||||
AUR.parse_response(json.loads(response))
|
||||
|
||||
|
||||
def test_parse_response_unknown_error(resource_path_root: Path) -> None:
|
||||
def test_parse_response_unknown_error() -> None:
|
||||
"""
|
||||
must raise exception on invalid response with empty error message
|
||||
"""
|
||||
@ -159,7 +109,7 @@ def test_package_info(aur: AUR, aur_package_ahriman: AURPackage, mocker: MockerF
|
||||
"""
|
||||
must make request for info
|
||||
"""
|
||||
request_mock = mocker.patch("ahriman.core.alpm.aur.AUR.make_request", return_value=[aur_package_ahriman])
|
||||
request_mock = mocker.patch("ahriman.core.alpm.remote.aur.AUR.make_request", return_value=[aur_package_ahriman])
|
||||
assert aur.package_info(aur_package_ahriman.name) == aur_package_ahriman
|
||||
request_mock.assert_called_once_with("info", aur_package_ahriman.name)
|
||||
|
||||
@ -168,6 +118,6 @@ def test_package_search(aur: AUR, aur_package_ahriman: AURPackage, mocker: Mocke
|
||||
"""
|
||||
must make request for search
|
||||
"""
|
||||
request_mock = mocker.patch("ahriman.core.alpm.aur.AUR.make_request", return_value=[aur_package_ahriman])
|
||||
assert aur.package_search(aur_package_ahriman.name, by="name") == [aur_package_ahriman]
|
||||
request_mock.assert_called_once_with("search", aur_package_ahriman.name, by="name")
|
||||
request_mock = mocker.patch("ahriman.core.alpm.remote.aur.AUR.make_request", return_value=[aur_package_ahriman])
|
||||
assert aur.package_search(aur_package_ahriman.name) == [aur_package_ahriman]
|
||||
request_mock.assert_called_once_with("search", aur_package_ahriman.name, by="name-desc")
|
88
tests/ahriman/core/alpm/remote/test_official.py
Normal file
88
tests/ahriman/core/alpm/remote/test_official.py
Normal file
@ -0,0 +1,88 @@
|
||||
import json
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.alpm.remote.official import Official
|
||||
from ahriman.core.exceptions import InvalidPackageInfo
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
|
||||
|
||||
def _get_response(resource_path_root: Path) -> str:
|
||||
"""
|
||||
load response from resource file
|
||||
:param resource_path_root: path to resource root
|
||||
:return: response text
|
||||
"""
|
||||
return (resource_path_root / "models" / "package_akonadi_aur").read_text()
|
||||
|
||||
|
||||
def test_parse_response(aur_package_akonadi: AURPackage, resource_path_root: Path) -> None:
|
||||
"""
|
||||
must parse success response
|
||||
"""
|
||||
response = _get_response(resource_path_root)
|
||||
assert Official.parse_response(json.loads(response)) == [aur_package_akonadi]
|
||||
|
||||
|
||||
def test_parse_response_unknown_error(resource_path_root: Path) -> None:
|
||||
"""
|
||||
must raise exception on invalid response with empty error message
|
||||
"""
|
||||
response = (resource_path_root / "models" / "official_error").read_text()
|
||||
with pytest.raises(InvalidPackageInfo, match="API validation error"):
|
||||
Official.parse_response(json.loads(response))
|
||||
|
||||
|
||||
def test_make_request(official: Official, aur_package_akonadi: AURPackage,
|
||||
mocker: MockerFixture, resource_path_root: Path) -> None:
|
||||
"""
|
||||
must perform request to official repositories
|
||||
"""
|
||||
response_mock = MagicMock()
|
||||
response_mock.json.return_value = json.loads(_get_response(resource_path_root))
|
||||
request_mock = mocker.patch("requests.get", return_value=response_mock)
|
||||
|
||||
assert official.make_request("akonadi", by="q") == [aur_package_akonadi]
|
||||
request_mock.assert_called_once_with("https://archlinux.org/packages/search/json", params={"q": ("akonadi",)})
|
||||
|
||||
|
||||
def test_make_request_failed(official: Official, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must reraise generic exception
|
||||
"""
|
||||
mocker.patch("requests.get", side_effect=Exception())
|
||||
with pytest.raises(Exception):
|
||||
official.make_request("akonadi", by="q")
|
||||
|
||||
|
||||
def test_make_request_failed_http_error(official: Official, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must reraise http exception
|
||||
"""
|
||||
mocker.patch("requests.get", side_effect=requests.exceptions.HTTPError())
|
||||
with pytest.raises(requests.exceptions.HTTPError):
|
||||
official.make_request("akonadi", by="q")
|
||||
|
||||
|
||||
def test_package_info(official: Official, aur_package_akonadi: AURPackage, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must make request for info
|
||||
"""
|
||||
request_mock = mocker.patch("ahriman.core.alpm.remote.official.Official.make_request",
|
||||
return_value=[aur_package_akonadi])
|
||||
assert official.package_info(aur_package_akonadi.name) == aur_package_akonadi
|
||||
request_mock.assert_called_once_with(aur_package_akonadi.name, by="name")
|
||||
|
||||
|
||||
def test_package_search(official: Official, aur_package_akonadi: AURPackage, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must make request for search
|
||||
"""
|
||||
request_mock = mocker.patch("ahriman.core.alpm.remote.official.Official.make_request",
|
||||
return_value=[aur_package_akonadi])
|
||||
assert official.package_search(aur_package_akonadi.name) == [aur_package_akonadi]
|
||||
request_mock.assert_called_once_with(aur_package_akonadi.name, by="q")
|
72
tests/ahriman/core/alpm/remote/test_remote.py
Normal file
72
tests/ahriman/core/alpm/remote/test_remote.py
Normal file
@ -0,0 +1,72 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.alpm.remote.remote import Remote
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
|
||||
|
||||
def test_info(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call info method
|
||||
"""
|
||||
info_mock = mocker.patch("ahriman.core.alpm.remote.remote.Remote.package_info")
|
||||
Remote.info("ahriman")
|
||||
info_mock.assert_called_once_with("ahriman")
|
||||
|
||||
|
||||
def test_multisearch(aur_package_ahriman: AURPackage, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must search in AUR with multiple words
|
||||
"""
|
||||
terms = ["ahriman", "is", "cool"]
|
||||
search_mock = mocker.patch("ahriman.core.alpm.remote.remote.Remote.search", return_value=[aur_package_ahriman])
|
||||
|
||||
assert Remote.multisearch(*terms) == [aur_package_ahriman]
|
||||
search_mock.assert_has_calls([mock.call("ahriman"), mock.call("cool")])
|
||||
|
||||
|
||||
def test_multisearch_empty(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return empty list if no long terms supplied
|
||||
"""
|
||||
terms = ["it", "is"]
|
||||
search_mock = mocker.patch("ahriman.core.alpm.remote.remote.Remote.search")
|
||||
|
||||
assert Remote.multisearch(*terms) == []
|
||||
search_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_multisearch_single(aur_package_ahriman: AURPackage, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must search in AUR with one word
|
||||
"""
|
||||
search_mock = mocker.patch("ahriman.core.alpm.remote.remote.Remote.search", return_value=[aur_package_ahriman])
|
||||
assert Remote.multisearch("ahriman") == [aur_package_ahriman]
|
||||
search_mock.assert_called_once_with("ahriman")
|
||||
|
||||
|
||||
def test_search(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call search method
|
||||
"""
|
||||
search_mock = mocker.patch("ahriman.core.alpm.remote.remote.Remote.package_search")
|
||||
Remote.search("ahriman")
|
||||
search_mock.assert_called_once_with("ahriman")
|
||||
|
||||
|
||||
def test_package_info(remote: Remote) -> None:
|
||||
"""
|
||||
must raise NotImplemented for missing package info method
|
||||
"""
|
||||
with pytest.raises(NotImplementedError):
|
||||
remote.package_info("package")
|
||||
|
||||
|
||||
def test_package_search(remote: Remote) -> None:
|
||||
"""
|
||||
must raise NotImplemented for missing package search method
|
||||
"""
|
||||
with pytest.raises(NotImplementedError):
|
||||
remote.package_search("package")
|
@ -9,8 +9,8 @@ from pytest_mock import MockerFixture
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.exceptions import BuildFailed, InvalidOption, UnsafeRun
|
||||
from ahriman.core.util import check_output, check_user, exception_response_text, filter_json, package_like, \
|
||||
pretty_datetime, pretty_size, tmpdir, walk
|
||||
from ahriman.core.util import check_output, check_user, exception_response_text, filter_json, full_version, \
|
||||
package_like, pretty_datetime, pretty_size, tmpdir, walk
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
@ -177,6 +177,16 @@ def test_filter_json_empty_value(package_ahriman: Package) -> None:
|
||||
assert "base" not in filter_json(probe, probe.keys())
|
||||
|
||||
|
||||
def test_full_version() -> None:
|
||||
"""
|
||||
must construct full version
|
||||
"""
|
||||
assert full_version("1", "r2388.d30e3201", "1") == "1:r2388.d30e3201-1"
|
||||
assert full_version(None, "0.12.1", "1") == "0.12.1-1"
|
||||
assert full_version(0, "0.12.1", "1") == "0.12.1-1"
|
||||
assert full_version(1, "0.12.1", "1") == "1:0.12.1-1"
|
||||
|
||||
|
||||
def test_package_like(package_ahriman: Package) -> None:
|
||||
"""
|
||||
package_like must return true for archives
|
||||
@ -298,24 +308,26 @@ def test_walk(resource_path_root: Path) -> None:
|
||||
must traverse directory recursively
|
||||
"""
|
||||
expected = sorted([
|
||||
resource_path_root / "core/ahriman.ini",
|
||||
resource_path_root / "core/logging.ini",
|
||||
resource_path_root / "models/aur_error",
|
||||
resource_path_root / "models/big_file_checksum",
|
||||
resource_path_root / "models/empty_file_checksum",
|
||||
resource_path_root / "models/package_ahriman_aur",
|
||||
resource_path_root / "models/package_ahriman_srcinfo",
|
||||
resource_path_root / "models/package_tpacpi-bat-git_srcinfo",
|
||||
resource_path_root / "models/package_yay_srcinfo",
|
||||
resource_path_root / "web/templates/build-status/login-modal.jinja2",
|
||||
resource_path_root / "web/templates/build-status/package-actions-modals.jinja2",
|
||||
resource_path_root / "web/templates/build-status/package-actions-script.jinja2",
|
||||
resource_path_root / "web/templates/static/favicon.ico",
|
||||
resource_path_root / "web/templates/utils/bootstrap-scripts.jinja2",
|
||||
resource_path_root / "web/templates/utils/style.jinja2",
|
||||
resource_path_root / "web/templates/build-status.jinja2",
|
||||
resource_path_root / "web/templates/email-index.jinja2",
|
||||
resource_path_root / "web/templates/repo-index.jinja2",
|
||||
resource_path_root / "core" / "ahriman.ini",
|
||||
resource_path_root / "core" / "logging.ini",
|
||||
resource_path_root / "models" / "aur_error",
|
||||
resource_path_root / "models" / "big_file_checksum",
|
||||
resource_path_root / "models" / "empty_file_checksum",
|
||||
resource_path_root / "models" / "official_error",
|
||||
resource_path_root / "models" / "package_ahriman_aur",
|
||||
resource_path_root / "models" / "package_akonadi_aur",
|
||||
resource_path_root / "models" / "package_ahriman_srcinfo",
|
||||
resource_path_root / "models" / "package_tpacpi-bat-git_srcinfo",
|
||||
resource_path_root / "models" / "package_yay_srcinfo",
|
||||
resource_path_root / "web" / "templates" / "build-status" / "login-modal.jinja2",
|
||||
resource_path_root / "web" / "templates" / "build-status" / "package-actions-modals.jinja2",
|
||||
resource_path_root / "web" / "templates" / "build-status" / "package-actions-script.jinja2",
|
||||
resource_path_root / "web" / "templates" / "static" / "favicon.ico",
|
||||
resource_path_root / "web" / "templates" / "utils" / "bootstrap-scripts.jinja2",
|
||||
resource_path_root / "web" / "templates" / "utils" / "style.jinja2",
|
||||
resource_path_root / "web" / "templates" / "build-status.jinja2",
|
||||
resource_path_root / "web" / "templates" / "email-index.jinja2",
|
||||
resource_path_root / "web" / "templates" / "repo-index.jinja2",
|
||||
])
|
||||
local_files = list(sorted(walk(resource_path_root)))
|
||||
assert local_files == expected
|
||||
|
Reference in New Issue
Block a user