def test_throw_error_if_track_exists(self): """ Should throw DuplicateTrackError given track for disc already exists """ album = GMusicAlbum(id, title, album_artist) album.add_track(1, 3, track) self.assertRaises(DuplicateTrackError, album.add_track, 1, 3, track)
def test_add_track_to_album(self): """ Should add track to album """ album = GMusicAlbum(id, title, album_artist) album.add_track(1, 3, track) self.assertEqual(len(album.tracks), 1) self.assertEqual(len(album.tracks[1]), 1) self.assertEqual(album.tracks.get(1).get(3).title, 'Limerence')
def test_album_total_tracks_count_one_disc(self): """ Given tracks have been added to tracks across 1 disc Should return the correct number of tracks added """ album = GMusicAlbum(id, title, album_artist) album.add_track(1, 3, track) album.add_track(1, 2, track) expected = 2 actual = album.total_tracks() self.assertEqual(actual, expected)
def test_album_constructor_no_year(self): """ Should construct album correctly with no year specified """ actual = GMusicAlbum(id, title, album_artist) self.assertEqual(actual.id, id) self.assertEqual(actual.album_artist, album_artist) self.assertEqual(actual.title, title) self.assertEqual(actual.year, '') self.assertEqual(actual.tracks, {})
def test_discs_added(self): """ Given tracks have been added to tracks across 2 discs Should return the correct number of discs """ album = GMusicAlbum(id, title, album_artist) album.add_track(1, 3, track) album.add_track(1, 2, track) album.add_track(2, 1, track) expected = set([1, 2]) actual = album.discs_added() self.assertEqual(actual, expected)
def test_add_track_to_album_on_another_disc(self): """ Should add track to album given same trackNum on different disc """ album = GMusicAlbum(id, title, album_artist) album.add_track(1, 3, track) album.add_track(2, 3, track2) self.assertEqual(len(album.tracks[2]), 1) self.assertEqual(album.tracks.get(2).get(3).title, 'Zhao Hua')
def _process_album(gm_album: gmusic.GMusicAlbum, sp_album: spotify.SpAlbum): # Usually if the user has the entire album added, we won't perform a # per track lookup. However during early stages I want more real test # cases for the matching logic # TODO reorder if statement when we are no longer performing track matching on everything if gm_album.total_tracks() != sp_album.total_tracks: # Sometimes Spotify will have a bonus CD whch GM does not logger.info( 'Album partially added to library - checking if bonus CD is on Spotify') if _bonus_disc_added(gm_album.discs_added(), sp_album.disc_count): logger.info( 'Bonus disc found on Spotify - marking complete album added') gm_album.set_whole_album_added(True) else: logger.info('No bonus disc found - assuming that user only has some tracks added') else: logger.info('Complete album added') gm_album.set_whole_album_added(True) # TODO handle empty results # TODO handle # tracks > return limit _match_tracks(gm_album.tracks, sp_album.tracks)
def test_album_equality(self): """Should mark two separate album instances as the same""" album1 = GMusicAlbum('123', 'testtitle', 'testalbumartist') album2 = GMusicAlbum('123', 'testtitle', 'testalbumartist') self.assertEqual(album1, album2)