mirror of
https://github.com/dw-0/kiauh.git
synced 2026-08-03 04:47:56 +05:00
fix(webui_client): get_existing_clients always returns an empty list
This commit is contained in:
@@ -14,10 +14,10 @@ import shutil
|
|||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import PIPE, CalledProcessError, run
|
from subprocess import PIPE, CalledProcessError, run
|
||||||
from typing import List, get_args
|
from typing import List
|
||||||
|
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from components.webui_client import MODULE_PATH
|
from components.webui_client import CLIENTS, MODULE_PATH
|
||||||
from components.webui_client.base_data import (
|
from components.webui_client.base_data import (
|
||||||
BaseWebClient,
|
BaseWebClient,
|
||||||
BaseWebClientConfig,
|
BaseWebClientConfig,
|
||||||
@@ -230,13 +230,8 @@ def backup_client_config_data(client: BaseWebClient) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def get_existing_clients() -> List[BaseWebClient]:
|
def get_existing_clients() -> List[BaseWebClient]:
|
||||||
clients = list(get_args(WebClientType))
|
clients: List[BaseWebClient] = [bwc() for bwc in CLIENTS.values()]
|
||||||
installed_clients: List[BaseWebClient] = []
|
return [client for client in clients if client.client_dir.exists()]
|
||||||
for client in clients:
|
|
||||||
if client.client_dir.exists():
|
|
||||||
installed_clients.append(client)
|
|
||||||
|
|
||||||
return installed_clients
|
|
||||||
|
|
||||||
|
|
||||||
def detect_client_cfg_conflict(curr_client: BaseWebClient) -> bool:
|
def detect_client_cfg_conflict(curr_client: BaseWebClient) -> bool:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from types import SimpleNamespace
|
||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -14,6 +15,7 @@ from components.webui_client.client_utils import (
|
|||||||
get_client_status,
|
get_client_status,
|
||||||
get_current_client_config,
|
get_current_client_config,
|
||||||
get_download_url,
|
get_download_url,
|
||||||
|
get_existing_clients,
|
||||||
get_local_client_version,
|
get_local_client_version,
|
||||||
get_next_free_port,
|
get_next_free_port,
|
||||||
get_nginx_listen_port,
|
get_nginx_listen_port,
|
||||||
@@ -346,3 +348,56 @@ class TestGetCurrentClientConfig:
|
|||||||
|
|
||||||
result = get_current_client_config()
|
result = get_current_client_config()
|
||||||
assert "Mainsail-Config" in result
|
assert "Mainsail-Config" in result
|
||||||
|
|
||||||
|
|
||||||
|
class TestGetExistingClients:
|
||||||
|
@staticmethod
|
||||||
|
def _client(installed: bool) -> SimpleNamespace:
|
||||||
|
return SimpleNamespace(client_dir=SimpleNamespace(exists=lambda: installed))
|
||||||
|
|
||||||
|
def test_returns_only_installed_clients(self, monkeypatch) -> None:
|
||||||
|
mainsail = self._client(installed=True)
|
||||||
|
fluidd = self._client(installed=False)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
client_utils,
|
||||||
|
"CLIENTS",
|
||||||
|
{"mainsail": lambda: mainsail, "fluidd": lambda: fluidd},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert get_existing_clients() == [mainsail]
|
||||||
|
|
||||||
|
def test_returns_only_fluidd_when_only_fluidd_installed(self, monkeypatch) -> None:
|
||||||
|
mainsail = self._client(installed=False)
|
||||||
|
fluidd = self._client(installed=True)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
client_utils,
|
||||||
|
"CLIENTS",
|
||||||
|
{"mainsail": lambda: mainsail, "fluidd": lambda: fluidd},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert get_existing_clients() == [fluidd]
|
||||||
|
|
||||||
|
def test_returns_both_clients_in_order_when_both_installed(
|
||||||
|
self, monkeypatch
|
||||||
|
) -> None:
|
||||||
|
mainsail = self._client(installed=True)
|
||||||
|
fluidd = self._client(installed=True)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
client_utils,
|
||||||
|
"CLIENTS",
|
||||||
|
{"mainsail": lambda: mainsail, "fluidd": lambda: fluidd},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert get_existing_clients() == [mainsail, fluidd]
|
||||||
|
|
||||||
|
def test_returns_empty_list_when_no_client_installed(self, monkeypatch) -> None:
|
||||||
|
monkeypatch.setattr(
|
||||||
|
client_utils,
|
||||||
|
"CLIENTS",
|
||||||
|
{
|
||||||
|
"mainsail": lambda: self._client(installed=False),
|
||||||
|
"fluidd": lambda: self._client(installed=False),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert get_existing_clients() == []
|
||||||
|
|||||||
Reference in New Issue
Block a user