diff options
Diffstat (limited to 'tests/test_models.py')
| -rw-r--r-- | tests/test_models.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/tests/test_models.py b/tests/test_models.py index 8cc2738..177b86b 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -2,6 +2,8 @@ from __future__ import annotations +from unittest.mock import patch + from starlette.testclient import TestClient from ollama_web.app import create_app @@ -14,6 +16,17 @@ def _login_client(client: TestClient) -> str: return str(login.headers["x-csrf-token"]) +class _FakeClient: + def __init__(self, capabilities: list[str] | None = None) -> None: + self._capabilities = capabilities or [] + + def show(self, _model: str) -> dict[str, list[str]]: + return {"capabilities": self._capabilities} + + def list(self) -> dict[str, list[dict[str, str]]]: + return {"models": []} + + def test_model_capabilities_route_supports_slash_in_model_name() -> None: """HuggingFace-style model names contain slashes and must reach the API. @@ -21,11 +34,12 @@ def test_model_capabilities_route_supports_slash_in_model_name() -> None: so the route uses the ``path`` converter. Encoding ``%2F`` must decode to the full model name, not split the URL into multiple segments. """ - with TestClient(create_app()) as client: - csrf = _login_client(client) + slash_model = "hf.co/hotdogs/gemma-4-E4B-it-ultra-uncensored-heretic-GGUF:Q5_K_M" + encoded = slash_model.replace("/", "%2F").replace(":", "%3A") + fake = _FakeClient(["completion", "vision", "tools", "thinking"]) - slash_model = "hf.co/hotdogs/gemma-4-E4B-it-ultra-uncensored-heretic-GGUF:Q5_K_M" - encoded = slash_model.replace("/", "%2F").replace(":", "%3A") + with patch("ollama_web.llm.get_client", return_value=fake), TestClient(create_app()) as client: + csrf = _login_client(client) response = client.get( f"/api/models/{encoded}/capabilities", headers={"X-CSRF-Token": csrf}, @@ -41,9 +55,10 @@ def test_model_capabilities_route_supports_slash_in_model_name() -> None: def test_model_capabilities_route_still_works_without_slashes() -> None: """Model names without slashes (e.g. cloud aliases) must keep working.""" - with TestClient(create_app()) as client: - csrf = _login_client(client) + fake = _FakeClient(["completion"]) + with patch("ollama_web.llm.get_client", return_value=fake), TestClient(create_app()) as client: + csrf = _login_client(client) response = client.get( "/api/models/glm-5.2%3Acloud/capabilities", headers={"X-CSRF-Token": csrf}, @@ -51,4 +66,4 @@ def test_model_capabilities_route_still_works_without_slashes() -> None: assert response.status_code == 200 payload = response.json() assert "capabilities" in payload - assert "completion" in [c.lower() for c in payload["capabilities"]] + assert "completion" in [c.lower() for c in payload["capabilities"]]
\ No newline at end of file |
