85 lines
2.9 KiB
Python
85 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Focused offline tests for the model-oriented Radarr overlay."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import sys
|
|
import types
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
SOURCE = Path(__file__).parents[1] / "platform/mcp/patches/mcp_radarr.py"
|
|
|
|
|
|
def load_module():
|
|
fastmcp = types.ModuleType("fastmcp")
|
|
fastmcp.FastMCP = object
|
|
sys.modules["fastmcp"] = fastmcp
|
|
pydantic = types.ModuleType("pydantic")
|
|
pydantic.Field = lambda *args, **kwargs: kwargs.get("default")
|
|
sys.modules["pydantic"] = pydantic
|
|
auth = types.ModuleType("arr_mcp.auth")
|
|
auth.get_radarr_client = lambda: None
|
|
sys.modules["arr_mcp"] = types.ModuleType("arr_mcp")
|
|
sys.modules["arr_mcp.auth"] = auth
|
|
spec = importlib.util.spec_from_file_location("radarr_patch", SOURCE)
|
|
module = importlib.util.module_from_spec(spec)
|
|
assert spec.loader
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
class RadarrPatchTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.module = load_module()
|
|
self.movies = [{
|
|
"id": 12, "title": "Example", "year": 2024, "hasFile": True,
|
|
"alternateTitles": [{"title": "large unwanted block"}],
|
|
"movieFile": {
|
|
"id": 44, "relativePath": "Example.mkv", "size": 2147483648,
|
|
"quality": {"quality": {"name": "Bluray-1080p"}},
|
|
"mediaInfo": {
|
|
"videoCodec": "x264", "resolution": "1920x1080",
|
|
"videoBitDepth": 8, "audioCodec": "EAC3",
|
|
"audioLanguages": "ger/eng", "subtitles": "ger",
|
|
},
|
|
},
|
|
}]
|
|
|
|
def test_inventory_is_compact_and_alias_aware(self):
|
|
result = self.module._compact_inventory(self.movies, codecs="h264")
|
|
self.assertEqual(result["totalMatched"], 1)
|
|
self.assertEqual(result["movies"][0]["videoCodec"], "x264")
|
|
self.assertEqual(result["movies"][0]["sizeGiB"], 2.0)
|
|
self.assertNotIn("alternateTitles", result["movies"][0])
|
|
|
|
def test_filter_and_pagination_return_valid_bounded_data(self):
|
|
result = self.module._compact_inventory(self.movies * 5, query="example", offset=1, limit=2)
|
|
self.assertEqual(result["returned"], 2)
|
|
self.assertTrue(result["hasMore"])
|
|
|
|
def test_surface_has_only_explicit_read_tools(self):
|
|
class FakeMcp:
|
|
def __init__(self):
|
|
self.names = []
|
|
|
|
def tool(self, **_kwargs):
|
|
def decorate(function):
|
|
self.names.append(function.__name__)
|
|
return function
|
|
return decorate
|
|
|
|
mcp = FakeMcp()
|
|
self.module.register_radarr_tools(mcp)
|
|
self.assertEqual(
|
|
mcp.names,
|
|
["radarr_find_movie", "radarr_movie_codec_inventory", "radarr_search_releases"],
|
|
)
|
|
self.assertNotIn("radarr_action", mcp.names)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|