forked from HomeLab/unraid-mcp
- ApiKeyVerifier(TokenVerifier) — validates Authorization: Bearer <key> against UNRAID_MCP_API_KEY; guards against empty-key bypass - _build_auth() replaces module-level _build_google_auth() call: returns MultiAuth(server=google, verifiers=[api_key]) when both set, GoogleProvider alone, ApiKeyVerifier alone, or None - settings.py: add UNRAID_MCP_API_KEY + is_api_key_auth_configured() + api_key_auth_enabled in get_config_summary() - run_server(): improved auth status logging for all three states - tests/test_api_key_auth.py: 9 tests covering verifier + _build_auth - .env.example: add UNRAID_MCP_API_KEY section - docs/GOOGLE_OAUTH.md: add API Key section - README.md / CLAUDE.md: rename section, document both auth methods - Fix pre-existing: test_health.py patched cache_middleware/error_middleware now match renamed _cache_middleware/_error_middleware in server.py
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
# tests/test_customization.py
|
|
"""Tests for customization subactions of the consolidated unraid tool."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
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
|