class TestAlbum(TestMusic): '''Tests Album''' def setUp(self): TestMusic.setUp(self) self.music_library = MusicLibrary() self.album = self.music_library._create_album('album1') def test_constructor(self): """Test that an Album object is properly constructed""" self.assertTrue(isinstance(self.album, Album)) self.assertEqual(self.album.artist, 'artist0') self.assertEqual(self.album.length, 8) self.assertEqual(self.album.title, 'album1') self.assertEqual(self.album.year, 0) def test_constructor_not(self): """Test that an AlbumHasNoTracks exception is raised when the created album doesn't exist in the cache""" self.assertRaises(AlbumHasNoTracks, self.music_library._create_album, 'foo') def test_has_album_art(self): """Test that album art exists for the file""" album_artist = "artist0 - album1" album_artist = album_artist.encode("base64") album_art = os.path.join(self.art_path, album_artist + ".jpg") open(album_art, "wb").close() self.assertTrue(self.album.has_album_art()) if os.path.exists(album_art): os.remove(album_art) def test_has_album_art_not(self): """Test that missing album art is reported back""" other_album = self.music_library._create_album('album1') self.assertFalse(other_album.has_album_art()) def test_album_art_url(self): """Test that the path to the album's art is returned""" result = self.album.album_art_url album_artist = "artist0 - album1" album_artist = album_artist.encode("base64") album_art = os.path.join(self.art_path, album_artist + ".jpg") self.assertEqual(result, album_art) def test_tracks(self): """Test that all tracks for an album are returned""" result = self.album.tracks self.assertEqual(len(result), 4) for i in result: self.assertTrue(isinstance(i, Track))
def setUp(self): TestMusic.setUp(self) self.music_library = MusicLibrary() self.track = Track('/path/to/track.mp3', # filename 'title', 1, # tracknumber 'artist0', 'album0', 2008, # year 240, # length 'lyrics', self.music_library._create_album)
def __init__(self): config = Configuration() music_library = MusicLibrary() image_library = ImageLibrary() video_library = VideoLibrary() self.ui = UserInterface(image_library, music_library, video_library, self.quit_client) if config.tray_icon_enabled: SystemTrayIcon(self.quit_client, self.toggle_interface_visibility) startLogging(sys.stdout) client = EntertainerLocalClientProtocol ClientCreator(reactor, client)
def setUp(self): TestMusic.setUp(self) self.music_library = MusicLibrary() self.album = self.music_library._create_album('album1')
def setUp(self): TestMusic.setUp(self) self.musiclibrary = MusicLibrary()
class TestMusicLibrary(TestMusic): '''Tests MusicLibrary''' def setUp(self): TestMusic.setUp(self) self.musiclibrary = MusicLibrary() def test_music_library_constructor(self): '''Test that the music library contructor works.''' self.assertTrue(isinstance(self.musiclibrary, MusicLibrary)) def testGetAllArtists(self): """testGetAllArtists - Ensures that all artists are returned from the music library""" result = self.musiclibrary.get_all_artists() self.assertEqual(result, ['artist0']) def testGetTracksByArtist(self): """testGetTracksByArtist - Ensure tracks by a certain artist are returned""" result = self.musiclibrary.get_tracks_by_artist('artist0') self.assertEqual(len(result), 8) for i in result: self.assertEqual(i.artist, 'artist0') def testGetTracksByUnknownArtist(self): """testGetTracksByUnknownArtist - Ensure proper handling of an missing artist in the cache""" self.assertEquals( len(self.musiclibrary.get_tracks_by_artist('foo')), 0) def testGetAllAlbums(self): """testGetAllAlbums - Ensures all albums are returned""" result = self.musiclibrary.get_all_albums() for i in result: self.assertTrue(isinstance(i, Album)) self.assertEqual(len(result), 2) def testGetAlbumsByArtist(self): """testGetAlbumsByArtist - Ensures correct albums by an artist is returned""" result = self.musiclibrary.get_albums_by_artist('artist0') self.assertEqual(len(result), 2) for i in result: self.assertEqual(i.artist, 'artist0') def testGetAlbumsByUnknownArtist(self): """testGetAlbumsByUnknownArtist - Ensures proper handling of an artist not in the cache""" self.assertEquals( len(self.musiclibrary.get_albums_by_artist('foo')), 0) def testNumberOfTracks(self): """testNumberOfTracks - Ensures number of all tracks is returned""" result = self.musiclibrary.number_of_tracks() self.assertEqual(result, 8) def testNumberOfTracksByArtist(self): """testNumberOfTracksByArtist - Ensures number of all tracks by one artist is returned""" result = self.musiclibrary.number_of_tracks_by_artist('artist0') self.assertEqual(result, 8) def testNumberOfTracksByUnknownArtist(self): """testNumberOfTracksByUnknownArtist - Ensures proper handling when artist called is not in the cache""" self.assertEqual( self.musiclibrary.number_of_albums_by_artist('foo'), 0) def testNumberOfAlbumsByArtist(self): """testNumberOfAlbumsByArtist - Ensures number of all albums by one artist is returned""" result = self.musiclibrary.number_of_albums_by_artist('artist0') self.assertEqual(result, 2) def testNumberOfAlbumsByUnknownArtist(self): """testNumberOfAlbumsByUnknownArtist - Ensures proper handling when artist called is not in the cache""" self.assertEqual( self.musiclibrary.number_of_albums_by_artist('foo'), 0) def testSaveLyrics(self): """testSaveLyrics - Ensures lyrics for a track are saved in the database""" # Only need a filename that matches something in the database, the rest # of the track is for construction purposes only track = Track('/filename/000', '', 0, '', '', 0, 1, '', None) self.musiclibrary.save_lyrics(track, 'some lyrics here') self.assertEqual(track.lyrics, 'some lyrics here')