mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Add test for Spotify select source (#128160)
This commit is contained in:
parent
9ff35d5a5a
commit
d50758197e
@ -79,6 +79,7 @@ def mock_spotify() -> Generator[MagicMock]:
|
|||||||
client.current_user.return_value = current_user
|
client.current_user.return_value = current_user
|
||||||
client.me.return_value = current_user
|
client.me.return_value = current_user
|
||||||
for fixture, method in (
|
for fixture, method in (
|
||||||
|
("devices.json", "devices"),
|
||||||
("current_user_playlist.json", "current_user_playlists"),
|
("current_user_playlist.json", "current_user_playlists"),
|
||||||
("playback.json", "current_playback"),
|
("playback.json", "current_playback"),
|
||||||
("followed_artists.json", "current_user_followed_artists"),
|
("followed_artists.json", "current_user_followed_artists"),
|
||||||
|
14
tests/components/spotify/fixtures/devices.json
Normal file
14
tests/components/spotify/fixtures/devices.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -5,6 +5,9 @@
|
|||||||
}),
|
}),
|
||||||
'area_id': None,
|
'area_id': None,
|
||||||
'capabilities': dict({
|
'capabilities': dict({
|
||||||
|
'source_list': list([
|
||||||
|
'DESKTOP-BKC5SIK',
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
'config_entry_id': <ANY>,
|
'config_entry_id': <ANY>,
|
||||||
'device_class': None,
|
'device_class': None,
|
||||||
@ -51,6 +54,9 @@
|
|||||||
'repeat': <RepeatMode.OFF: 'off'>,
|
'repeat': <RepeatMode.OFF: 'off'>,
|
||||||
'shuffle': False,
|
'shuffle': False,
|
||||||
'source': 'Master Bathroom Speaker',
|
'source': 'Master Bathroom Speaker',
|
||||||
|
'source_list': list([
|
||||||
|
'DESKTOP-BKC5SIK',
|
||||||
|
]),
|
||||||
'supported_features': <MediaPlayerEntityFeature: 444983>,
|
'supported_features': <MediaPlayerEntityFeature: 444983>,
|
||||||
'volume_level': 0.25,
|
'volume_level': 0.25,
|
||||||
}),
|
}),
|
||||||
@ -68,6 +74,9 @@
|
|||||||
}),
|
}),
|
||||||
'area_id': None,
|
'area_id': None,
|
||||||
'capabilities': dict({
|
'capabilities': dict({
|
||||||
|
'source_list': list([
|
||||||
|
'DESKTOP-BKC5SIK',
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
'config_entry_id': <ANY>,
|
'config_entry_id': <ANY>,
|
||||||
'device_class': None,
|
'device_class': None,
|
||||||
@ -112,6 +121,9 @@
|
|||||||
'repeat': <RepeatMode.OFF: 'off'>,
|
'repeat': <RepeatMode.OFF: 'off'>,
|
||||||
'shuffle': False,
|
'shuffle': False,
|
||||||
'source': 'Sonos Roam SL',
|
'source': 'Sonos Roam SL',
|
||||||
|
'source_list': list([
|
||||||
|
'DESKTOP-BKC5SIK',
|
||||||
|
]),
|
||||||
'supported_features': <MediaPlayerEntityFeature: 2048>,
|
'supported_features': <MediaPlayerEntityFeature: 2048>,
|
||||||
'volume_level': 0.46,
|
'volume_level': 0.46,
|
||||||
}),
|
}),
|
||||||
|
@ -7,6 +7,7 @@ from spotipy import SpotifyException
|
|||||||
from syrupy import SnapshotAssertion
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
|
ATTR_INPUT_SOURCE,
|
||||||
ATTR_MEDIA_CONTENT_ID,
|
ATTR_MEDIA_CONTENT_ID,
|
||||||
ATTR_MEDIA_CONTENT_TYPE,
|
ATTR_MEDIA_CONTENT_TYPE,
|
||||||
ATTR_MEDIA_ENQUEUE,
|
ATTR_MEDIA_ENQUEUE,
|
||||||
@ -16,6 +17,7 @@ from homeassistant.components.media_player import (
|
|||||||
ATTR_MEDIA_VOLUME_LEVEL,
|
ATTR_MEDIA_VOLUME_LEVEL,
|
||||||
DOMAIN as MEDIA_PLAYER_DOMAIN,
|
DOMAIN as MEDIA_PLAYER_DOMAIN,
|
||||||
SERVICE_PLAY_MEDIA,
|
SERVICE_PLAY_MEDIA,
|
||||||
|
SERVICE_SELECT_SOURCE,
|
||||||
MediaPlayerEnqueue,
|
MediaPlayerEnqueue,
|
||||||
MediaPlayerEntityFeature,
|
MediaPlayerEntityFeature,
|
||||||
MediaPlayerState,
|
MediaPlayerState,
|
||||||
@ -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.start_playback.call_count == 0
|
||||||
assert mock_spotify.return_value.add_to_queue.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
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user