mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add snapshot testing to Spotify (#128032)
* Add snapshot testing to Spotify * Fix
This commit is contained in:
parent
416ead5311
commit
71898d0c8c
125
tests/components/spotify/snapshots/test_media_player.ambr
Normal file
125
tests/components/spotify/snapshots/test_media_player.ambr
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_entities[media_player.spotify_spotify_1-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': dict({
|
||||||
|
}),
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'media_player',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'media_player.spotify_spotify_1',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': None,
|
||||||
|
'platform': 'spotify',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <MediaPlayerEntityFeature: 444983>,
|
||||||
|
'translation_key': 'spotify',
|
||||||
|
'unique_id': '1112264111',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_entities[media_player.spotify_spotify_1-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'entity_picture': '/api/media_player_proxy/media_player.spotify_spotify_1?token=mock-token&cache=7bb89748322acb6c',
|
||||||
|
'friendly_name': 'Spotify spotify_1',
|
||||||
|
'media_album_name': 'Permanent Waves',
|
||||||
|
'media_artist': 'Rush',
|
||||||
|
'media_content_id': 'spotify:track:4e9hUiLsN4mx61ARosFi7p',
|
||||||
|
'media_content_type': <MediaType.MUSIC: 'music'>,
|
||||||
|
'media_duration': 296.466,
|
||||||
|
'media_playlist': 'Spotify Web API Testing playlist',
|
||||||
|
'media_position': 249.367,
|
||||||
|
'media_position_updated_at': HAFakeDatetime(2023, 10, 21, 0, 0, tzinfo=datetime.timezone.utc),
|
||||||
|
'media_title': 'The Spirit Of Radio',
|
||||||
|
'media_track': 1,
|
||||||
|
'repeat': <RepeatMode.OFF: 'off'>,
|
||||||
|
'shuffle': False,
|
||||||
|
'source': 'Master Bathroom Speaker',
|
||||||
|
'supported_features': <MediaPlayerEntityFeature: 444983>,
|
||||||
|
'volume_level': 0.25,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'media_player.spotify_spotify_1',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'playing',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_podcast[media_player.spotify_spotify_1-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': dict({
|
||||||
|
}),
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'media_player',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'media_player.spotify_spotify_1',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': None,
|
||||||
|
'platform': 'spotify',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <MediaPlayerEntityFeature: 2048>,
|
||||||
|
'translation_key': 'spotify',
|
||||||
|
'unique_id': '1112264111',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_podcast[media_player.spotify_spotify_1-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'entity_picture': '/api/media_player_proxy/media_player.spotify_spotify_1?token=mock-token&cache=cf1e6e1e830f08d3',
|
||||||
|
'friendly_name': 'Spotify spotify_1',
|
||||||
|
'media_album_name': 'Safety Third',
|
||||||
|
'media_artist': 'Safety Third ',
|
||||||
|
'media_content_id': 'spotify:episode:3o0RYoo5iOMKSmEbunsbvW',
|
||||||
|
'media_content_type': <MediaType.PODCAST: 'podcast'>,
|
||||||
|
'media_duration': 3690.161,
|
||||||
|
'media_position': 5.41,
|
||||||
|
'media_position_updated_at': HAFakeDatetime(2023, 10, 21, 0, 0, tzinfo=datetime.timezone.utc),
|
||||||
|
'media_title': 'My Squirrel Has Brain Damage - Safety Third 119',
|
||||||
|
'repeat': <RepeatMode.OFF: 'off'>,
|
||||||
|
'shuffle': False,
|
||||||
|
'source': 'Sonos Roam SL',
|
||||||
|
'supported_features': <MediaPlayerEntityFeature: 2048>,
|
||||||
|
'volume_level': 0.46,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'media_player.spotify_spotify_1',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'playing',
|
||||||
|
})
|
||||||
|
# ---
|
@ -1,9 +1,10 @@
|
|||||||
"""Tests for the Spotify media player platform."""
|
"""Tests for the Spotify media player platform."""
|
||||||
|
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from spotipy import SpotifyException
|
from spotipy import SpotifyException
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
MediaPlayerEntityFeature,
|
MediaPlayerEntityFeature,
|
||||||
@ -15,80 +16,46 @@ from homeassistant.helpers import entity_registry as er
|
|||||||
|
|
||||||
from . import setup_integration
|
from . import setup_integration
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_json_value_fixture
|
from tests.common import MockConfigEntry, load_json_value_fixture, snapshot_platform
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.freeze_time("2023-10-21")
|
||||||
@pytest.mark.usefixtures("setup_credentials")
|
@pytest.mark.usefixtures("setup_credentials")
|
||||||
async def test_entities(
|
async def test_entities(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_spotify: MagicMock,
|
mock_spotify: MagicMock,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the Spotify entities."""
|
"""Test the Spotify entities."""
|
||||||
await setup_integration(hass, mock_config_entry)
|
with patch("secrets.token_hex", return_value="mock-token"):
|
||||||
state = hass.states.get("media_player.spotify_spotify_1")
|
await setup_integration(hass, mock_config_entry)
|
||||||
assert state
|
|
||||||
assert state.state == MediaPlayerState.PLAYING
|
await snapshot_platform(
|
||||||
assert state.attributes["media_content_type"] == "music"
|
hass, entity_registry, snapshot, mock_config_entry.entry_id
|
||||||
assert state.attributes["media_duration"] == 296.466
|
)
|
||||||
assert state.attributes["media_position"] == 249.367
|
|
||||||
assert "media_position_updated_at" in state.attributes
|
|
||||||
assert state.attributes["media_title"] == "The Spirit Of Radio"
|
|
||||||
assert state.attributes["media_artist"] == "Rush"
|
|
||||||
assert state.attributes["media_album_name"] == "Permanent Waves"
|
|
||||||
assert state.attributes["media_track"] == 1
|
|
||||||
assert state.attributes["repeat"] == "off"
|
|
||||||
assert state.attributes["shuffle"] is False
|
|
||||||
assert state.attributes["volume_level"] == 0.25
|
|
||||||
assert state.attributes["source"] == "Master Bathroom Speaker"
|
|
||||||
assert state.attributes["supported_features"] == (
|
|
||||||
MediaPlayerEntityFeature.BROWSE_MEDIA
|
|
||||||
| MediaPlayerEntityFeature.NEXT_TRACK
|
|
||||||
| MediaPlayerEntityFeature.PAUSE
|
|
||||||
| MediaPlayerEntityFeature.PLAY
|
|
||||||
| MediaPlayerEntityFeature.PLAY_MEDIA
|
|
||||||
| MediaPlayerEntityFeature.PREVIOUS_TRACK
|
|
||||||
| MediaPlayerEntityFeature.REPEAT_SET
|
|
||||||
| MediaPlayerEntityFeature.SEEK
|
|
||||||
| MediaPlayerEntityFeature.SELECT_SOURCE
|
|
||||||
| MediaPlayerEntityFeature.SHUFFLE_SET
|
|
||||||
| MediaPlayerEntityFeature.VOLUME_SET
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.freeze_time("2023-10-21")
|
||||||
@pytest.mark.usefixtures("setup_credentials")
|
@pytest.mark.usefixtures("setup_credentials")
|
||||||
async def test_podcast(
|
async def test_podcast(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_spotify: MagicMock,
|
mock_spotify: MagicMock,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the Spotify entities while listening a podcast."""
|
"""Test the Spotify entities while listening a podcast."""
|
||||||
mock_spotify.return_value.current_playback.return_value = load_json_value_fixture(
|
mock_spotify.return_value.current_playback.return_value = load_json_value_fixture(
|
||||||
"playback_episode.json", DOMAIN
|
"playback_episode.json", DOMAIN
|
||||||
)
|
)
|
||||||
await setup_integration(hass, mock_config_entry)
|
with patch("secrets.token_hex", return_value="mock-token"):
|
||||||
state = hass.states.get("media_player.spotify_spotify_1")
|
await setup_integration(hass, mock_config_entry)
|
||||||
assert state
|
|
||||||
assert state.state == MediaPlayerState.PLAYING
|
await snapshot_platform(
|
||||||
assert state.attributes["media_content_type"] == "podcast"
|
hass, entity_registry, snapshot, mock_config_entry.entry_id
|
||||||
assert state.attributes["media_duration"] == 3690.161
|
)
|
||||||
assert state.attributes["media_position"] == 5.41
|
|
||||||
assert "media_position_updated_at" in state.attributes
|
|
||||||
assert (
|
|
||||||
state.attributes["media_title"]
|
|
||||||
== "My Squirrel Has Brain Damage - Safety Third 119"
|
|
||||||
)
|
|
||||||
assert state.attributes["media_artist"] == "Safety Third "
|
|
||||||
assert state.attributes["media_album_name"] == "Safety Third"
|
|
||||||
assert state.attributes["repeat"] == "off"
|
|
||||||
assert state.attributes["shuffle"] is False
|
|
||||||
assert state.attributes["volume_level"] == 0.46
|
|
||||||
assert state.attributes["source"] == "Sonos Roam SL"
|
|
||||||
assert (
|
|
||||||
state.attributes["supported_features"] == MediaPlayerEntityFeature.SELECT_SOURCE
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("setup_credentials")
|
@pytest.mark.usefixtures("setup_credentials")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user