|
| 1 | +"""Test MCP server configuration and metadata.""" |
| 2 | + |
| 3 | +from mcp.types import Icon |
| 4 | + |
| 5 | + |
| 6 | +class TestServerIcons: |
| 7 | + """Verify server icon configuration meets MCP requirements.""" |
| 8 | + |
| 9 | + def test_server_icons_defined(self): |
| 10 | + """Check that SERVER_ICONS is defined and properly structured.""" |
| 11 | + from ha_mcp.server import SERVER_ICONS |
| 12 | + |
| 13 | + assert SERVER_ICONS is not None, "SERVER_ICONS must be defined" |
| 14 | + assert isinstance(SERVER_ICONS, list), "SERVER_ICONS must be a list" |
| 15 | + assert len(SERVER_ICONS) > 0, "SERVER_ICONS must contain at least one icon" |
| 16 | + |
| 17 | + def test_icons_are_valid_mcp_icon_types(self): |
| 18 | + """Check that all icons are valid MCP Icon objects.""" |
| 19 | + from ha_mcp.server import SERVER_ICONS |
| 20 | + |
| 21 | + for i, icon in enumerate(SERVER_ICONS): |
| 22 | + assert isinstance(icon, Icon), f"Icon at index {i} must be an mcp.types.Icon" |
| 23 | + |
| 24 | + def test_icons_have_required_fields(self): |
| 25 | + """Check that all icons have required 'src' field.""" |
| 26 | + from ha_mcp.server import SERVER_ICONS |
| 27 | + |
| 28 | + for i, icon in enumerate(SERVER_ICONS): |
| 29 | + assert icon.src, f"Icon at index {i} must have a non-empty 'src' field" |
| 30 | + # src should be a URL pointing to GitHub raw content |
| 31 | + assert icon.src.startswith("https://"), "Icon src must be an HTTPS URL" |
| 32 | + |
| 33 | + def test_icons_have_valid_mime_types(self): |
| 34 | + """Check that icons have valid MIME types when specified.""" |
| 35 | + from ha_mcp.server import SERVER_ICONS |
| 36 | + |
| 37 | + valid_image_types = {"image/png", "image/svg+xml", "image/jpeg", "image/webp"} |
| 38 | + for i, icon in enumerate(SERVER_ICONS): |
| 39 | + if icon.mimeType: |
| 40 | + assert icon.mimeType in valid_image_types, ( |
| 41 | + f"Icon at index {i} has invalid mimeType: {icon.mimeType}" |
| 42 | + ) |
| 43 | + |
| 44 | + def test_icons_include_svg_format(self): |
| 45 | + """Check that at least one SVG icon is included for scalability.""" |
| 46 | + from ha_mcp.server import SERVER_ICONS |
| 47 | + |
| 48 | + svg_icons = [icon for icon in SERVER_ICONS if icon.mimeType == "image/svg+xml"] |
| 49 | + assert len(svg_icons) > 0, "Should include at least one SVG icon for scalability" |
| 50 | + |
| 51 | + def test_icons_include_raster_format(self): |
| 52 | + """Check that at least one raster icon (PNG) is included for compatibility.""" |
| 53 | + from ha_mcp.server import SERVER_ICONS |
| 54 | + |
| 55 | + raster_icons = [icon for icon in SERVER_ICONS if icon.mimeType == "image/png"] |
| 56 | + assert len(raster_icons) > 0, "Should include at least one PNG icon for compatibility" |
| 57 | + |
| 58 | + def test_icon_urls_point_to_correct_repository(self): |
| 59 | + """Check that icon URLs point to the ha-mcp repository.""" |
| 60 | + from ha_mcp.server import SERVER_ICONS |
| 61 | + |
| 62 | + expected_base = "https://raw.githubusercontent.com/homeassistant-ai/ha-mcp/" |
| 63 | + for i, icon in enumerate(SERVER_ICONS): |
| 64 | + assert icon.src.startswith(expected_base), ( |
| 65 | + f"Icon at index {i} should point to homeassistant-ai/ha-mcp repository" |
| 66 | + ) |
0 commit comments