mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-05-04 04:03:49 +00:00
Compare commits
No commits in common. "270084bb3961a4c761d833b4eab441474877bd87" and "8cafdb52e5552db32ebadabb8ebdd8398734c020" have entirely different histories.
270084bb39
...
8cafdb52e5
@ -190,8 +190,7 @@ class Watcher(LazyLogging):
|
|||||||
Returns:
|
Returns:
|
||||||
list[PkgbuildPatch]: list of patches which are stored for the package
|
list[PkgbuildPatch]: list of patches which are stored for the package
|
||||||
"""
|
"""
|
||||||
# patches are package base based, we don't know (and don't differentiate) to which package does them belong
|
self.package_get(package_base)
|
||||||
# so here we skip checking if package exists or not
|
|
||||||
variables = [variable] if variable is not None else None
|
variables = [variable] if variable is not None else None
|
||||||
return self.database.patches_list(package_base, variables).get(package_base, [])
|
return self.database.patches_list(package_base, variables).get(package_base, [])
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import aiohttp_apispec # type: ignore[import-untyped]
|
|||||||
|
|
||||||
from aiohttp.web import HTTPNoContent, HTTPNotFound, Response, json_response
|
from aiohttp.web import HTTPNoContent, HTTPNotFound, Response, json_response
|
||||||
|
|
||||||
|
from ahriman.core.exceptions import UnknownPackageError
|
||||||
from ahriman.models.user_access import UserAccess
|
from ahriman.models.user_access import UserAccess
|
||||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PatchNameSchema, PatchSchema
|
from ahriman.web.schemas import AuthSchema, ErrorSchema, PatchNameSchema, PatchSchema
|
||||||
from ahriman.web.views.base import BaseView
|
from ahriman.web.views.base import BaseView
|
||||||
@ -75,7 +76,7 @@ class PatchView(StatusViewGuard, BaseView):
|
|||||||
200: {"description": "Success response", "schema": PatchSchema},
|
200: {"description": "Success response", "schema": PatchSchema},
|
||||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||||
404: {"description": "Patch name is unknown", "schema": ErrorSchema},
|
404: {"description": "Package base and/or patch name are unknown", "schema": ErrorSchema},
|
||||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||||
},
|
},
|
||||||
security=[{"token": [GET_PERMISSION]}],
|
security=[{"token": [GET_PERMISSION]}],
|
||||||
@ -90,12 +91,15 @@ class PatchView(StatusViewGuard, BaseView):
|
|||||||
Response: 200 with package patch on success
|
Response: 200 with package patch on success
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
HTTPNotFound: if package patch is unknown
|
HTTPNotFound: if package base is unknown
|
||||||
"""
|
"""
|
||||||
package_base = self.request.match_info["package"]
|
package_base = self.request.match_info["package"]
|
||||||
variable = self.request.match_info["patch"]
|
variable = self.request.match_info["patch"]
|
||||||
|
|
||||||
patches = self.service().patches_get(package_base, variable)
|
try:
|
||||||
|
patches = self.service().patches_get(package_base, variable)
|
||||||
|
except UnknownPackageError:
|
||||||
|
raise HTTPNotFound(reason=f"Package {package_base} is unknown")
|
||||||
|
|
||||||
selected = next((patch for patch in patches if patch.key == variable), None)
|
selected = next((patch for patch in patches if patch.key == variable), None)
|
||||||
if selected is None:
|
if selected is None:
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
#
|
#
|
||||||
import aiohttp_apispec # type: ignore[import-untyped]
|
import aiohttp_apispec # type: ignore[import-untyped]
|
||||||
|
|
||||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response
|
from aiohttp.web import HTTPBadRequest, HTTPNoContent, HTTPNotFound, Response, json_response
|
||||||
|
|
||||||
|
from ahriman.core.exceptions import UnknownPackageError
|
||||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||||
from ahriman.models.user_access import UserAccess
|
from ahriman.models.user_access import UserAccess
|
||||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackageNameSchema, PatchSchema
|
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackageNameSchema, PatchSchema
|
||||||
@ -49,6 +50,7 @@ class PatchesView(StatusViewGuard, BaseView):
|
|||||||
200: {"description": "Success response", "schema": PatchSchema(many=True)},
|
200: {"description": "Success response", "schema": PatchSchema(many=True)},
|
||||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||||
|
404: {"description": "Package base is unknown", "schema": ErrorSchema},
|
||||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||||
},
|
},
|
||||||
security=[{"token": [GET_PERMISSION]}],
|
security=[{"token": [GET_PERMISSION]}],
|
||||||
@ -61,9 +63,15 @@ class PatchesView(StatusViewGuard, BaseView):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Response: 200 with package patches on success
|
Response: 200 with package patches on success
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
HTTPNotFound: if package base is unknown
|
||||||
"""
|
"""
|
||||||
package_base = self.request.match_info["package"]
|
package_base = self.request.match_info["package"]
|
||||||
patches = self.service().patches_get(package_base, None)
|
try:
|
||||||
|
patches = self.service().patches_get(package_base, None)
|
||||||
|
except UnknownPackageError:
|
||||||
|
raise HTTPNotFound(reason=f"Package {package_base} is unknown")
|
||||||
|
|
||||||
response = [patch.view() for patch in patches]
|
response = [patch.view() for patch in patches]
|
||||||
return json_response(response)
|
return json_response(response)
|
||||||
|
@ -212,6 +212,14 @@ def test_patches_get(watcher: Watcher, package_ahriman: Package, mocker: MockerF
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def test_patches_get_failed(watcher: Watcher, package_ahriman: Package) -> None:
|
||||||
|
"""
|
||||||
|
must raise UnknownPackageError on patches in case of unknown package
|
||||||
|
"""
|
||||||
|
with pytest.raises(UnknownPackageError):
|
||||||
|
watcher.patches_get(package_ahriman.base, None)
|
||||||
|
|
||||||
|
|
||||||
def test_patches_remove(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_patches_remove(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must remove patches for the package
|
must remove patches for the package
|
||||||
|
@ -70,6 +70,17 @@ async def test_get(client: TestClient, package_ahriman: Package) -> None:
|
|||||||
assert patches == patch.view()
|
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())
|
||||||
|
|
||||||
|
|
||||||
async def test_get_patch_not_found(client: TestClient, package_ahriman: Package) -> None:
|
async def test_get_patch_not_found(client: TestClient, package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must return not found for missing patch
|
must return not found for missing patch
|
||||||
|
@ -46,6 +46,17 @@ async def test_get(client: TestClient, package_ahriman: Package) -> None:
|
|||||||
assert patches == [patch.view()]
|
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(PatchesView.get, code=404)
|
||||||
|
|
||||||
|
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/patches")
|
||||||
|
assert response.status == 404
|
||||||
|
assert not response_schema.validate(await response.json())
|
||||||
|
|
||||||
|
|
||||||
async def test_post(client: TestClient, package_ahriman: Package) -> None:
|
async def test_post(client: TestClient, package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must create patch
|
must create patch
|
||||||
|
2
tox.ini
2
tox.ini
@ -74,8 +74,6 @@ depends =
|
|||||||
docs
|
docs
|
||||||
allowlist_externals =
|
allowlist_externals =
|
||||||
git
|
git
|
||||||
passenv =
|
|
||||||
SSH_AUTH_SOCK
|
|
||||||
commands =
|
commands =
|
||||||
git add package/archlinux/PKGBUILD src/ahriman/__init__.py docs/ahriman-architecture.svg package/share/man/man1/ahriman.1 package/share/bash-completion/completions/_ahriman package/share/zsh/site-functions/_ahriman
|
git add package/archlinux/PKGBUILD src/ahriman/__init__.py docs/ahriman-architecture.svg package/share/man/man1/ahriman.1 package/share/bash-completion/completions/_ahriman package/share/zsh/site-functions/_ahriman
|
||||||
git commit -m "Release {posargs}"
|
git commit -m "Release {posargs}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user