def test_save(self): s1 = Song('One', 'U2', 'Achtung Baby', '4:38') s2 = Song('Two', 'U2', 'Epimeno', '7:32') p = Playlist('Ala bala') p.add_songs([s1, s2]) p.save() self.assertTrue(os.path.isfile('./Ala-bala.json'))
def test_next_song_returns_next_song(self): s1 = Song('One', 'U2', 'Achtung Baby', '4:38') s2 = Song('Two', 'U2', 'Epimeno', '7:32') p = Playlist('Ala bala') p.add_songs([s1, s2]) self.assertEqual(p.next_song(), s1) self.assertEqual(p.next_song(), s2)
def test_playlist_total_length(self): s1 = Song('One', 'U2', 'Achtung Baby', '4:38') s2 = Song('Warriors of the World', 'Manowar', 'Manowar album', '3:10') p = Playlist('random songs') p.add_songs([s1,s2]) result = p.total_length() self.assertEqual(result , '7:48')
def test_show_artists_displays_correctly(self): s1 = Song('One', 'U2', 'Achtung Baby', '4:38') s2 = Song('Two', 'U2', 'Epimeno', '7:32') s3 = Song('Three', 'U2', 'Achtung Baby', '3:15') s4 = Song('Warriors of the World', 'Manowar', 'Manowar album', '3:10') p = Playlist('Ala bala') p.add_songs([s1, s2, s3, s4]) expectedHistogram = {'U2': 3, 'Manowar': 1} self.assertEqual(p.show_artists(), expectedHistogram)
def test_playlist_add_songs(self): s1 = Song('One', 'U2', 'Achtung Baby', '4:38') s2 = Song('Warriors of the World', 'Manowar', 'Manowar album', '3:10') s3 = Song('Chiki chiki ta', 'Kondio', 'Doko doko', '7:32') songlist = [s1, s2, s3] p = Playlist('mish mash') p.add_songs(songlist) for s in songlist: self.assertIn(s, p.songslist)
def test_next_song_repeat_works(self): s1 = Song('One', 'U2', 'Achtung Baby', '4:38') s2 = Song('Two', 'U2', 'Epimeno', '7:32') s3 = Song('Three', 'U2', 'Achtung Baby', '3:15') p = Playlist('Ala bala', repeat=True) p.add_songs([s1, s2, s3]) self.assertEqual(p.next_song(), s1) self.assertEqual(p.next_song(), s2) self.assertEqual(p.next_song(), s3) self.assertEqual(p.next_song(), s1)
def test_load(self): s1 = Song('One', 'U2', 'Achtung Baby', '4:38') s2 = Song('Two', 'U2', 'Epimeno', '7:32') s3 = Song('Three', 'Kondio', 'Doko doko', '7:32') p = Playlist('newplaylist') newsongs = p.load('./Ala-bala.json') os.remove("./Ala-bala.json") p.add_songs(newsongs) self.assertIn(s1, p.songslist) self.assertIn(s2, p.songslist) self.assertNotIn(s3, p.songslist)