/
/
/
1"""
2Tests for the set_repeat MCP tool.
3
4Validates that:
51. Valid repeat_mode values (off/one/all) are accepted and forwarded to MA.
62. Invalid repeat_mode values raise a clean ToolError.
7"""
8
9from __future__ import annotations
10
11from unittest.mock import MagicMock
12
13import pytest
14from fastmcp import Client, FastMCP
15from fastmcp.exceptions import ToolError
16from music_assistant_models.enums import RepeatMode
17
18
19async def test_set_repeat_accepts_valid_modes(mounted_queue: FastMCP, mock_mass: MagicMock) -> None:
20 """Each valid repeat_mode value is accepted and forwarded to MA."""
21 for mode in ("off", "one", "all"):
22 mock_mass.player_queues.set_repeat.reset_mock()
23 async with Client(mounted_queue) as client:
24 await client.call_tool("queue_set_repeat", {"queue_id": "q1", "repeat_mode": mode})
25 mock_mass.player_queues.set_repeat.assert_called_once_with("q1", RepeatMode(mode))
26
27
28async def test_set_repeat_accepts_mixed_case(mounted_queue: FastMCP, mock_mass: MagicMock) -> None:
29 """repeat_mode is normalized to lowercase before validation."""
30 mock_mass.player_queues.set_repeat.reset_mock()
31 async with Client(mounted_queue) as client:
32 await client.call_tool("queue_set_repeat", {"queue_id": "q1", "repeat_mode": "ALL"})
33 mock_mass.player_queues.set_repeat.assert_called_once_with("q1", RepeatMode.ALL)
34
35
36async def test_set_repeat_rejects_invalid_mode(mounted_queue: FastMCP) -> None:
37 """Invalid repeat_mode raises ToolError with the list of valid options."""
38 async with Client(mounted_queue) as client:
39 with pytest.raises(ToolError, match="bogus"):
40 await client.call_tool("queue_set_repeat", {"queue_id": "q1", "repeat_mode": "bogus"})
41
42
43async def test_set_repeat_defaults_to_off(mounted_queue: FastMCP, mock_mass: MagicMock) -> None:
44 """Calling set_repeat without repeat_mode defaults to 'off'."""
45 mock_mass.player_queues.set_repeat.reset_mock()
46 async with Client(mounted_queue) as client:
47 await client.call_tool("queue_set_repeat", {"queue_id": "q1"})
48 mock_mass.player_queues.set_repeat.assert_called_once_with("q1", RepeatMode.OFF)
49