mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
feat: add ability to disable specific routes (#119)
This commit is contained in:
@ -18,6 +18,8 @@ def test_test_coverage() -> None:
|
||||
elif (version := source_file.parts[4]) in ("v1", "v2"):
|
||||
api = source_file.parts[5]
|
||||
filename = f"test_view_{version}_{api}_{source_file.name}"
|
||||
elif source_file.name.endswith("_guard.py"):
|
||||
filename = f"test_{source_file.name}"
|
||||
else:
|
||||
filename = f"test_view_{source_file.name}"
|
||||
else:
|
||||
|
@ -11,7 +11,7 @@ from ahriman.core.util import walk
|
||||
from ahriman.web.routes import _dynamic_routes, _module, _modules, setup_routes
|
||||
|
||||
|
||||
def test_dynamic_routes(resource_path_root: Path) -> None:
|
||||
def test_dynamic_routes(resource_path_root: Path, configuration: Configuration) -> None:
|
||||
"""
|
||||
must return all available routes
|
||||
"""
|
||||
@ -19,10 +19,10 @@ def test_dynamic_routes(resource_path_root: Path) -> None:
|
||||
expected_views = [
|
||||
file
|
||||
for file in walk(views_root)
|
||||
if file.suffix == ".py" and file.name not in ("__init__.py", "base.py")
|
||||
if file.suffix == ".py" and file.name not in ("__init__.py", "base.py", "status_view_guard.py")
|
||||
]
|
||||
|
||||
routes = _dynamic_routes(views_root)
|
||||
routes = _dynamic_routes(views_root, configuration)
|
||||
assert all(isinstance(view, type) for view in routes.values())
|
||||
assert len(set(routes.values())) == len(expected_views)
|
||||
|
||||
@ -74,5 +74,5 @@ def test_setup_routes(application: Application, configuration: Configuration) ->
|
||||
"""
|
||||
must generate non-empty list of routes
|
||||
"""
|
||||
setup_routes(application, configuration.getpath("web", "static_path"))
|
||||
setup_routes(application, configuration)
|
||||
assert application.router.routes()
|
||||
|
19
tests/ahriman/web/views/test_status_view_guard.py
Normal file
19
tests/ahriman/web/views/test_status_view_guard.py
Normal file
@ -0,0 +1,19 @@
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
|
||||
def test_routes(configuration: Configuration) -> None:
|
||||
"""
|
||||
must correctly return routes list
|
||||
"""
|
||||
StatusViewGuard.ROUTES = routes = ["route1", "route2"]
|
||||
assert StatusViewGuard.routes(configuration) == routes
|
||||
|
||||
|
||||
def test_routes_empty(configuration: Configuration) -> None:
|
||||
"""
|
||||
must return empty routes list if option is set
|
||||
"""
|
||||
StatusViewGuard.ROUTES = ["route1", "route2"]
|
||||
configuration.set_option("web", "service_only", "yes")
|
||||
assert StatusViewGuard.routes(configuration) == []
|
@ -6,6 +6,7 @@ from aiohttp.web import HTTPBadRequest, HTTPNotFound
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.models.repository_id import RepositoryId
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
@ -69,6 +70,15 @@ async def test_get_permission(base: BaseView) -> None:
|
||||
assert await base.get_permission(request) == UserAccess.Unauthorized
|
||||
|
||||
|
||||
def test_get_routes(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return list of available routes
|
||||
"""
|
||||
routes = ["route1", "route2"]
|
||||
mocker.patch.object(BaseView, "ROUTES", routes)
|
||||
assert BaseView.routes(configuration) == routes
|
||||
|
||||
|
||||
def test_get_non_empty() -> None:
|
||||
"""
|
||||
must correctly extract non-empty values
|
||||
|
Reference in New Issue
Block a user