def test_integ_populate_and_sync(self):

        # drop a track
        dropped_track = self.Dlist.sources[0].reference.tracks.pop()
        self.Dlist.sources[0].tracks.remove(dropped_track)

        # populate
        self.Dlist.populate(self.access_token)
        tracks = self.tracks[:]
        tracks.remove(dropped_track)
        self.assertEqual(set(tracks), set(spio.get_tracks(self.access_token, self.Dlist.uri)))

        # re-add the track and sync
        self.Dlist.sources[0].tracks += [dropped_track]
        diff = self.Dlist.sync()
        spio.add_tracks_to_drain(self.access_token, self.Dlist, diff)

        # check if the track was added
        tracks += [dropped_track]
        self.assertEqual(set(tracks), set(spio.get_tracks(self.access_token, self.Dlist.uri)))
        # depopulate
        self.Dlist.depopulate(spio.get_access_token(test_user))
        self.assertEqual(set(), set(spio.get_tracks(self.access_token, self.Dlist.uri)))

        self.Dlist.cleanup(test_user)
        self.assertEqual(set(os.listdir(test_user + "/Playlists/")), {'spotify:playlist:4L3PeQ9LzinSq0Q3KnzLvb_ref', 'spotify:playlist:069rrIb9s1MRw2BBwXmeJE_drain', 'spotify:playlist:6E2XjEeEOEhUKVoftRHusb_ref'})
Beispiel #2
0
 def test_populate_depopulate(self):
     with playlist.open_drainlist(test_user, dname) as infile:
         d = playlist.Drainlist(test_user, infile)
     token = spio.get_access_token(test_user)
     tracks = spio.get_tracks(token, listname) + spio.get_tracks(
         token, list2name)
     d.populate(token)
     self.assertEqual(set(tracks), set(spio.get_tracks(token, d.uri)))
     d.depopulate(token)
     self.assertEqual(set(), set(spio.get_tracks(token, d.uri)))
Beispiel #3
0
 def test_add_remove_tracks_to_from_drain(self):
     with playlist.open_drainlist(test_user, dname) as infile:
         d = playlist.Drainlist(test_user, infile)
     dump_tracks = ["spotify:track:7EE7jbv7Dv8ZkyWBlKhPXX"]
     spio.add_tracks_to_drain(self.token, d, dump_tracks)
     tracks = spio.get_tracks(self.token, d.uri)
     self.assertEqual(tracks, dump_tracks)
     spio.remove_tracks_from_drain(self.token, d, dump_tracks)
     spio.get_tracks(self.token, d.uri)
     tracks = spio.get_tracks(self.token, d.uri)
     self.assertEqual(tracks, [])
    def setUp(self):
        spotify.create_new_drain(test_user, self.drainSinkName ,self.drain_name, self.sources)
        self.access_token = spio.get_access_token(test_user)
        with playlist.open_drainlist(test_user, self.drain_name) as infile:
            self.Dlist = playlist.Drainlist(test_user, infile)

        if spio.get_tracks(self.access_token, self.Dlist.uri):
            self.Dlist.depopulate(spio.get_access_token(test_user))
Beispiel #5
0
 def from_web_api(cls, user, access_token, uri, reference):
     """
     Generates a playlist object from the spotify API
     :param user: Associated user
     :param access_token:
     :param uri: the URI corresponding to the playlist
     :param reference: The reference playlist Object (None if this is a reference)
     :return: The newly constructed Playlist object
     """
     tracks = spio.get_tracks(access_token, uri)
     name = spio.get_name(access_token, uri)
     return cls(user, name, uri, tracks, reference)
Beispiel #6
0
 def populate(self, access_token):
     """
     Adds one of each track (uniquely) in every source to the drainlist sink on Spotify
     it will not add tracks already on the playlist
     This should only be done on startup in order to skip the ref stage, can remove later
     :param access_token: Securely ID's the user
     :return: None
     """
     tracks = []
     for source in self.sources:
         tracks += source.tracks
     tracks = list(
         set(tracks) - set(spio.get_tracks(access_token, self.uri)))
     spio.add_tracks_to_drain(access_token, self, list(set(tracks)))
Beispiel #7
0
 def test_get_tracks(self):
     # since playlist is volatile just check if one track is in there
     tracks = spio.get_tracks(self.token, listname)
     self.assertTrue("spotify:track:7EE7jbv7Dv8ZkyWBlKhPXX" in tracks)
    def tearDown(self):
        for f in os.listdir(test_user + "/Playlists/"):
            os.remove(test_user + "/Playlists/" + f)

        if spio.get_tracks(self.access_token, self.Dlist.uri):
            self.Dlist.depopulate(spio.get_access_token(test_user))