mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-03-12 13:03:39 +00:00
support archive loading and management
This commit is contained in:
@@ -16,6 +16,7 @@ from ahriman.core.database import SQLite
|
||||
from ahriman.core.database.migrations import Migrations
|
||||
from ahriman.core.log.log_loader import LogLoader
|
||||
from ahriman.core.repository import Repository
|
||||
from ahriman.core.repository.package_info import PackageInfo
|
||||
from ahriman.core.spawn import Spawn
|
||||
from ahriman.core.status import Client
|
||||
from ahriman.core.status.watcher import Watcher
|
||||
@@ -688,4 +689,5 @@ def watcher(local_client: Client) -> Watcher:
|
||||
Returns:
|
||||
Watcher: package status watcher test instance
|
||||
"""
|
||||
return Watcher(local_client)
|
||||
package_info = PackageInfo()
|
||||
return Watcher(local_client, package_info)
|
||||
|
||||
@@ -8,6 +8,16 @@ from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def test_package_archives(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return package archives from package info
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.package_info.PackageInfo.package_archives", return_value=[package_ahriman])
|
||||
|
||||
result = watcher.package_archives(package_ahriman.base)
|
||||
assert result == [package_ahriman]
|
||||
|
||||
|
||||
def test_packages(watcher: Watcher, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return list of available packages
|
||||
|
||||
@@ -10,7 +10,7 @@ from ahriman.core.exceptions import InitializeError
|
||||
from ahriman.core.spawn import Spawn
|
||||
from ahriman.core.status.watcher import Watcher
|
||||
from ahriman.web.keys import ConfigurationKey
|
||||
from ahriman.web.web import _create_socket, _on_shutdown, _on_startup, run_server, setup_server
|
||||
from ahriman.web.web import _create_socket, _create_watcher, _on_shutdown, _on_startup, run_server, setup_server
|
||||
|
||||
|
||||
async def test_create_socket(application: Application, mocker: MockerFixture) -> None:
|
||||
@@ -139,6 +139,20 @@ def test_run_with_socket(application: Application, mocker: MockerFixture) -> Non
|
||||
)
|
||||
|
||||
|
||||
def test_create_watcher(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create watcher for repository
|
||||
"""
|
||||
database_mock = mocker.patch("ahriman.core.database.SQLite.load")
|
||||
client_mock = mocker.patch("ahriman.core.status.Client.load")
|
||||
configuration_path, repository_id = configuration.check_loaded()
|
||||
|
||||
result = _create_watcher(configuration_path, repository_id)
|
||||
assert isinstance(result, Watcher)
|
||||
database_mock.assert_called_once()
|
||||
client_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_setup_no_repositories(configuration: Configuration, spawner: Spawn) -> None:
|
||||
"""
|
||||
must raise InitializeError if no repositories set
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import pytest
|
||||
|
||||
from aiohttp.test_utils import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.models.build_status import BuildStatusEnum
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.v1.packages.archives import Archives
|
||||
|
||||
|
||||
async def test_get_permission() -> None:
|
||||
"""
|
||||
must return correct permission for the request
|
||||
"""
|
||||
for method in ("GET",):
|
||||
request = pytest.helpers.request("", "", method)
|
||||
assert await Archives.get_permission(request) == UserAccess.Reporter
|
||||
|
||||
|
||||
def test_routes() -> None:
|
||||
"""
|
||||
must return correct routes
|
||||
"""
|
||||
assert Archives.ROUTES == ["/api/v1/packages/{package}/archives"]
|
||||
|
||||
|
||||
async def test_get(client: TestClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must get archives for package
|
||||
"""
|
||||
await client.post(f"/api/v1/packages/{package_ahriman.base}",
|
||||
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
|
||||
mocker.patch("ahriman.core.status.watcher.Watcher.package_archives", return_value=[package_ahriman])
|
||||
response_schema = pytest.helpers.schema_response(Archives.get)
|
||||
|
||||
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/archives")
|
||||
assert response.status == 200
|
||||
|
||||
archives = await response.json()
|
||||
assert not response_schema.validate(archives)
|
||||
|
||||
|
||||
async def test_get_not_found(client: TestClient, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return not found for missing package
|
||||
"""
|
||||
response_schema = pytest.helpers.schema_response(Archives.get, code=404)
|
||||
|
||||
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/archives")
|
||||
assert response.status == 404
|
||||
assert not response_schema.validate(await response.json())
|
||||
Reference in New Issue
Block a user