mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 23:37:18 +00:00
add status route
This commit is contained in:
parent
32df4fc54f
commit
a37cb72d4e
@ -23,6 +23,7 @@ from ahriman.web.views.ahriman import AhrimanView
|
|||||||
from ahriman.web.views.index import IndexView
|
from ahriman.web.views.index import IndexView
|
||||||
from ahriman.web.views.package import PackageView
|
from ahriman.web.views.package import PackageView
|
||||||
from ahriman.web.views.packages import PackagesView
|
from ahriman.web.views.packages import PackagesView
|
||||||
|
from ahriman.web.views.status import StatusView
|
||||||
|
|
||||||
|
|
||||||
def setup_routes(application: Application) -> None:
|
def setup_routes(application: Application) -> None:
|
||||||
@ -44,6 +45,8 @@ def setup_routes(application: Application) -> None:
|
|||||||
GET /api/v1/package/:base get package base status
|
GET /api/v1/package/:base get package base status
|
||||||
POST /api/v1/package/:base update package base status
|
POST /api/v1/package/:base update package base status
|
||||||
|
|
||||||
|
GET /api/v1/status get web service status itself
|
||||||
|
|
||||||
:param application: web application instance
|
:param application: web application instance
|
||||||
"""
|
"""
|
||||||
application.router.add_get("/", IndexView)
|
application.router.add_get("/", IndexView)
|
||||||
@ -58,3 +61,5 @@ def setup_routes(application: Application) -> None:
|
|||||||
application.router.add_delete("/api/v1/packages/{package}", PackageView)
|
application.router.add_delete("/api/v1/packages/{package}", PackageView)
|
||||||
application.router.add_get("/api/v1/packages/{package}", PackageView)
|
application.router.add_get("/api/v1/packages/{package}", PackageView)
|
||||||
application.router.add_post("/api/v1/packages/{package}", PackageView)
|
application.router.add_post("/api/v1/packages/{package}", PackageView)
|
||||||
|
|
||||||
|
application.router.add_get("/api/v1/status", StatusView)
|
||||||
|
49
src/ahriman/web/views/status.py
Normal file
49
src/ahriman/web/views/status.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#
|
||||||
|
# Copyright (c) 2021 ahriman team.
|
||||||
|
#
|
||||||
|
# This file is part of ahriman
|
||||||
|
# (see https://github.com/arcan1s/ahriman).
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
from aiohttp.web import Response, json_response
|
||||||
|
|
||||||
|
import ahriman.version as version
|
||||||
|
|
||||||
|
from ahriman.web.views.base import BaseView
|
||||||
|
|
||||||
|
|
||||||
|
class StatusView(BaseView):
|
||||||
|
"""
|
||||||
|
web service status web view
|
||||||
|
"""
|
||||||
|
|
||||||
|
async def get(self) -> Response:
|
||||||
|
"""
|
||||||
|
get current service status
|
||||||
|
:return: 200 with service status object
|
||||||
|
"""
|
||||||
|
packages = self.service.packages
|
||||||
|
per_status = {"total": len(packages)}
|
||||||
|
for _, status in packages:
|
||||||
|
per_status.setdefault(status.status.name, 0)
|
||||||
|
per_status[status.status.name] += 1
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"architecture": self.service.architecture,
|
||||||
|
"packages": per_status,
|
||||||
|
"repository": self.service.repository.name,
|
||||||
|
"version": version.__version__,
|
||||||
|
}
|
||||||
|
return json_response(data)
|
22
tests/ahriman/web/views/test_view_status.py
Normal file
22
tests/ahriman/web/views/test_view_status.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from pytest_aiohttp import TestClient
|
||||||
|
|
||||||
|
import ahriman.version as version
|
||||||
|
|
||||||
|
from ahriman.models.build_status import BuildStatusEnum
|
||||||
|
from ahriman.models.package import Package
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get(client: TestClient, package_ahriman: Package) -> None:
|
||||||
|
"""
|
||||||
|
must generate web service status correctly)
|
||||||
|
"""
|
||||||
|
await client.post(f"/api/v1/packages/{package_ahriman.base}",
|
||||||
|
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
|
||||||
|
|
||||||
|
response = await client.get("/api/v1/status")
|
||||||
|
assert response.status == 200
|
||||||
|
|
||||||
|
json = await response.json()
|
||||||
|
assert json["version"] == version.__version__
|
||||||
|
assert json["packages"]
|
||||||
|
assert json["packages"]["total"] == 1
|
Loading…
Reference in New Issue
Block a user