def test_client_get_tracks_list(client): track = factories.TrackJSONFactory() client.convert_uri = lambda: '' client.api.get_track = lambda _: track actual = client.get_tracks_list(uris=['']) assert actual == [models.track(track)]
def test_client_get_track(client): track = factories.TrackJSONFactory() client.convert_uri = lambda: '' client.api.get_track = lambda _: track actual = client.get_track(uri='') assert actual == models.track(track)
def test_client_get_playlist_items_ref(client): track = factories.TrackJSONFactory() client.convert_uri = lambda: '' client.api.get_playlist_tracks = lambda _: [track] actual = client.get_playlist_items_refs(uri='') assert actual == [models.track_ref(track)]
def test_client_save_playlist_add_track(client, requests_mock): playlist = factories.PlaylistFactory() playlist_id = int(playlist.uri) json_tracklist = [{ 'id': t['id'], 'track': t } for t in [factories.TrackJSONFactory() for _ in range(0, 10)]] new_track = mopidy_funkwhale.models.track(factories.TrackJSONFactory()) # mopidy models are immutable, so we need to make a new playlist tracklist = tuple( mopidy_funkwhale.models.track(json['track']) for json in json_tracklist) local_playlist = models.Playlist( uri=mopidy_funkwhale.translator.get_playlist_uri(playlist_id), name=playlist.name, tracks=tracklist + (new_track, ), last_modified=playlist.last_modified) add_mock = mock.Mock() del_mock = mock.Mock() favorite_mock = mock.Mock() unfavorite_mock = mock.Mock() client.api.add_track_to_playlist = add_mock client.api.remove_track_from_playlist = del_mock client.api.favorite_track = favorite_mock client.api.unfavorite_track = unfavorite_mock client.get_playlist = lambda uri=None: local_playlist client.api.get_playlist_tracks = lambda _: json_tracklist actual = client.save_playlist(local_playlist) assert actual == local_playlist add_mock.assert_called_with( str(playlist_id), mopidy_funkwhale.translator.get_id(new_track.uri)) del_mock.assert_not_called() favorite_mock.assert_not_called() unfavorite_mock.assert_not_called()
def test_client_get_playlist(client): playlist = factories.PlaylistJSONFactory() tracks = [{ 'id': t['id'], 'track': t } for t in [ factories.TrackJSONFactory() for _ in range(playlist['tracks_count']) ]] client.convert_uri = lambda: '' client.api.get_playlist = lambda _: playlist client.api.get_playlist_tracks = lambda _: tracks actual = client.get_playlist(uri='') assert actual == models.playlist(playlist, tracks)