def test_lookup_of_search_uri(config, get_station_mock_return_value, playlist_item_mock, get_station_list_return_value_mock, station_result_mock): with mock.patch.object(MopidyAPIClient, 'get_station', return_value=get_station_mock_return_value): with mock.patch.object( APIClient, 'create_station', mock.Mock(return_value=Station.from_json( mock.MagicMock(MopidyAPIClient), station_result_mock['result']))) as create_station_mock: with mock.patch.object( APIClient, 'get_station_list', return_value=get_station_list_return_value_mock): backend = conftest.get_backend(config) get_station_mock_return_value.id = conftest.MOCK_STATION_ID backend.library.pandora_station_cache[get_station_mock_return_value.id] = \ StationCacheItem(station_result_mock['result'], iter([playlist_item_mock])) track_uri = PlaylistItemUri._from_track(playlist_item_mock) backend.library.pandora_track_cache[ track_uri.uri] = TrackCacheItem( mock.Mock(spec=models.Ref.track), playlist_item_mock) results = backend.library.lookup('pandora:search:S1234567') # Make sure a station is created for the search URI first assert create_station_mock.called # Check that the first track to be played is returned correctly. assert results[0].uri == track_uri.uri
def test_get_images_for_track_with_images(config, playlist_item_mock): backend = conftest.get_backend(config) track_uri = PandoraUri.factory('pandora:track:mock_id:mock_token') backend.library.pandora_track_cache[track_uri.uri] = TrackCacheItem( mock.Mock(spec=models.Ref.track), playlist_item_mock) results = backend.library.get_images([track_uri.uri]) assert len(results[track_uri.uri]) == 1 assert results[track_uri.uri][0].uri == playlist_item_mock.album_art_url
def test_get_images_for_ad_with_images(config, ad_item_mock): backend = conftest.get_backend(config) ad_uri = PandoraUri.factory('pandora:ad:{}:{}'.format( conftest.MOCK_STATION_ID, conftest.MOCK_TRACK_AD_TOKEN)) backend.library.pandora_track_cache[ad_uri.uri] = TrackCacheItem( mock.Mock(spec=models.Ref.track), ad_item_mock) results = backend.library.get_images([ad_uri.uri]) assert len(results[ad_uri.uri]) == 1 assert results[ad_uri.uri][0].uri == ad_item_mock.image_url
def test_lookup_overrides_album_and_artist_uris(config, playlist_item_mock): backend = conftest.get_backend(config) track_uri = PlaylistItemUri._from_track(playlist_item_mock) backend.library.pandora_track_cache[track_uri.uri] = TrackCacheItem( mock.Mock(spec=models.Ref.track), playlist_item_mock) results = backend.library.lookup(track_uri.uri) track = results[0] assert next(iter(track.artists)).uri == track_uri.uri assert track.album.uri == track_uri.uri
def test_lookup_of_track_uri(config, playlist_item_mock): backend = conftest.get_backend(config) track_uri = PlaylistItemUri._from_track(playlist_item_mock) backend.library.pandora_track_cache[track_uri.uri] = TrackCacheItem( mock.Mock(spec=models.Ref.track), playlist_item_mock) results = backend.library.lookup(track_uri.uri) assert len(results) == 1 track = results[0] assert track.uri == track_uri.uri
def test_get_images_for_track_with_images(config, playlist_item_mock): backend = conftest.get_backend(config) track_uri = PandoraUri.factory("pandora:track:mock_id:mock_token") backend.library.pandora_track_cache[track_uri.uri] = TrackCacheItem( mock.Mock(spec=models.Ref.track), playlist_item_mock) results = backend.library.get_images([track_uri.uri]) assert len(results[track_uri.uri]) == 1 # chrome blocks getting non https images from Pandora, therefore the # library provider substitutes https for http. We need to perform # the same substitution here to verify it worked correctly assert results[ track_uri.uri][0].uri == playlist_item_mock.album_art_url.replace( "http://", "https://", 1)
def test_lookup_of_ad_uri_defaults_missing_values(config, ad_item_mock): backend = conftest.get_backend(config) ad_item_mock.title = '' ad_item_mock.company_name = None track_uri = PlaylistItemUri._from_track(ad_item_mock) backend.library.pandora_track_cache[track_uri.uri] = TrackCacheItem( mock.Mock(spec=models.Ref.track), ad_item_mock) results = backend.library.lookup(track_uri.uri) assert len(results) == 1 track = results[0] assert track.name == 'Advertisement' assert '(Title not specified)' in next(iter(track.artists)).name assert track.album.name == '(Company name not specified)'
def test_translate_uri_returns_audio_url(provider, playlist_item_mock): test_uri = "pandora:track:test_station_id:test_token" provider.backend.library.pandora_track_cache[test_uri] = TrackCacheItem( mock.Mock(spec=models.Ref.track), playlist_item_mock) assert provider.translate_uri(test_uri) == conftest.MOCK_TRACK_AUDIO_HIGH