Example #1
0
 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)
Example #2
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')
Example #3
0
 def test_bad_album(self):
     '''Test that a bad album in the track returns AlbumHasNoTracks.'''
     bad_track = Track('', '', 1, '', 'foo-bar-baz**', 2, 3, '',
         self.music_library._create_album)
     try:
         # pylint: disable-msg=W0612
         album = bad_track.album
         self.fail()
     except AlbumHasNoTracks:
         pass
Example #4
0
class TestTrack(TestMusic):

    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 test_constructor(self):
        '''Test that a Track object is created.'''
        self.assertTrue(isinstance(self.track, Track))
        self.assertEqual(self.track.artist, 'artist0')
        self.assertEqual(self.track.filename, '/path/to/track.mp3')
        self.assertEqual(self.track.length, 240)
        self.assertEqual(self.track.length_string, '4:00')
        self.assertEqual(self.track.lyrics, 'lyrics')
        self.assertEqual(self.track.number, 1)
        self.assertEqual(self.track.title, 'title')
        self.assertEqual(self.track.year, 2008)

    def test_bad_constructor(self):
        '''Test that bad track construction raises an exception for the integer
        fields.'''
        for i in [2, 5, 6]:
            t = ['', '', 1, '', '', 2, 3, '']
            t[i] = str(t[i])
            self.assertRaises(TrackTypeError, Track, t[0], t[1], t[2], t[3],
                t[4], t[5], t[6], t[7], None)

    def test_album_property(self):
        '''Test that an album object is returned.'''
        result = self.track.album
        self.assertTrue(isinstance(result, Album))
        self.assertEqual(result.title, 'album0')

    def test_bad_album(self):
        '''Test that a bad album in the track returns AlbumHasNoTracks.'''
        bad_track = Track('', '', 1, '', 'foo-bar-baz**', 2, 3, '',
            self.music_library._create_album)
        try:
            # pylint: disable-msg=W0612
            album = bad_track.album
            self.fail()
        except AlbumHasNoTracks:
            pass

    def test_get_album_art_url(self):
        '''Test that the album art url is returned.'''
        album_artist = "artist0 - album0"
        album_artist = album_artist.encode("base64")
        album_art = os.path.join(self.art_path, album_artist + ".jpg")
        open(album_art, "wb").close()
        result = self.track.get_album_art_url()
        self.assertEqual(result, album_art)
        if os.path.exists(album_art):
            os.remove(album_art)

        result = self.track.get_album_art_url()
        self.assertEqual(result, None)

    def test_lyrics_property(self):
        '''Test the lyrics property.'''
        self.track.lyrics = 'some new lyrics'
        self.assertEqual(self.track.lyrics, 'some new lyrics')

        self.track.lyrics = None
        self.assertEqual(self.track.lyrics, '')

    def test_get_type(self):
        '''Test that the type is returned.'''
        self.assertEqual(self.track.get_type(), Playable.AUDIO_STREAM)

    def test_get_uri(self):
        '''Test that the uri is returned.'''
        self.assertEqual(self.track.get_uri(), 'file:///path/to/track.mp3')