def test_artist_with_multiple_albums(self): artist = Artist('artist name', 'country') artist.add_album(Album('first album title', 2020)) artist.add_album(Album('second album title', 2020)) expected_albums = [ Album('first album title', 2020), Album('second album title', 2020) ] assert list(artist.get_albums()) == expected_albums
def test_sort_albums_by_most_recent(self): artist = Artist('artist name', 'country') artist.add_album(Album('first album title', 2020)) artist.add_album(Album('second album title', 2021)) expected_albums = [ Album('second album title', 2021), Album('first album title', 2020) ] artist.sort_albums_by_date() assert list(artist.get_albums()) == expected_albums
def test_artists_with_multiple_songs(self): artist = Artist('artist name', 'country') first_album = Album('first album title', 2020) first_album.add(Song('first song title')) first_album.add(Song('second song title')) second_album = Album('second album title', 2020) second_album.add(Song('third song title')) artist.add_album(first_album) artist.add_album(second_album) expected_songs = [ Song('first song title'), Song('second song title'), Song('third song title') ] assert list(artist.get_songs()) == expected_songs
def load_data(): new_artist = None new_album = None artist_list = [] with open('albums.txt') as albums: for a_line in albums: artist_field, album_field, year_field, song_field = a_line.strip( ).split("\t") print("{} - {} - {} - {}".format(artist_field, album_field, year_field, song_field)) if new_artist is None: new_artist = Artist(artist_field) artist_list.append(new_artist) elif new_artist.name != artist_field: # Compare to previous artist, and if not equal to previous artist # Retrieve artist object if there is one, if not then create new artist new_artist = find_object(artist_field, artist_list) if new_artist is None: new_artist = Artist(artist_field) artist_list.append(new_artist) new_album = None if new_album is None: new_album = Album(album_field, year_field, new_artist) new_artist.add_album(new_album) elif new_album.name != album_field: new_album = find_object(album_field, new_artist.albums) if new_album is None: new_album = Album(album_field, year_field, new_artist) new_artist.add_album(new_album) # Song is just the same, song is created and we add song new_song = Song(song_field, new_artist) new_album.add_song(new_song) return artist_list
def test_to_and_from_str_with_albums_without_songs(self): artist = Artist('artist name', 'country') artist.add_album(Album('first album name', 2020)) artist.add_album(Album('second album name', 2020)) assert Artist.from_string(str(artist)) == artist
def test_equality_for_artist_with_albums(self): artist = Artist('artist name', 'country') artist.add_album(Album('album title', 2020)) assert artist != Artist('artist name', 'country')
def test_artist_with_one_song(self): artist = Artist('artist name', 'country') album = Album('album title', 2020) album.add(Song('song title')) artist.add_album(album) assert list(artist.get_songs()) == [Song('song title')]
def test_artist_with_albums_but_no_songs(self): artist = Artist('artist name', 'country') artist.add_album(Album('album title', 2020)) assert list(artist.get_songs()) == []
def test_artist_with_single_album(self): artist = Artist('artist name', 'country') artist.add_album(Album('album title', 2020)) assert list(artist.get_albums()) == [Album('album title', 2020)]