mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 09:17:10 +00:00
tests
This commit is contained in:
parent
75ae985b39
commit
33e9c79c9b
@ -753,7 +753,8 @@ class SqueezeBoxMediaPlayerEntity(
|
|||||||
case _:
|
case _:
|
||||||
_param = [
|
_param = [
|
||||||
command + "s",
|
command + "s",
|
||||||
"items0",
|
"items",
|
||||||
|
"0",
|
||||||
"1",
|
"1",
|
||||||
"search:" + search_string if search_string is not None else "",
|
"search:" + search_string if search_string is not None else "",
|
||||||
]
|
]
|
||||||
|
@ -224,6 +224,7 @@ def mock_pysqueezebox_player(uuid: str) -> MagicMock:
|
|||||||
"homeassistant.components.squeezebox.Player", autospec=True
|
"homeassistant.components.squeezebox.Player", autospec=True
|
||||||
) as mock_player:
|
) as mock_player:
|
||||||
mock_player.async_browse = AsyncMock(side_effect=mock_async_browse)
|
mock_player.async_browse = AsyncMock(side_effect=mock_async_browse)
|
||||||
|
mock_player.async_query = AsyncMock(side_effect=mock_async_query)
|
||||||
mock_player.generate_image_url_from_track_id = MagicMock(
|
mock_player.generate_image_url_from_track_id = MagicMock(
|
||||||
return_value="http://lms.internal:9000/html/images/favorites.png"
|
return_value="http://lms.internal:9000/html/images/favorites.png"
|
||||||
)
|
)
|
||||||
@ -246,6 +247,21 @@ def mock_pysqueezebox_player(uuid: str) -> MagicMock:
|
|||||||
return mock_player
|
return mock_player
|
||||||
|
|
||||||
|
|
||||||
|
async def mock_async_query(*parameters: str) -> dict[str, str | int] | None:
|
||||||
|
"""Return a result, currently used by generate _playlist."""
|
||||||
|
_cmds = ("album", "genre", "playlist", "artist", "track", "favorite")
|
||||||
|
_loop = ""
|
||||||
|
for _cmd in _cmds:
|
||||||
|
for _param in parameters:
|
||||||
|
if _cmd in _param:
|
||||||
|
if _cmd == "favorite":
|
||||||
|
_loop = "loop_loop"
|
||||||
|
else:
|
||||||
|
_loop = _cmd + "s_loop"
|
||||||
|
break
|
||||||
|
return {_loop: [{"id": FAKE_VALID_ITEM_ID, "title": "Fake Item 1"}], "count": 1}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def lms_factory(player_factory: MagicMock) -> MagicMock:
|
def lms_factory(player_factory: MagicMock) -> MagicMock:
|
||||||
"""Return a factory for creating mock Lyrion Media Servers with arbitrary number of players."""
|
"""Return a factory for creating mock Lyrion Media Servers with arbitrary number of players."""
|
||||||
|
@ -829,6 +829,100 @@ async def test_squeezebox_play_other_item(
|
|||||||
assert configured_player.async_load_playlist.call_count == 3
|
assert configured_player.async_load_playlist.call_count == 3
|
||||||
|
|
||||||
|
|
||||||
|
async def test_squeezebox_play_other_text(
|
||||||
|
hass: HomeAssistant, configured_player: MagicMock
|
||||||
|
) -> None:
|
||||||
|
"""Test query service call."""
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_PLAY,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: "media_player.test_player",
|
||||||
|
ATTR_COMMAND: "album",
|
||||||
|
ATTR_SEARCH_TYPE: "text",
|
||||||
|
ATTR_SEARCH_STRING: "Fake Item 1",
|
||||||
|
ATTR_PLAYLIST_ACTION: "play",
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert configured_player.async_load_playlist.call_count == 1
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_PLAY,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: "media_player.test_player",
|
||||||
|
ATTR_COMMAND: "album",
|
||||||
|
ATTR_SEARCH_TYPE: "text",
|
||||||
|
ATTR_SEARCH_STRING: "Fake Item 1",
|
||||||
|
ATTR_PLAYLIST_ACTION: "add",
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert configured_player.async_load_playlist.call_count == 2
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_PLAY,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: "media_player.test_player",
|
||||||
|
ATTR_COMMAND: "album",
|
||||||
|
ATTR_SEARCH_TYPE: "text",
|
||||||
|
ATTR_SEARCH_STRING: "Fake Item 1",
|
||||||
|
ATTR_PLAYLIST_ACTION: "next",
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert configured_player.async_load_playlist.call_count == 3
|
||||||
|
|
||||||
|
|
||||||
|
async def test_squeezebox_play_favorite_text(
|
||||||
|
hass: HomeAssistant, configured_player: MagicMock
|
||||||
|
) -> None:
|
||||||
|
"""Test query service call."""
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_PLAY,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: "media_player.test_player",
|
||||||
|
ATTR_COMMAND: "favorite",
|
||||||
|
ATTR_SEARCH_TYPE: "text",
|
||||||
|
ATTR_SEARCH_STRING: "Fake Item 1",
|
||||||
|
ATTR_PLAYLIST_ACTION: "play",
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert configured_player.async_load_playlist.call_count == 1
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_PLAY,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: "media_player.test_player",
|
||||||
|
ATTR_COMMAND: "favorite",
|
||||||
|
ATTR_SEARCH_TYPE: "text",
|
||||||
|
ATTR_SEARCH_STRING: "Fake Item 1",
|
||||||
|
ATTR_PLAYLIST_ACTION: "add",
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert configured_player.async_load_playlist.call_count == 2
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_PLAY,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: "media_player.test_player",
|
||||||
|
ATTR_COMMAND: "favorite",
|
||||||
|
ATTR_SEARCH_TYPE: "text",
|
||||||
|
ATTR_SEARCH_STRING: "Fake Item 1",
|
||||||
|
ATTR_PLAYLIST_ACTION: "next",
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert configured_player.async_load_playlist.call_count == 3
|
||||||
|
|
||||||
|
|
||||||
async def test_squeezebox_play_favorite_item(
|
async def test_squeezebox_play_favorite_item(
|
||||||
hass: HomeAssistant, configured_player: MagicMock
|
hass: HomeAssistant, configured_player: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user