Esempio n. 1
0
    def test_playlist_next_song_works_as_expected_with_repeat_and_shuffle(
            self):
        f = Song(title="Odin",
                 artist="Manowar",
                 album="The Sons of Odin",
                 length="3:44")
        s = Song(title="Empty",
                 artist="Metric",
                 album="Live It Out",
                 length="5:55")
        q = Song(title="Superman",
                 artist="Eminem",
                 album="The Eminem Show",
                 length="5:50")
        code_songs = Playlist(name="Code", repeat=True, shuffle=True)
        test = Playlist(name="Code2", repeat=True, shuffle=True)

        code_songs.add_song(f)
        code_songs.add_song(s)
        code_songs.add_song(q)

        test.add_song(code_songs.next_song())
        test.add_song(code_songs.next_song())
        test.add_song(code_songs.next_song())

        code_songs.next_song()

        assert code_songs.next_song() in getattr(test, 'songs')
Esempio n. 2
0
    def test_playlist_next_song_works_as_expected_with_no_repeat_and_no_shuffle(
            self):
        f = Song(title="Odin",
                 artist="Manowar",
                 album="The Sons of Odin",
                 length="3:44")
        s = Song(title="Empty",
                 artist="Metric",
                 album="Live It Out",
                 length="5:55")
        q = Song(title="Superman",
                 artist="Eminem",
                 album="The Eminem Show",
                 length="5:50")
        code_songs = Playlist(name="Code", repeat=False, shuffle=False)

        code_songs.add_song(f)
        code_songs.add_song(s)
        code_songs.add_song(q)

        code_songs.next_song()
        code_songs.next_song()

        self.assertEqual(code_songs.next_song(),
                         'There are no more songs in your playlist.')
Esempio n. 3
0
 def setUp(self):
     self.my_song = Song("Solder Of Frortune", "Deep Purple",
                         "Stormbringer", "3:14")
     self.second_song = Song("I Stand Alone", "Godsmack", "Awake", "4:30")
     self.rock = Playlist("Rock songs", True)
     self.songs = [self.my_song, self.second_song]
     self.rock.add_songs(self.songs)
 def test_add_list_of_songs_to_an_empty_playlist_then_return_the_total_length_of_the_songs(self):
     song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
     song2 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
     song3 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
     playlist = Playlist(name="Code", repeat=True, shuffle=True)
     playlist.add_songs([song, song2, song3])
     expected_result = '0:11:12'
     self.assertEqual(playlist.total_length(), expected_result)
 def test_the_function_artists_of_a_playlist_then_return_dictionary_where_keys_are_the_artists_and_values_are_the_numbers_of_the_songs(self):
     song = Song(title="Odin", artist="Manowar1", album="The Sons of Odin", length="3:44")
     song2 = Song(title="Odin", artist="Manowar2", album="The Sons of Odin", length="3:44")
     song3 = Song(title="Odin", artist="Manowar3", album="The Sons of Odin", length="3:44")
     playlist = Playlist(name="Code", repeat=True, shuffle=True)
     playlist.add_songs([song, song2, song3])
     expected_result = {'Manowar1': 1, 'Manowar2': 1, 'Manowar3': 1}
     self.assertEqual(playlist.artists(), expected_result)
 def test_returning_playlist_next_song_when_reach_the_last_song_and_shuffle_and_no_repeat_then_return_a_song(self):
     song = Song(title="Odin", artist="Manowar1", album="The Sons of Odin", length="3:44")
     song2 = Song(title="Odin", artist="Manowar2", album="The Sons of Odin", length="3:44")
     song3 = Song(title="Odin", artist="Manowar3", album="The Sons of Odin", length="3:44")
     playlist = Playlist(name="Code", repeat=False, shuffle=True)
     playlist.add_songs([song, song2, song3])
     expected_result = song
     self.assertEqual(type(playlist.next_song(song3)), type(expected_result))
 def setUp(self):
     self.pl = Playlist("ssss")
     self.pl.add_song(
         Song(title="Odin",
              artist="Manowar",
              album="The Sons of Odin",
              time="3:44"))
     self.pl.add_song(
         Song(title="Odin", artist="Manowar", album="Odin", time="6:26"))
Esempio n. 8
0
    def test_playlist_artists_works_as_expected(self):
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)
        test = Song(title="Odin",
                    artist="Manowar",
                    album="The Sons of Odin",
                    length="3:44")

        my_playlist.add_song(test)

        self.assertEqual(my_playlist.artists(), {'Manowar': 1})
Esempio n. 9
0
    def test_playlist_add_song_adds_song_to_object_list_of_songs(self):
        test = Song(title="Odin",
                    artist="Manowar",
                    album="The Sons of Odin",
                    length="3:44")
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)

        my_playlist.add_song(test)

        assert test in my_playlist.songs
Esempio n. 10
0
    def test_playlist_remove_song_removes_song_from_object_list_of_songs(self):
        test = Song(title="Odin",
                    artist="Manowar",
                    album="The Sons of Odin",
                    length="3:44")
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)

        my_playlist.add_song(test)
        my_playlist.remove_song(test)

        self.assertEqual(my_playlist.songs, [])
