mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
allow empty key patches via api
This commit is contained in:
parent
89f1b6ea0f
commit
ce7a8fde3c
@ -130,12 +130,11 @@ class Patch(Handler):
|
|||||||
variables(list[str] | None): extract patches only for specified PKGBUILD variables
|
variables(list[str] | None): extract patches only for specified PKGBUILD variables
|
||||||
exit_code(bool): exit with error on empty search result
|
exit_code(bool): exit with error on empty search result
|
||||||
"""
|
"""
|
||||||
patches = []
|
patches = [
|
||||||
if variables is not None:
|
patch
|
||||||
for variable in variables:
|
for patch in application.reporter.package_patches_get(package_base, None)
|
||||||
patches.extend(application.reporter.package_patches_get(package_base, variable))
|
if variables is None or patch.key in variables
|
||||||
else:
|
]
|
||||||
patches = application.reporter.package_patches_get(package_base, variables)
|
|
||||||
Patch.check_if_empty(exit_code, not patches)
|
Patch.check_if_empty(exit_code, not patches)
|
||||||
|
|
||||||
PatchPrinter(package_base, patches)(verbose=True, separator=" = ")
|
PatchPrinter(package_base, patches)(verbose=True, separator=" = ")
|
||||||
@ -154,4 +153,4 @@ class Patch(Handler):
|
|||||||
for variable in variables: # iterate over single variable
|
for variable in variables: # iterate over single variable
|
||||||
application.reporter.package_patches_remove(package_base, variable)
|
application.reporter.package_patches_remove(package_base, variable)
|
||||||
else:
|
else:
|
||||||
application.reporter.package_patches_remove(package_base, variables) # just pass as is
|
application.reporter.package_patches_remove(package_base, None) # just pass as is
|
||||||
|
@ -25,8 +25,8 @@ class PatchSchema(Schema):
|
|||||||
request and response patch schema
|
request and response patch schema
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = fields.String(required=True, metadata={
|
key = fields.String(metadata={
|
||||||
"description": "environment variable name",
|
"description": "environment variable name. Required in case if it is not full diff",
|
||||||
})
|
})
|
||||||
value = fields.String(metadata={
|
value = fields.String(metadata={
|
||||||
"description": "environment variable value",
|
"description": "environment variable value",
|
||||||
|
@ -96,7 +96,7 @@ class PatchesView(StatusViewGuard, BaseView):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
data = await self.request.json()
|
data = await self.request.json()
|
||||||
key = data["key"]
|
key = data.get("key")
|
||||||
value = data["value"]
|
value = data["value"]
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise HTTPBadRequest(reason=str(ex))
|
raise HTTPBadRequest(reason=str(ex))
|
||||||
|
@ -161,12 +161,12 @@ def test_patch_set_list(application: Application, mocker: MockerFixture) -> None
|
|||||||
must list available patches for the command
|
must list available patches for the command
|
||||||
"""
|
"""
|
||||||
get_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_patches_get",
|
get_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_patches_get",
|
||||||
return_value=[PkgbuildPatch(None, "patch")])
|
return_value=[PkgbuildPatch(None, "patch"), PkgbuildPatch("version", "value")])
|
||||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||||
|
|
||||||
Patch.patch_set_list(application, "ahriman", ["version"], False)
|
Patch.patch_set_list(application, "ahriman", ["version"], False)
|
||||||
get_mock.assert_called_once_with("ahriman", "version")
|
get_mock.assert_called_once_with("ahriman", None)
|
||||||
print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ")
|
print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ")
|
||||||
check_mock.assert_called_once_with(False, False)
|
check_mock.assert_called_once_with(False, False)
|
||||||
|
|
||||||
|
@ -64,6 +64,24 @@ async def test_post(client: TestClient, package_ahriman: Package) -> None:
|
|||||||
assert patches == [payload]
|
assert patches == [payload]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_post_full_diff(client: TestClient, package_ahriman: Package) -> None:
|
||||||
|
"""
|
||||||
|
must create patch from full diff
|
||||||
|
"""
|
||||||
|
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 = {"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:
|
async def test_post_exception(client: TestClient, package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must raise exception on invalid payload
|
must raise exception on invalid payload
|
||||||
|
Loading…
Reference in New Issue
Block a user