Skip to content

Commit

Permalink
Add test for Spotify select source (home-assistant#128160)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Oct 11, 2024
1 parent 9ff35d5 commit d507581
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/components/spotify/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def mock_spotify() -> Generator[MagicMock]:
client.current_user.return_value = current_user
client.me.return_value = current_user
for fixture, method in (
("devices.json", "devices"),
("current_user_playlist.json", "current_user_playlists"),
("playback.json", "current_playback"),
("followed_artists.json", "current_user_followed_artists"),
Expand Down
14 changes: 14 additions & 0 deletions tests/components/spotify/fixtures/devices.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"devices": [
{
"id": "21dac6b0e0a1f181870fdc9749b2656466557666",
"is_active": false,
"is_private_session": false,
"is_restricted": false,
"name": "DESKTOP-BKC5SIK",
"supports_volume": true,
"type": "Computer",
"volume_percent": 69
}
]
}
12 changes: 12 additions & 0 deletions tests/components/spotify/snapshots/test_media_player.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
}),
'area_id': None,
'capabilities': dict({
'source_list': list([
'DESKTOP-BKC5SIK',
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
Expand Down Expand Up @@ -51,6 +54,9 @@
'repeat': <RepeatMode.OFF: 'off'>,
'shuffle': False,
'source': 'Master Bathroom Speaker',
'source_list': list([
'DESKTOP-BKC5SIK',
]),
'supported_features': <MediaPlayerEntityFeature: 444983>,
'volume_level': 0.25,
}),
Expand All @@ -68,6 +74,9 @@
}),
'area_id': None,
'capabilities': dict({
'source_list': list([
'DESKTOP-BKC5SIK',
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
Expand Down Expand Up @@ -112,6 +121,9 @@
'repeat': <RepeatMode.OFF: 'off'>,
'shuffle': False,
'source': 'Sonos Roam SL',
'source_list': list([
'DESKTOP-BKC5SIK',
]),
'supported_features': <MediaPlayerEntityFeature: 2048>,
'volume_level': 0.46,
}),
Expand Down
24 changes: 24 additions & 0 deletions tests/components/spotify/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from syrupy import SnapshotAssertion

from homeassistant.components.media_player import (
ATTR_INPUT_SOURCE,
ATTR_MEDIA_CONTENT_ID,
ATTR_MEDIA_CONTENT_TYPE,
ATTR_MEDIA_ENQUEUE,
Expand All @@ -16,6 +17,7 @@
ATTR_MEDIA_VOLUME_LEVEL,
DOMAIN as MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
SERVICE_SELECT_SOURCE,
MediaPlayerEnqueue,
MediaPlayerEntityFeature,
MediaPlayerState,
Expand Down Expand Up @@ -391,3 +393,25 @@ async def test_play_unsupported_media(
)
assert mock_spotify.return_value.start_playback.call_count == 0
assert mock_spotify.return_value.add_to_queue.call_count == 0


@pytest.mark.usefixtures("setup_credentials")
async def test_select_source(
hass: HomeAssistant,
mock_spotify: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test the Spotify media player source select."""
await setup_integration(hass, mock_config_entry)
await hass.services.async_call(
MEDIA_PLAYER_DOMAIN,
SERVICE_SELECT_SOURCE,
{
ATTR_ENTITY_ID: "media_player.spotify_spotify_1",
ATTR_INPUT_SOURCE: "DESKTOP-BKC5SIK",
},
blocking=True,
)
mock_spotify.return_value.transfer_playback.assert_called_with(
"21dac6b0e0a1f181870fdc9749b2656466557666", True
)

0 comments on commit d507581

Please sign in to comment.