def create_playlist(): """ Make a new playlist """ playlist = pywhatsnext.Playlist() playlist.save() return playlist.to_dict(), 201
def test_read_write_playlist(self): # fail to read with self.assertRaises(pywhatsnext.NotFoundException): pywhatsnext.Playlist.from_id("anidthatdoesntexist") playlist = pywhatsnext.Playlist() # Successful read and write playlist.save() another_playlist = pywhatsnext.Playlist.from_id(playlist.id) self.assertEqual(playlist.to_dict(), another_playlist.to_dict()) # update the song needs to get a save to be sent to database song_body = {"youtube_id": "a song source"} playlist.append(pywhatsnext.Song.from_body(song_body)) self.assertNotEqual( playlist.to_dict(), pywhatsnext.Playlist.from_id(playlist.id).to_dict()) playlist.save() self.assertEqual(playlist.to_dict(), pywhatsnext.Playlist.from_id(playlist.id).to_dict()) # test delete playlist.delete() with self.assertRaises(pywhatsnext.NotFoundException): pywhatsnext.Playlist.from_id(playlist.id)
def test_playlist(self): original_body = { "id": "123", "owner": "someuser", "current_song": "asongid", "songs": [{ "id": "asongid", "youtube_id": "asongsource" }] } playlist = pywhatsnext.Playlist() playlist.init_from_body(original_body) self.assertEqual(playlist.to_dict(), original_body)
def test_multiple_add_next(self): playlist = pywhatsnext.Playlist() playlist.save() for i in range(10): song = pywhatsnext.Song.from_body({ "youtube_id": "source" + str(i), "id": "id" + str(i) }) playlist.append(song) playlist.save() playlist.next() playlist.save()
def test_playlist_actions(self): original_body = { "id": "123", "owner": "someuser", "songs": [{ "id": "asongid", "youtube_id": "asongsource" }] } playlist = pywhatsnext.Playlist() playlist.init_from_body(original_body) self.assertEqual(playlist.current_song['id'], "asongid") playlist.next() self.assertEqual(playlist.current_song['id'], "asongid") playlist.append( pywhatsnext.Song.from_body({ "id": "anothersongid", "youtube_id": "nothing" })) self.assertEqual(playlist.current_song['id'], "asongid") playlist.next() self.assertEqual(playlist.current_song['id'], "anothersongid")