mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Sonos add tests for media_player.play_media share link (#120169)
This commit is contained in:
parent
28eef00cce
commit
3cf52a4767
@ -237,6 +237,17 @@ def patch_gethostbyname(host: str) -> str:
|
|||||||
return host
|
return host
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="soco_sharelink")
|
||||||
|
def soco_sharelink():
|
||||||
|
"""Fixture to mock soco.plugins.sharelink.ShareLinkPlugin."""
|
||||||
|
with patch("homeassistant.components.sonos.speaker.ShareLinkPlugin") as mock_share:
|
||||||
|
mock_instance = MagicMock()
|
||||||
|
mock_instance.is_share_link.return_value = True
|
||||||
|
mock_instance.add_share_link_to_queue.return_value = 10
|
||||||
|
mock_share.return_value = mock_instance
|
||||||
|
yield mock_instance
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="soco_factory")
|
@pytest.fixture(name="soco_factory")
|
||||||
def soco_factory(
|
def soco_factory(
|
||||||
music_library, speaker_info, current_track_info_empty, battery_info, alarm_clock
|
music_library, speaker_info, current_track_info_empty, battery_info, alarm_clock
|
||||||
|
@ -302,6 +302,134 @@ async def test_play_media_lib_track_add(
|
|||||||
assert soco_mock.play_from_queue.call_count == 0
|
assert soco_mock.play_from_queue.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
|
_share_link: str = "spotify:playlist:abcdefghij0123456789XY"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_play_media_share_link_add(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
soco_factory: SoCoMockFactory,
|
||||||
|
async_autosetup_sonos,
|
||||||
|
soco_sharelink,
|
||||||
|
) -> None:
|
||||||
|
"""Tests playing a share link with enqueue option add."""
|
||||||
|
await hass.services.async_call(
|
||||||
|
MP_DOMAIN,
|
||||||
|
SERVICE_PLAY_MEDIA,
|
||||||
|
{
|
||||||
|
"entity_id": "media_player.zone_a",
|
||||||
|
"media_content_type": "playlist",
|
||||||
|
"media_content_id": _share_link,
|
||||||
|
ATTR_MEDIA_ENQUEUE: MediaPlayerEnqueue.ADD,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert soco_sharelink.add_share_link_to_queue.call_count == 1
|
||||||
|
assert (
|
||||||
|
soco_sharelink.add_share_link_to_queue.call_args_list[0].args[0] == _share_link
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
soco_sharelink.add_share_link_to_queue.call_args_list[0].kwargs["timeout"]
|
||||||
|
== LONG_SERVICE_TIMEOUT
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_play_media_share_link_next(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
soco_factory: SoCoMockFactory,
|
||||||
|
async_autosetup_sonos,
|
||||||
|
soco_sharelink,
|
||||||
|
) -> None:
|
||||||
|
"""Tests playing a share link with enqueue option next."""
|
||||||
|
await hass.services.async_call(
|
||||||
|
MP_DOMAIN,
|
||||||
|
SERVICE_PLAY_MEDIA,
|
||||||
|
{
|
||||||
|
"entity_id": "media_player.zone_a",
|
||||||
|
"media_content_type": "playlist",
|
||||||
|
"media_content_id": _share_link,
|
||||||
|
ATTR_MEDIA_ENQUEUE: MediaPlayerEnqueue.NEXT,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert soco_sharelink.add_share_link_to_queue.call_count == 1
|
||||||
|
assert (
|
||||||
|
soco_sharelink.add_share_link_to_queue.call_args_list[0].args[0] == _share_link
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
soco_sharelink.add_share_link_to_queue.call_args_list[0].kwargs["timeout"]
|
||||||
|
== LONG_SERVICE_TIMEOUT
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
soco_sharelink.add_share_link_to_queue.call_args_list[0].kwargs["position"] == 1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_play_media_share_link_play(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
soco_factory: SoCoMockFactory,
|
||||||
|
async_autosetup_sonos,
|
||||||
|
soco_sharelink,
|
||||||
|
) -> None:
|
||||||
|
"""Tests playing a share link with enqueue option play."""
|
||||||
|
soco_mock = soco_factory.mock_list.get("192.168.42.2")
|
||||||
|
await hass.services.async_call(
|
||||||
|
MP_DOMAIN,
|
||||||
|
SERVICE_PLAY_MEDIA,
|
||||||
|
{
|
||||||
|
"entity_id": "media_player.zone_a",
|
||||||
|
"media_content_type": "playlist",
|
||||||
|
"media_content_id": _share_link,
|
||||||
|
ATTR_MEDIA_ENQUEUE: MediaPlayerEnqueue.PLAY,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert soco_sharelink.add_share_link_to_queue.call_count == 1
|
||||||
|
assert (
|
||||||
|
soco_sharelink.add_share_link_to_queue.call_args_list[0].args[0] == _share_link
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
soco_sharelink.add_share_link_to_queue.call_args_list[0].kwargs["timeout"]
|
||||||
|
== LONG_SERVICE_TIMEOUT
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
soco_sharelink.add_share_link_to_queue.call_args_list[0].kwargs["position"] == 1
|
||||||
|
)
|
||||||
|
assert soco_mock.play_from_queue.call_count == 1
|
||||||
|
soco_mock.play_from_queue.assert_called_with(9)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_play_media_share_link_replace(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
soco_factory: SoCoMockFactory,
|
||||||
|
async_autosetup_sonos,
|
||||||
|
soco_sharelink,
|
||||||
|
) -> None:
|
||||||
|
"""Tests playing a share link with enqueue option replace."""
|
||||||
|
soco_mock = soco_factory.mock_list.get("192.168.42.2")
|
||||||
|
await hass.services.async_call(
|
||||||
|
MP_DOMAIN,
|
||||||
|
SERVICE_PLAY_MEDIA,
|
||||||
|
{
|
||||||
|
"entity_id": "media_player.zone_a",
|
||||||
|
"media_content_type": "playlist",
|
||||||
|
"media_content_id": _share_link,
|
||||||
|
ATTR_MEDIA_ENQUEUE: MediaPlayerEnqueue.REPLACE,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert soco_mock.clear_queue.call_count == 1
|
||||||
|
assert soco_sharelink.add_share_link_to_queue.call_count == 1
|
||||||
|
assert (
|
||||||
|
soco_sharelink.add_share_link_to_queue.call_args_list[0].args[0] == _share_link
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
soco_sharelink.add_share_link_to_queue.call_args_list[0].kwargs["timeout"]
|
||||||
|
== LONG_SERVICE_TIMEOUT
|
||||||
|
)
|
||||||
|
assert soco_mock.play_from_queue.call_count == 1
|
||||||
|
soco_mock.play_from_queue.assert_called_with(0)
|
||||||
|
|
||||||
|
|
||||||
_mock_playlists = [
|
_mock_playlists = [
|
||||||
MockMusicServiceItem(
|
MockMusicServiceItem(
|
||||||
"playlist1",
|
"playlist1",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user