Esempio n. 11
0
    def test_playlist_total_length_is_calculated_correctly_with_songs_sum_over_hour(
            self):
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)
        test1 = Song(title="Odin",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="55:44")
        test2 = Song(title="Empty",
                     artist="Metric",
                     album="Live It Out",
                     length="5:16")

        my_playlist.add_song(test1)
        my_playlist.add_song(test2)

        self.assertEqual(my_playlist.total_length(), '1:01:00')
Esempio n. 12
0
    def test_playlist_remove_song_raises_exception_if_song_not_in_object_list_of_songs(
            self):
        test = Song(title="Odin",
                    artist="Manowar",
                    album="The Sons of Odin",
                    length="3:44")
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)
        exc = None

        try:
            my_playlist.remove_song(test)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), f'{test.title} is not in this playlist.')
Esempio n. 13
0
    def test_playlist_total_length_is_calculated_correctly_with_songs_under_a_minute(
            self):
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)
        test1 = Song(title="Odin",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="0:44")
        test2 = Song(title="Empty",
                     artist="Metric",
                     album="Live It Out",
                     length="0:10")

        my_playlist.add_song(test1)
        my_playlist.add_song(test2)

        self.assertEqual(my_playlist.total_length(), '0:54')
Esempio n. 14
0
    def test_playlist_add_song_raises_excpetion_if_song_already_in_playlist(
            self):
        test1 = Song(title="Odin",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        test2 = Song(title="Odin",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)
        exc = None

        my_playlist.add_song(test1)

        try:
            my_playlist.add_song(test2)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Song is already in the playlist.')
Esempio n. 15
0
 def test_add_songs_when_songs_is_not_list_then_raise_type_error(self):
     with self.assertRaises(TypeError):
         Playlist('OneRepublic').add_songs((Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44')))
Esempio n. 16
0
 def test_total_length_when_songs_add_up_to_a_full_hour_the_return_length_in_format_hh_mm_ss(self):
     test_playlist = Playlist('OneRepublic', songs_list = [Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='33:44'), Song(title='Counting Stars', artist='OneRepublic', album='Native', length='33:50')])
     expected_result = '1:07:34'
     self.assertEqual(test_playlist.total_length(), expected_result)
Esempio n. 17
0
 def test_artists_return_histogram_of_artists_in_playlist(self):
     test_playlist = Playlist('OneRepublic', songs_list = [Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44'), Song(title='Counting Stars', artist='OneRepublic', album='Native', length='3:50')])
     expected_result = {'OneRepublic': 2}
     self.assertEqual(test_playlist.artists(), expected_result)
Esempio n. 18
0
 def test_add_song_when_song_is_not_instance_of_class_song_then_raise_type_error(self):
     with self.assertRaises(TypeError):
         Playlist('OneRepublic').add_song(('Love Runs Out', 'OneRepublic', 'Native', '3:44'))
Esempio n. 19
0
 def test_add_song_when_song_is_instance_of_class_song_then_add_song_to_playlist(self):
     test_playlist = Playlist('OneRepublic')
     test_playlist.add_song(Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44'))
     expected_result = [Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44')]
     self.assertEqual(test_playlist.songs_list, expected_result)
Esempio n. 20
0
 def test_remove_song_when_song_is_not_instance_of_class_song_then_raise_type_error(self):
     test_playlist = Playlist('OneRepublic', songs_list=[Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44')])
     with self.assertRaises(TypeError):
         test_playlist.remove_song(('Love Runs Out', 'OneRepublic', 'Native', '3:44'))
Esempio n. 21
0
 def test_remove_song_when_song_is_not_present_in_songs_list_then_raise_value_error(self):
     test_playlist = Playlist('OneRepublic', songs_list = [])
     with self.assertRaises(ValueError):
         test_playlist.remove_song(Song(title='Counting Stars', artist='OneRepublic', album='Native', length='3:50'))
Esempio n. 22
0
    def test_playlist_total_length_is_calculated_correctly_without_any_songs(
            self):
        my_playlist = Playlist(name="Code", repeat=True, shuffle=True)

        self.assertEqual(my_playlist.total_length(), '0:00')
Esempio n. 23
0
 def test_remove_song_when_song_is_present_in_songs_list_then_remove_song_from_playlist(self):
     test_playlist = Playlist('OneRepublic', songs_list=[Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44')])
     test_playlist.remove_song(Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44'))
     expected_result = []
     self.assertEqual(test_playlist.songs_list, expected_result)
Esempio n. 24
0
 def test_add_songs_when_songs_are_instances_of_class_song_and_are_in_a_list_then_add_songs_to_playlist(self):
     test_playlist = Playlist('OneRepublic', songs_list = [])
     test_playlist.add_songs([Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44'), Song(title='Counting Stars', artist='OneRepublic', album='Native', length='3:50')])
     expected_result = [Song(title='Love Runs Out', artist='OneRepublic', album='Native', length='3:44'), Song(title='Counting Stars', artist='OneRepublic', album='Native', length='3:50')]
     self.assertEqual(test_playlist.songs_list, expected_result)
Esempio n. 25
0
    def test_playlist_init_initializes_object_correctly(self):
        code_songs = Playlist(name="Code", repeat=True, shuffle=False)

        self.assertEqual(code_songs.name, 'Code')
        self.assertEqual(code_songs.repeat, True)
        self.assertEqual(code_songs.shuffle, False)