mirror of
https://github.com/jmagar/unraid-mcp.git
synced 2026-03-23 12:39:24 -07:00
Threads 1, 2, 3 — test hygiene:
- Move elicit_and_configure/elicit_reset_confirmation to module-level imports
in unraid.py so tests can patch at unraid_mcp.tools.unraid.* (thread 2)
- Add return type annotations to _make_tool() in test_customization.py (thread 1)
- Replace unused _mock_ensure_started fixture params with @usefixtures (thread 3)
Thread 4 — remove dead 'connect' subaction from _SYSTEM_QUERIES; the subaction
was always rejected with a ToolError, creating an inconsistent contract.
Thread 5 — centralize two inline "query { online }" strings by reusing
_SYSTEM_QUERIES["online"]; add _DOCKER_QUERIES["_resolve"] for container-name
resolution instead of an inline query literal.
Threads 14, 15, 16, 17, 18 — test improvements:
- test-tools.sh: reword header to "broad non-destructive smoke coverage" (t14)
- test-tools.sh: add _json_payload() helper using jq --arg for safe JSON
construction; replace all printf-based payloads (thread 15)
- test_input_validation.py: add return type annotations to _make_tool and all
nested _run_test coroutines (thread 16)
- test_query_validation.py: extract _all_domain_dicts() shared helper to
eliminate the duplicate 22-item registry (thread 17)
- test_query_validation.py: tighten regression threshold from 50 → 90 (thread 18)
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
# tests/test_customization.py
|
|
"""Tests for customization subactions of the consolidated unraid tool."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
from conftest import make_tool_fn
|
|
|
|
|
|
@pytest.fixture
|
|
def _mock_graphql():
|
|
with patch("unraid_mcp.tools.unraid.make_graphql_request", new_callable=AsyncMock) as m:
|
|
yield m
|
|
|
|
|
|
def _make_tool() -> Any:
|
|
return make_tool_fn("unraid_mcp.tools.unraid", "register_unraid_tool", "unraid")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_theme_returns_customization(_mock_graphql):
|
|
_mock_graphql.return_value = {
|
|
"customization": {"theme": {"name": "azure"}, "partnerInfo": None, "activationCode": None}
|
|
}
|
|
result = await _make_tool()(action="customization", subaction="theme")
|
|
assert result["customization"]["theme"]["name"] == "azure"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_public_theme(_mock_graphql):
|
|
_mock_graphql.return_value = {"publicTheme": {"name": "black"}}
|
|
result = await _make_tool()(action="customization", subaction="public_theme")
|
|
assert result["publicTheme"]["name"] == "black"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_is_initial_setup(_mock_graphql):
|
|
_mock_graphql.return_value = {"isInitialSetup": False}
|
|
result = await _make_tool()(action="customization", subaction="is_initial_setup")
|
|
assert result["isInitialSetup"] is False
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_set_theme_requires_theme(_mock_graphql):
|
|
from unraid_mcp.core.exceptions import ToolError
|
|
|
|
with pytest.raises(ToolError, match="theme_name"):
|
|
await _make_tool()(action="customization", subaction="set_theme")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_set_theme_success(_mock_graphql):
|
|
_mock_graphql.return_value = {
|
|
"customization": {"setTheme": {"name": "azure", "showBannerImage": True}}
|
|
}
|
|
result = await _make_tool()(action="customization", subaction="set_theme", theme_name="azure")
|
|
assert result["success"] is True
|