|
1 | 1 | """Tests for the Spotify media player platform.""" |
2 | 2 |
|
3 | | -from unittest.mock import MagicMock |
| 3 | +from unittest.mock import MagicMock, patch |
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 | from spotipy import SpotifyException |
| 7 | +from syrupy import SnapshotAssertion |
7 | 8 |
|
8 | 9 | from homeassistant.components.media_player import ( |
9 | 10 | MediaPlayerEntityFeature, |
|
15 | 16 |
|
16 | 17 | from . import setup_integration |
17 | 18 |
|
18 | | -from tests.common import MockConfigEntry, load_json_value_fixture |
| 19 | +from tests.common import MockConfigEntry, load_json_value_fixture, snapshot_platform |
19 | 20 |
|
20 | 21 |
|
| 22 | +@pytest.mark.freeze_time("2023-10-21") |
21 | 23 | @pytest.mark.usefixtures("setup_credentials") |
22 | 24 | async def test_entities( |
23 | 25 | hass: HomeAssistant, |
24 | 26 | mock_spotify: MagicMock, |
25 | 27 | mock_config_entry: MockConfigEntry, |
26 | 28 | entity_registry: er.EntityRegistry, |
| 29 | + snapshot: SnapshotAssertion, |
27 | 30 | ) -> None: |
28 | 31 | """Test the Spotify entities.""" |
29 | | - await setup_integration(hass, mock_config_entry) |
30 | | - state = hass.states.get("media_player.spotify_spotify_1") |
31 | | - assert state |
32 | | - assert state.state == MediaPlayerState.PLAYING |
33 | | - assert state.attributes["media_content_type"] == "music" |
34 | | - assert state.attributes["media_duration"] == 296.466 |
35 | | - assert state.attributes["media_position"] == 249.367 |
36 | | - assert "media_position_updated_at" in state.attributes |
37 | | - assert state.attributes["media_title"] == "The Spirit Of Radio" |
38 | | - assert state.attributes["media_artist"] == "Rush" |
39 | | - assert state.attributes["media_album_name"] == "Permanent Waves" |
40 | | - assert state.attributes["media_track"] == 1 |
41 | | - assert state.attributes["repeat"] == "off" |
42 | | - assert state.attributes["shuffle"] is False |
43 | | - assert state.attributes["volume_level"] == 0.25 |
44 | | - assert state.attributes["source"] == "Master Bathroom Speaker" |
45 | | - assert state.attributes["supported_features"] == ( |
46 | | - MediaPlayerEntityFeature.BROWSE_MEDIA |
47 | | - | MediaPlayerEntityFeature.NEXT_TRACK |
48 | | - | MediaPlayerEntityFeature.PAUSE |
49 | | - | MediaPlayerEntityFeature.PLAY |
50 | | - | MediaPlayerEntityFeature.PLAY_MEDIA |
51 | | - | MediaPlayerEntityFeature.PREVIOUS_TRACK |
52 | | - | MediaPlayerEntityFeature.REPEAT_SET |
53 | | - | MediaPlayerEntityFeature.SEEK |
54 | | - | MediaPlayerEntityFeature.SELECT_SOURCE |
55 | | - | MediaPlayerEntityFeature.SHUFFLE_SET |
56 | | - | MediaPlayerEntityFeature.VOLUME_SET |
57 | | - ) |
| 32 | + with patch("secrets.token_hex", return_value="mock-token"): |
| 33 | + await setup_integration(hass, mock_config_entry) |
58 | 34 |
|
| 35 | + await snapshot_platform( |
| 36 | + hass, entity_registry, snapshot, mock_config_entry.entry_id |
| 37 | + ) |
59 | 38 |
|
| 39 | + |
| 40 | +@pytest.mark.freeze_time("2023-10-21") |
60 | 41 | @pytest.mark.usefixtures("setup_credentials") |
61 | 42 | async def test_podcast( |
62 | 43 | hass: HomeAssistant, |
63 | 44 | mock_spotify: MagicMock, |
64 | 45 | mock_config_entry: MockConfigEntry, |
65 | 46 | entity_registry: er.EntityRegistry, |
| 47 | + snapshot: SnapshotAssertion, |
66 | 48 | ) -> None: |
67 | 49 | """Test the Spotify entities while listening a podcast.""" |
68 | 50 | mock_spotify.return_value.current_playback.return_value = load_json_value_fixture( |
69 | 51 | "playback_episode.json", DOMAIN |
70 | 52 | ) |
71 | | - await setup_integration(hass, mock_config_entry) |
72 | | - state = hass.states.get("media_player.spotify_spotify_1") |
73 | | - assert state |
74 | | - assert state.state == MediaPlayerState.PLAYING |
75 | | - assert state.attributes["media_content_type"] == "podcast" |
76 | | - assert state.attributes["media_duration"] == 3690.161 |
77 | | - assert state.attributes["media_position"] == 5.41 |
78 | | - assert "media_position_updated_at" in state.attributes |
79 | | - assert ( |
80 | | - state.attributes["media_title"] |
81 | | - == "My Squirrel Has Brain Damage - Safety Third 119" |
82 | | - ) |
83 | | - assert state.attributes["media_artist"] == "Safety Third " |
84 | | - assert state.attributes["media_album_name"] == "Safety Third" |
85 | | - assert state.attributes["repeat"] == "off" |
86 | | - assert state.attributes["shuffle"] is False |
87 | | - assert state.attributes["volume_level"] == 0.46 |
88 | | - assert state.attributes["source"] == "Sonos Roam SL" |
89 | | - assert ( |
90 | | - state.attributes["supported_features"] == MediaPlayerEntityFeature.SELECT_SOURCE |
91 | | - ) |
| 53 | + with patch("secrets.token_hex", return_value="mock-token"): |
| 54 | + await setup_integration(hass, mock_config_entry) |
| 55 | + |
| 56 | + await snapshot_platform( |
| 57 | + hass, entity_registry, snapshot, mock_config_entry.entry_id |
| 58 | + ) |
92 | 59 |
|
93 | 60 |
|
94 | 61 | @pytest.mark.usefixtures("setup_credentials") |
|
0 commit comments