コード例 #1
0
ファイル: test_music.py プロジェクト: tiwilliam/entertainer
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))