forked from clan/clan-core
Merge pull request 'API: add performance constraints' (#1685) from hsjobeki/clan-core:hsjobeki-main into main
This commit is contained in:
commit
c4bbdb2212
@ -104,21 +104,24 @@ def get_modules(base_path: str) -> dict[str, str]:
|
|||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def list_modules(base_path: str) -> list[str]:
|
def list_modules(base_path: str) -> dict[str, ModuleInfo]:
|
||||||
"""
|
"""
|
||||||
Show information about a module
|
Show information about a module
|
||||||
"""
|
"""
|
||||||
modules = get_modules(base_path)
|
modules = get_modules(base_path)
|
||||||
return [m for m in modules.keys()]
|
return {
|
||||||
|
module_name: get_module_info(module_name, module_path)
|
||||||
|
for module_name, module_path in modules.items()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@API.register
|
def get_module_info(
|
||||||
def show_module_info(base_path: str, module_name: str) -> ModuleInfo:
|
module_name: str,
|
||||||
|
module_path: str,
|
||||||
|
) -> ModuleInfo:
|
||||||
"""
|
"""
|
||||||
Show information about a module
|
Retrieves information about a module
|
||||||
"""
|
"""
|
||||||
modules = get_modules(base_path)
|
|
||||||
module_path = modules.get(module_name, None)
|
|
||||||
if not module_path:
|
if not module_path:
|
||||||
raise ClanError(
|
raise ClanError(
|
||||||
"Module not found",
|
"Module not found",
|
||||||
|
@ -21,6 +21,7 @@ def test_schema_for_machine(test_flake_with_core: FlakeForTest) -> None:
|
|||||||
@pytest.mark.with_core
|
@pytest.mark.with_core
|
||||||
def test_create_machine_on_minimal_clan(test_flake_minimal: FlakeForTest) -> None:
|
def test_create_machine_on_minimal_clan(test_flake_minimal: FlakeForTest) -> None:
|
||||||
assert list_machines(test_flake_minimal.path) == {}
|
assert list_machines(test_flake_minimal.path) == {}
|
||||||
|
|
||||||
create_machine(
|
create_machine(
|
||||||
test_flake_minimal.path,
|
test_flake_minimal.path,
|
||||||
Machine(
|
Machine(
|
||||||
@ -31,7 +32,9 @@ def test_create_machine_on_minimal_clan(test_flake_minimal: FlakeForTest) -> Non
|
|||||||
icon=None,
|
icon=None,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
assert list(list_machines(test_flake_minimal.path).keys()) == ["foo"]
|
|
||||||
|
result = list_machines(test_flake_minimal.path)
|
||||||
|
assert list(result.keys()) == ["foo"]
|
||||||
|
|
||||||
# Writes into settings.json
|
# Writes into settings.json
|
||||||
set_config_for_machine(
|
set_config_for_machine(
|
||||||
|
@ -1,27 +1,15 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from fixtures_flakes import FlakeForTest
|
from fixtures_flakes import FlakeForTest
|
||||||
|
|
||||||
from clan_cli.api.modules import list_modules, show_module_info
|
from clan_cli.api.modules import list_modules
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.with_core
|
@pytest.mark.with_core
|
||||||
def test_list_modules(test_flake_with_core: FlakeForTest) -> None:
|
def test_list_modules(test_flake_with_core: FlakeForTest) -> None:
|
||||||
base_path = test_flake_with_core.path
|
base_path = test_flake_with_core.path
|
||||||
module_list = list_modules(base_path)
|
modules_info = list_modules(base_path)
|
||||||
assert isinstance(module_list, list)
|
|
||||||
assert len(module_list) > 1
|
assert len(modules_info.items()) > 1
|
||||||
# Random test for those two modules
|
# Random test for those two modules
|
||||||
assert "borgbackup" in module_list
|
assert "borgbackup" in modules_info.keys()
|
||||||
assert "syncthing" in module_list
|
assert "syncthing" in modules_info.keys()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.with_core
|
|
||||||
def test_modules_details(test_flake_with_core: FlakeForTest) -> None:
|
|
||||||
base_path = test_flake_with_core.path
|
|
||||||
test_module = "borgbackup"
|
|
||||||
module_info = show_module_info(base_path, test_module)
|
|
||||||
assert module_info.description is not None and module_info.description != ""
|
|
||||||
assert module_info.categories and "backup" in module_info.categories
|
|
||||||
assert module_info.roles
|
|
||||||
assert set(module_info.roles) == {"server", "client"}
|
|
||||||
assert module_info.readme is not None and module_info.readme != ""
|
|
||||||
|
Loading…
Reference in New Issue
Block a user