mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-17 15:59:55 +00:00
support vars in interface
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.exceptions import UnknownPackageError
|
||||
from ahriman.core.status.watcher import Watcher
|
||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
from ahriman.models.log_record_id import LogRecordId
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
|
||||
|
||||
def test_load(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -163,6 +165,42 @@ def test_package_update_unknown(watcher: Watcher, package_ahriman: Package) -> N
|
||||
watcher.package_update(package_ahriman.base, BuildStatusEnum.Unknown, None)
|
||||
|
||||
|
||||
def test_patches_get(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return patches for the package
|
||||
"""
|
||||
patches_mock = mocker.patch("ahriman.core.database.SQLite.patches_list")
|
||||
|
||||
watcher.patches_get(package_ahriman.base, None)
|
||||
watcher.patches_get(package_ahriman.base, "var")
|
||||
patches_mock.assert_has_calls([
|
||||
MockCall(package_ahriman.base, None),
|
||||
MockCall().get(package_ahriman.base, []),
|
||||
MockCall(package_ahriman.base, ["var"]),
|
||||
MockCall().get(package_ahriman.base, []),
|
||||
])
|
||||
|
||||
|
||||
def test_patches_remove(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must remove patches for the package
|
||||
"""
|
||||
patches_mock = mocker.patch("ahriman.core.database.SQLite.patches_remove")
|
||||
watcher.patches_remove(package_ahriman.base, "var")
|
||||
patches_mock.assert_called_once_with(package_ahriman.base, ["var"])
|
||||
|
||||
|
||||
def test_patches_update(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must update patches for the package
|
||||
"""
|
||||
patch = PkgbuildPatch("key", "value")
|
||||
patches_mock = mocker.patch("ahriman.core.database.SQLite.patches_insert")
|
||||
|
||||
watcher.patches_update(package_ahriman.base, patch)
|
||||
patches_mock.assert_called_once_with(package_ahriman.base, [patch])
|
||||
|
||||
|
||||
def test_status_update(watcher: Watcher) -> None:
|
||||
"""
|
||||
must update service status
|
||||
|
@ -92,6 +92,13 @@ def test_serialize_list() -> None:
|
||||
assert PkgbuildPatch("key", ["val'ue", "val\"ue2"]).serialize() == """key=('val'"'"'ue' 'val"ue2')"""
|
||||
|
||||
|
||||
def test_view() -> None:
|
||||
"""
|
||||
must correctly serialize to json
|
||||
"""
|
||||
assert PkgbuildPatch("key", "value").view() == {"key": "key", "value": "value"}
|
||||
|
||||
|
||||
def test_write(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must write serialized value to the file
|
||||
|
1
tests/ahriman/web/schemas/test_package_patch_schema.py
Normal file
1
tests/ahriman/web/schemas/test_package_patch_schema.py
Normal file
@ -0,0 +1 @@
|
||||
# schema testing goes in view class tests
|
1
tests/ahriman/web/schemas/test_patch_name_schema.py
Normal file
1
tests/ahriman/web/schemas/test_patch_name_schema.py
Normal file
@ -0,0 +1 @@
|
||||
# schema testing goes in view class tests
|
1
tests/ahriman/web/schemas/test_versioned_log_schema.py
Normal file
1
tests/ahriman/web/schemas/test_versioned_log_schema.py
Normal file
@ -0,0 +1 @@
|
||||
# schema testing goes in view class tests
|
@ -0,0 +1,81 @@
|
||||
import pytest
|
||||
|
||||
from aiohttp.test_utils import TestClient
|
||||
|
||||
from ahriman.models.build_status import BuildStatusEnum
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.v1.status.patch import PatchView
|
||||
|
||||
|
||||
async def test_get_permission() -> None:
|
||||
"""
|
||||
must return correct permission for the request
|
||||
"""
|
||||
for method in ("GET",):
|
||||
request = pytest.helpers.request("", "", method)
|
||||
assert await PatchView.get_permission(request) == UserAccess.Reporter
|
||||
for method in ("DELETE",):
|
||||
request = pytest.helpers.request("", "", method)
|
||||
assert await PatchView.get_permission(request) == UserAccess.Full
|
||||
|
||||
|
||||
def test_routes() -> None:
|
||||
"""
|
||||
must return correct routes
|
||||
"""
|
||||
assert PatchView.ROUTES == ["/api/v1/packages/{package}/patches/{patch}"]
|
||||
|
||||
|
||||
async def test_delete(client: TestClient, package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must delete patch for package
|
||||
"""
|
||||
await client.post(f"/api/v1/packages/{package_ahriman.base}",
|
||||
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
|
||||
await client.post(f"/api/v1/packages/{package_python_schedule.base}",
|
||||
json={"status": BuildStatusEnum.Success.value, "package": package_python_schedule.view()})
|
||||
|
||||
patch_key = "k"
|
||||
await client.post(f"/api/v1/packages/{package_ahriman.base}/patches", json={"key": patch_key, "value": "v"})
|
||||
await client.post(f"/api/v1/packages/{package_python_schedule.base}/patches",
|
||||
json={"key": patch_key, "value": "v2"})
|
||||
|
||||
response = await client.delete(f"/api/v1/packages/{package_ahriman.base}/patches/{patch_key}")
|
||||
assert response.status == 204
|
||||
|
||||
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/patches")
|
||||
assert not await response.json()
|
||||
|
||||
response = await client.get(f"/api/v1/packages/{package_python_schedule.base}/patches")
|
||||
assert await response.json()
|
||||
|
||||
|
||||
async def test_get(client: TestClient, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must get patch for package
|
||||
"""
|
||||
patch = PkgbuildPatch("k", "v")
|
||||
await client.post(f"/api/v1/packages/{package_ahriman.base}",
|
||||
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
|
||||
await client.post(f"/api/v1/packages/{package_ahriman.base}/patches", json=patch.view())
|
||||
response_schema = pytest.helpers.schema_response(PatchView.get)
|
||||
|
||||
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/patches/{patch.key}")
|
||||
assert response.status == 200
|
||||
|
||||
patches = await response.json()
|
||||
assert not response_schema.validate(patches)
|
||||
assert patches == patch.view()
|
||||
|
||||
|
||||
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(PatchView.get, code=404)
|
||||
|
||||
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/patches/random")
|
||||
assert response.status == 404
|
||||
assert not response_schema.validate(await response.json())
|
@ -0,0 +1,75 @@
|
||||
import pytest
|
||||
|
||||
from aiohttp.test_utils import TestClient
|
||||
|
||||
from ahriman.models.build_status import BuildStatusEnum
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.v1.status.patches import PatchesView
|
||||
|
||||
|
||||
async def test_get_permission() -> None:
|
||||
"""
|
||||
must return correct permission for the request
|
||||
"""
|
||||
for method in ("GET",):
|
||||
request = pytest.helpers.request("", "", method)
|
||||
assert await PatchesView.get_permission(request) == UserAccess.Reporter
|
||||
for method in ("POST",):
|
||||
request = pytest.helpers.request("", "", method)
|
||||
assert await PatchesView.get_permission(request) == UserAccess.Full
|
||||
|
||||
|
||||
def test_routes() -> None:
|
||||
"""
|
||||
must return correct routes
|
||||
"""
|
||||
assert PatchesView.ROUTES == ["/api/v1/packages/{package}/patches"]
|
||||
|
||||
|
||||
async def test_get(client: TestClient, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must get patch for package
|
||||
"""
|
||||
patch = PkgbuildPatch("k", "v")
|
||||
await client.post(f"/api/v1/packages/{package_ahriman.base}",
|
||||
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
|
||||
await client.post(f"/api/v1/packages/{package_ahriman.base}/patches", json=patch.view())
|
||||
response_schema = pytest.helpers.schema_response(PatchesView.get)
|
||||
|
||||
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/patches")
|
||||
assert response.status == 200
|
||||
|
||||
patches = await response.json()
|
||||
assert not response_schema.validate(patches)
|
||||
assert patches == [patch.view()]
|
||||
|
||||
|
||||
async def test_post(client: TestClient, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must create patch
|
||||
"""
|
||||
await client.post(f"/api/v1/packages/{package_ahriman.base}",
|
||||
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
|
||||
request_schema = pytest.helpers.schema_request(PatchesView.post)
|
||||
|
||||
payload = {"key": "k", "value": "v"}
|
||||
assert not request_schema.validate(payload)
|
||||
response = await client.post(f"/api/v1/packages/{package_ahriman.base}/patches", json=payload)
|
||||
assert response.status == 204
|
||||
|
||||
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/patches")
|
||||
patches = await response.json()
|
||||
assert patches == [payload]
|
||||
|
||||
|
||||
async def test_post_exception(client: TestClient, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must raise exception on invalid payload
|
||||
"""
|
||||
response_schema = pytest.helpers.schema_response(PatchesView.post, code=400)
|
||||
|
||||
response = await client.post(f"/api/v1/packages/{package_ahriman.base}/patches", json={})
|
||||
assert response.status == 400
|
||||
assert not response_schema.validate(await response.json())
|
@ -44,7 +44,16 @@ async def test_get(client: TestClient, package_ahriman: Package) -> None:
|
||||
|
||||
logs = await response.json()
|
||||
assert not response_schema.validate(logs)
|
||||
assert logs["logs"] == [[42.0, "message 1"], [43.0, "message 2"]]
|
||||
assert logs == [
|
||||
{
|
||||
"created": 42.0,
|
||||
"message": "message 1",
|
||||
},
|
||||
{
|
||||
"created": 43.0,
|
||||
"message": "message 2",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
async def test_get_with_pagination(client: TestClient, package_ahriman: Package) -> None:
|
||||
@ -67,18 +76,7 @@ async def test_get_with_pagination(client: TestClient, package_ahriman: Package)
|
||||
|
||||
logs = await response.json()
|
||||
assert not response_schema.validate(logs)
|
||||
assert logs["logs"] == [[43.0, "message 2"]]
|
||||
|
||||
|
||||
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(LogsView.get, code=404)
|
||||
|
||||
response = await client.get(f"/api/v2/packages/{package_ahriman.base}/logs")
|
||||
assert response.status == 404
|
||||
assert not response_schema.validate(await response.json())
|
||||
assert logs == [{"created": 43.0, "message": "message 2"}]
|
||||
|
||||
|
||||
async def test_get_bad_request(client: TestClient, package_ahriman: Package) -> None:
|
||||
|
Reference in New Issue
Block a user