add ability to reload authentication module

This commit is contained in:
2021-09-17 16:05:38 +03:00
parent 41731ca359
commit 16bb1403a1
15 changed files with 219 additions and 12 deletions

View File

@ -0,0 +1,15 @@
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
"""
reload_mock = mocker.patch("ahriman.core.configuration.Configuration.reload")
load_mock = mocker.patch("ahriman.core.auth.auth.Auth.load")
response = await client.post("/service-api/v1/reload-auth")
assert response.ok
reload_mock.assert_called_once()
load_mock.assert_called_with(client.app["configuration"])

View File

@ -6,19 +6,19 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
"""
must call post request correctly
"""
add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_remove")
remove_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_remove")
response = await client.post("/service-api/v1/remove", json={"packages": ["ahriman"]})
assert response.ok
add_mock.assert_called_with(["ahriman"])
remove_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_remove")
remove_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_remove")
response = await client.post("/service-api/v1/remove")
assert response.status == 400
add_mock.assert_not_called()
remove_mock.assert_not_called()

View File

@ -5,6 +5,13 @@ from multidict import MultiDict
from ahriman.web.views.base import BaseView
def test_configuration(base: BaseView) -> None:
"""
must return configuration
"""
assert base.configuration
def test_service(base: BaseView) -> None:
"""
must return service