move update under add

This commit is contained in:
Evgenii Alekseev 2021-09-09 00:49:07 +03:00
parent cafa76f680
commit 9fb27d959b
7 changed files with 18 additions and 98 deletions

View File

@ -89,13 +89,6 @@ class Spawn(Thread):
""" """
self.spawn_process("remove", *packages) self.spawn_process("remove", *packages)
def packages_update(self, packages: Iterable[str]) -> None:
"""
update packages
:param packages: packages list to update
"""
self.spawn_process("update", *packages)
def spawn_process(self, command: str, *args: str, **kwargs: str) -> None: def spawn_process(self, command: str, *args: str, **kwargs: str) -> None:
""" """
spawn external ahriman process with supplied arguments spawn external ahriman process with supplied arguments

View File

@ -23,7 +23,6 @@ from ahriman.web.views.index import IndexView
from ahriman.web.views.service.add import AddView from ahriman.web.views.service.add import AddView
from ahriman.web.views.service.remove import RemoveView from ahriman.web.views.service.remove import RemoveView
from ahriman.web.views.service.search import SearchView from ahriman.web.views.service.search import SearchView
from ahriman.web.views.service.update import UpdateView
from ahriman.web.views.status.ahriman import AhrimanView from ahriman.web.views.status.ahriman import AhrimanView
from ahriman.web.views.status.package import PackageView from ahriman.web.views.status.package import PackageView
from ahriman.web.views.status.packages import PackagesView from ahriman.web.views.status.packages import PackagesView
@ -45,9 +44,9 @@ def setup_routes(application: Application) -> None:
POST /service-api/v1/remove remove existing package from repository POST /service-api/v1/remove remove existing package from repository
GET /service-api/v1/search search for substring in AUR POST /service-api/v1/update update packages in repository, actually it is just alias for add
POST /service-api/v1/update update existing package in repository GET /service-api/v1/search search for substring in AUR
GET /status-api/v1/ahriman get current service status GET /status-api/v1/ahriman get current service status
POST /status-api/v1/ahriman update service status POST /status-api/v1/ahriman update service status
@ -75,7 +74,7 @@ def setup_routes(application: Application) -> None:
application.router.add_get("/service-api/v1/search", SearchView, allow_head=False) application.router.add_get("/service-api/v1/search", SearchView, allow_head=False)
application.router.add_post("/service-api/v1/update", UpdateView) application.router.add_post("/service-api/v1/update", AddView)
application.router.add_get("/status-api/v1/ahriman", AhrimanView, allow_head=True) application.router.add_get("/status-api/v1/ahriman", AhrimanView, allow_head=True)
application.router.add_post("/status-api/v1/ahriman", AhrimanView) application.router.add_post("/status-api/v1/ahriman", AhrimanView)

View File

@ -42,7 +42,7 @@ class AddView(BaseView):
data = await self.extract_data(["packages"]) data = await self.extract_data(["packages"])
try: try:
now = data.get("build_now") or False now = data.get("build_now", True)
packages = data["packages"] packages = data["packages"]
except Exception as e: except Exception as e:
return json_response(text=str(e), status=400) return json_response(text=str(e), status=400)

View File

@ -1,50 +0,0 @@
#
# 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 HTTPFound, Response, json_response
from ahriman.web.views.base import BaseView
class UpdateView(BaseView):
"""
update package web view
"""
async def post(self) -> Response:
"""
update existing packages
JSON body must be supplied, the following model is used:
{
"packages": "ahriman", # either list of packages or package name
}
:return: redirect to main page on success
"""
data = await self.extract_data(["packages"])
try:
packages = data["packages"]
except Exception as e:
return json_response(text=str(e), status=400)
self.spawner.packages_update(packages)
return HTTPFound("/")

View File

@ -63,15 +63,6 @@ def test_packages_remove(spawner: Spawn, mocker: MockerFixture) -> None:
spawn_mock.assert_called_with("remove", "ahriman", "linux") spawn_mock.assert_called_with("remove", "ahriman", "linux")
def test_packages_update(spawner: Spawn, mocker: MockerFixture) -> None:
"""
must call package updates
"""
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn.spawn_process")
spawner.packages_update(["ahriman", "linux"])
spawn_mock.assert_called_with("update", "ahriman", "linux")
def test_spawn_process(spawner: Spawn, mocker: MockerFixture) -> None: def test_spawn_process(spawner: Spawn, mocker: MockerFixture) -> None:
""" """
must correctly spawn child process must correctly spawn child process

View File

@ -10,7 +10,7 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
response = await client.post("/service-api/v1/add", json={"packages": ["ahriman"]}) response = await client.post("/service-api/v1/add", json={"packages": ["ahriman"]})
assert response.status == 200 assert response.status == 200
add_mock.assert_called_with(["ahriman"], False) add_mock.assert_called_with(["ahriman"], True)
async def test_post_now(client: TestClient, mocker: MockerFixture) -> None: async def test_post_now(client: TestClient, mocker: MockerFixture) -> None:
@ -18,10 +18,10 @@ async def test_post_now(client: TestClient, mocker: MockerFixture) -> None:
must call post and run build must call post and run build
""" """
add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_add") add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_add")
response = await client.post("/service-api/v1/add", json={"packages": ["ahriman"], "build_now": True}) response = await client.post("/service-api/v1/add", json={"packages": ["ahriman"], "build_now": False})
assert response.status == 200 assert response.status == 200
add_mock.assert_called_with(["ahriman"], True) add_mock.assert_called_with(["ahriman"], False)
async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None: async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None:
@ -33,3 +33,14 @@ async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None
assert response.status == 400 assert response.status == 400
add_mock.assert_not_called() add_mock.assert_not_called()
async def test_post_update(client: TestClient, mocker: MockerFixture) -> None:
"""
must call post request correctly for alias
"""
add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_add")
response = await client.post("/service-api/v1/update", json={"packages": ["ahriman"]})
assert response.status == 200
add_mock.assert_called_with(["ahriman"], True)

View File

@ -1,24 +0,0 @@
from aiohttp.test_utils import TestClient
from pytest_mock import MockerFixture
async def test_post(client: TestClient, mocker: MockerFixture) -> None:
"""
must call post request correctly
"""
add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_update")
response = await client.post("/service-api/v1/update", json={"packages": ["ahriman"]})
assert response.status == 200
add_mock.assert_called_with(["ahriman"])
async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None:
"""
must raise exception on missing packages payload
"""
add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_update")
response = await client.post("/service-api/v1/update")
assert response.status == 400
add_mock.assert_not_called()