add package request endpoint

This commit is contained in:
2021-10-01 08:58:50 +03:00
parent 8add507957
commit 6be6614e6d
13 changed files with 117 additions and 25 deletions

View File

@ -24,18 +24,7 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
response = await client.post("/service-api/v1/add", json={"packages": ["ahriman"]})
assert response.ok
add_mock.assert_called_with(["ahriman"], True)
async def test_post_now(client: TestClient, mocker: MockerFixture) -> None:
"""
must call post and run build
"""
add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_add")
response = await client.post("/service-api/v1/add", json={"packages": ["ahriman"], "build_now": False})
assert response.ok
add_mock.assert_called_with(["ahriman"], False)
add_mock.assert_called_with(["ahriman"], now=True)
async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None:
@ -57,4 +46,4 @@ async def test_post_update(client: TestClient, mocker: MockerFixture) -> None:
response = await client.post("/service-api/v1/update", json={"packages": ["ahriman"]})
assert response.ok
add_mock.assert_called_with(["ahriman"], True)
add_mock.assert_called_with(["ahriman"], now=True)

View File

@ -0,0 +1,38 @@
import pytest
from aiohttp.test_utils import TestClient
from pytest_mock import MockerFixture
from ahriman.models.user_access import UserAccess
from ahriman.web.views.service.request import RequestView
async def test_get_permission() -> None:
"""
must return correct permission for the request
"""
for method in ("POST",):
request = pytest.helpers.request("", "", method)
assert await RequestView.get_permission(request) == UserAccess.Read
async def test_post(client: TestClient, mocker: MockerFixture) -> None:
"""
must call post request correctly
"""
add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_add")
response = await client.post("/service-api/v1/request", json={"packages": ["ahriman"]})
assert response.ok
add_mock.assert_called_with(["ahriman"], now=False)
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_add")
response = await client.post("/service-api/v1/request")
assert response.status == 400
add_mock.assert_not_called()

View File

@ -9,12 +9,12 @@ repositories = core extra community multilib
root = /
[auth]
allow_read_only = no
client_id = client_id
client_secret = client_secret
oauth_provider = GoogleClient
oauth_scopes = https://www.googleapis.com/auth/userinfo.email
salt = salt
safe_build_status = no
[build]
archbuild_flags =