fix: process list patch values in http requests

This commit parses values from post request as well as always serializes
values for the web interface
This commit is contained in:
2024-11-22 17:22:37 +02:00
parent 3c1fdec0e9
commit 45a620c40b
7 changed files with 29 additions and 6 deletions

View File

@ -61,6 +61,7 @@ def test_parse() -> None:
assert PkgbuildPatch.parse("key", """("QU'OUTED" ARRAY VALUE)""").value == ["QU'OUTED", "ARRAY", "VALUE"]
assert PkgbuildPatch.parse("key()", """{ function with " quotes }""").value == """{ function with " quotes }"""
assert PkgbuildPatch.parse("key", json.dumps(["array", "value"])).value == ["array", "value"]
assert PkgbuildPatch.parse("key", ["array", "value"]).value == ["array", "value"]
def test_quote() -> None:

View File

@ -82,6 +82,25 @@ async def test_post_full_diff(client: TestClient, package_ahriman: Package) -> N
assert patches == [payload]
async def test_post_array(client: TestClient, package_ahriman: Package) -> None:
"""
must create patch from list variable
"""
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": "(array value)"}
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()
parsed = [PkgbuildPatch(patch["key"], patch["value"]) for patch in patches]
assert parsed == [PkgbuildPatch("k", ["array", "value"])]
async def test_post_exception(client: TestClient, package_ahriman: Package) -> None:
"""
must raise exception on invalid payload