feat: changes screen implementation (#117)

Add support of changes generation. Changes will be generated (unless explicitly asked not to) automatically during check process (i.e. `repo-update --dry-run` and aliases) and uploaded to the remote server. Changes can be reviewed either by web interface or by special subcommands.

Changes will be automatically cleared during next successful build
This commit is contained in:
2023-11-30 14:56:41 +02:00
committed by GitHub
parent a689448854
commit 2760b36977
81 changed files with 2107 additions and 382 deletions

View File

@ -0,0 +1 @@
# schema testing goes in view class tests

View File

@ -0,0 +1,84 @@
import pytest
from aiohttp.test_utils import TestClient
from ahriman.models.build_status import BuildStatusEnum
from ahriman.models.changes import Changes
from ahriman.models.package import Package
from ahriman.models.user_access import UserAccess
from ahriman.web.views.v1.status.changes import ChangesView
async def test_get_permission() -> None:
"""
must return correct permission for the request
"""
for method in ("GET",):
request = pytest.helpers.request("", "", method)
assert await ChangesView.get_permission(request) == UserAccess.Reporter
for method in ("POST",):
request = pytest.helpers.request("", "", method)
assert await ChangesView.get_permission(request) == UserAccess.Full
def test_routes() -> None:
"""
must return correct routes
"""
assert ChangesView.ROUTES == ["/api/v1/packages/{package}/changes"]
async def test_get(client: TestClient, package_ahriman: Package) -> None:
"""
must get changes for package
"""
changes = Changes("sha", "change")
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}/changes", json=changes.view())
response_schema = pytest.helpers.schema_response(ChangesView.get)
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/changes")
assert response.status == 200
assert await response.json() == changes.view()
assert not response_schema.validate(changes.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(ChangesView.get, code=404)
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/changes")
assert response.status == 404
assert not response_schema.validate(await response.json())
async def test_post(client: TestClient, package_ahriman: Package) -> None:
"""
must update package changes
"""
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(ChangesView.post)
changes = Changes("sha", "change")
assert not request_schema.validate(changes.view())
response = await client.post(f"/api/v1/packages/{package_ahriman.base}/changes", json=changes.view())
assert response.status == 204
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/changes")
assert await response.json() == changes.view()
async def test_post_exception(client: TestClient, package_ahriman: Package) -> None:
"""
must raise exception on invalid payload
"""
response_schema = pytest.helpers.schema_response(ChangesView.post, code=400)
response = await client.post(f"/api/v1/packages/{package_ahriman.base}/changes", json=[])
assert response.status == 400
assert not response_schema.validate(await response.json())