mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-09-04 07:49:55 +00:00
feat: use split packages (#135)
* move argument parsers to handlers themselves
* use hatchling instead of flit
* Revert "use hatchling instead of flit"
This reverts commit d18d146d79
.
* add package-splitt script
* replace simplify walk method
* split packages
* explicitly install packages
* separate support triggers from main package
* add docs examples
* sort actions
* docs update
* add metapackage
* review fixes
This commit is contained in:
@ -1,14 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from aiohttp.web import Application
|
||||
from importlib.machinery import ModuleSpec
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from types import ModuleType
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.utils import walk
|
||||
from ahriman.web.routes import _dynamic_routes, _module, _modules, setup_routes
|
||||
from ahriman.web.routes import _dynamic_routes, setup_routes
|
||||
|
||||
|
||||
def test_dynamic_routes(resource_path_root: Path, configuration: Configuration) -> None:
|
||||
@ -22,54 +17,11 @@ def test_dynamic_routes(resource_path_root: Path, configuration: Configuration)
|
||||
if file.suffix == ".py" and file.name not in ("__init__.py", "base.py", "status_view_guard.py")
|
||||
]
|
||||
|
||||
routes = _dynamic_routes(views_root, configuration)
|
||||
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_module(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load module
|
||||
"""
|
||||
exec_mock = mocker.patch("importlib.machinery.SourceFileLoader.exec_module")
|
||||
module_info = next(_modules(Path(__file__).parent))
|
||||
|
||||
module = _module(module_info)
|
||||
assert isinstance(module, ModuleType)
|
||||
exec_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_module_no_spec(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise ValueError if spec is not available
|
||||
"""
|
||||
mocker.patch("importlib.machinery.FileFinder.find_spec", return_value=None)
|
||||
module_info = next(_modules(Path(__file__).parent))
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
_module(module_info)
|
||||
|
||||
|
||||
def test_module_no_loader(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise ValueError if loader is not available
|
||||
"""
|
||||
mocker.patch("importlib.machinery.FileFinder.find_spec", return_value=ModuleSpec("name", None))
|
||||
module_info = next(_modules(Path(__file__).parent))
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
_module(module_info)
|
||||
|
||||
|
||||
def test_modules() -> None:
|
||||
"""
|
||||
must load modules
|
||||
"""
|
||||
modules = list(_modules(Path(__file__).parent.parent))
|
||||
assert modules
|
||||
assert all(not module.ispkg for module in modules)
|
||||
|
||||
|
||||
def test_setup_routes(application: Application, configuration: Configuration) -> None:
|
||||
"""
|
||||
must generate non-empty list of routes
|
||||
|
@ -1,6 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from aiohttp.test_utils import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.static import StaticView
|
||||
@ -31,12 +32,11 @@ async def test_get(client_with_auth: TestClient) -> None:
|
||||
assert response.headers["Location"] == "/static/favicon.ico"
|
||||
|
||||
|
||||
async def test_get_not_found(client_with_auth: TestClient) -> None:
|
||||
async def test_get_not_found(client_with_auth: TestClient, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise not found if path is invalid
|
||||
"""
|
||||
for route in client_with_auth.app.router.routes():
|
||||
if hasattr(route.handler, "ROUTES"):
|
||||
route.handler.ROUTES = []
|
||||
static_route = next(route for route in client_with_auth.app.router.routes() if route.handler == StaticView)
|
||||
mocker.patch.object(static_route.handler, "ROUTES", [])
|
||||
response = await client_with_auth.get("/favicon.ico", allow_redirects=False)
|
||||
assert response.status == 404
|
||||
|
Reference in New Issue
Block a user