def test_if_song_is_added(self): playlist = Playlist() song = Song() playlist.add_song(song) self.assertTrue(song in playlist.songs)
def main(): playlist = Playlist(repeat=True, shuffle=True) playlist.add_song(Song(artist="Someone1", title="Something1")) playlist.add_song(Song(artist="Someone1", title="Something2")) code = Playlist.load('Auto-generated-playlist-#1.json') print(code.name) print(code.next_song()) print(code.next_song())
def test_trying_to_delete_song_that_is_not_instance_of_song_class(self): playlist = Playlist() exc = None try: playlist.remove_song('song') except Exception as err: exc = err self.assertIsNotNone(exc)
def test_add_song_with_not_song_instance_should_raise_error(self): playlist = Playlist() exc = None try: playlist.add_song('song') except Exception as err: exc = err self.assertIsNotNone(exc)
def test_add_songs_adding_not_a_list_should_raise_error(self): playlist = Playlist() exc = None try: playlist.add_songs(('song1', 'song2')) except Exception as err: exc = err self.assertIsNotNone(exc)
def test_count_songs_of_an_artist(self): playlist = Playlist() playlist.add_song(Song(artist="Someone1", title="Something1")) playlist.add_song(Song(artist="Someone1", title="Something2")) playlist.add_song(Song(artist="Someone1", title="Something3")) playlist.add_song(Song(artist="Someone1", title="Something4")) self.assertTrue(playlist.count_songs_of_an_artist("Someone1") == 4)
def test_artists(self): playlist = Playlist() playlist.add_song(Song(artist="Someone1", title="Something1")) playlist.add_song(Song(artist="Someone1", title="Something2")) playlist.add_song(Song(artist="Someone2", title="Something3")) playlist.add_song(Song(artist="Someone3", title="Something4")) self.assertTrue({ 'Someone1': 2, 'Someone2': 1, 'Someone3': 1 } == playlist.artists())
def test_next_song_in_case_three_with_not_empty_list(self): playlist = Playlist(repeat=False, shuffle=True) playlist.add_song(Song(artist="Someone1", title="Something1")) exc = None self.assertTrue(isinstance(playlist.next_song(), Song)) try: playlist.next_song() except Exception as err: exc = err self.assertIsNotNone(exc)
def test_next_song_in_case_four_with_not_empty_list(self): playlist = Playlist(repeat=True, shuffle=True) playlist.add_song(Song(artist="Someone1", title="Something1")) playlist.add_song(Song(artist="Someone1", title="Something2")) # after two calls length of playlist.not_played_songs should be zero # in the third call length of playlist.not_playes_songs should be 1 # because list is coppied and one song is played and removed from the list playlist.next_song() playlist.next_song() self.assertTrue(len(playlist.not_played_songs) == 0) playlist.next_song() self.assertTrue(len(playlist.not_played_songs) == 1)
def test_next_song_in_case_one_with_not_empty_list(self): playlist = Playlist(repeat=True, shuffle=False) playlist.add_song(Song(artist="Someone1", title="Something1")) playlist.add_song(Song(artist="Someone1", title="Something2")) # first next_song should return first song # second next_song should return third song # third should return first song self.assertTrue(playlist.next_song() == Song(artist="Someone1", title="Something1")) self.assertTrue(playlist.next_song() == Song(artist="Someone1", title="Something2")) self.assertTrue(playlist.next_song() == Song(artist="Someone1", title="Something1"))
def test_next_song_in_case_two_with_not_empty_list(self): playlist = Playlist(repeat=False, shuffle=False) playlist.add_song(Song(artist="Someone1", title="Something1")) playlist.add_song(Song(artist="Someone1", title="Something2")) exc = None # first next_song should return first song # second next_song should return third song # third should raise error self.assertTrue(playlist.next_song() == Song(artist="Someone1", title="Something1")) self.assertTrue(playlist.next_song() == Song(artist="Someone1", title="Something2")) try: playlist.next_song() except Exception as err: exc = err self.assertIsNotNone(exc)
def create_new_playlist(self, name, items): self.category_list.add_items([ListTreeItem(Playlist("local", name, items))])