mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-01-26 07:59:47 +00:00
* feat: add openmetrics support & endpoint * add support of named resources * update docstrings * generate docs * add another test for http api
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from aiohttp.web import Application
|
|
from pathlib import Path
|
|
|
|
from ahriman.core.configuration import Configuration
|
|
from ahriman.core.utils import walk
|
|
from ahriman.web.routes import _dynamic_routes, _identifier, setup_routes
|
|
|
|
|
|
def test_dynamic_routes(resource_path_root: Path, configuration: Configuration) -> None:
|
|
"""
|
|
must return all available routes
|
|
"""
|
|
views_root = resource_path_root / ".." / ".." / "src" / "ahriman" / "web" / "views"
|
|
expected_views = [
|
|
file
|
|
for file in walk(views_root)
|
|
if file.suffix == ".py" and file.name not in ("__init__.py", "base.py", "status_view_guard.py")
|
|
]
|
|
|
|
routes = dict(_dynamic_routes(configuration))
|
|
assert all(isinstance(view, type) for view in routes.values())
|
|
assert len(set(routes.values())) == len(expected_views)
|
|
|
|
|
|
def test_identifier() -> None:
|
|
"""
|
|
must correctly extract route identifiers
|
|
"""
|
|
assert _identifier("/") == "_"
|
|
assert _identifier("/api/v1/status") == "_api_v1_status"
|
|
assert _identifier("/api/v1/packages/{package}") == "_api_v1_packages_:package"
|
|
|
|
|
|
def test_setup_routes(application: Application, configuration: Configuration) -> None:
|
|
"""
|
|
must generate non-empty list of routes
|
|
"""
|
|
application.router._named_resources = {}
|
|
setup_routes(application, configuration)
|
|
assert application.router.routes()
|