def check_filelist(startnames, wantnames): with helpers.tempdir('cherrymusic.test_migration_0003') as tmpd: artfolder = helpers.mkpath('art/', tmpd) for name in startnames: helpers.mkpath(name, artfolder) with patch('cherrymusicserver.pathprovider.albumArtFilePath', _mock_artpath(artfolder)): migration_0003.migrate() expected, result = sorted(wantnames), sorted(os.listdir(artfolder)) eq_(expected, result, '\n%r\n%r' % (expected, result))
def test_isplayable(): """ existing, nonempty files of supported types should be playable """ model = cherrymodel.CherryModel() with patch( 'cherrymusicserver.cherrymodel.CherryModel.supportedFormats', ['mp3']): with tempdir('test_isplayable') as tmpdir: mkfile = lambda name, content='': mkpath(name, tmpdir, content) mkdir = lambda name: mkpath(name + '/', tmpdir) with cherryconfig({'media.basedir': tmpdir}): isplayable = model.isplayable assert isplayable(mkfile('ok.mp3', 'content')) assert not isplayable(mkfile('empty.mp3')) assert not isplayable(mkfile('bla.unsupported', 'content')) assert not isplayable(mkdir('directory.mp3')) assert not isplayable('inexistant')
def test_search_results_missing_in_filesystem(): "inexistent MusicEntries returned by sqlitecache search should be ignored" cache_finds = [ cherrymodel.MusicEntry('i-dont-exist.dir', dir=True), cherrymodel.MusicEntry('i-dont-exist.mp3', dir=False), cherrymodel.MusicEntry('i-exist.dir', dir=True), cherrymodel.MusicEntry('i-exist.mp3', dir=False), ] mock_cache = Mock(spec=sqlitecache.SQLiteCache) mock_cache.searchfor.return_value = cache_finds model = cherrymodel.CherryModel() model.cache = mock_cache with tempdir('test_cherrymodel_search_missing_results') as tmpdir: mkpath('i-exist.dir/', tmpdir) mkpath('i-exist.mp3', tmpdir, 'some content') with cherryconfig({'media.basedir': tmpdir}): results = model.search('the query') eq_(set(cache_finds[2:]), set(results))
def test_is_playable_by_transcoding(): """ filetypes should still be playable if they can be transcoded """ from audiotranscode import AudioTranscode with patch('audiotranscode.AudioTranscode', spec=AudioTranscode) as ATMock: ATMock.return_value = ATMock ATMock.availableDecoderFormats.return_value = ['xxx'] with tempdir('test_isplayable_by_transcoding') as tmpdir: with cherryconfig({'media.basedir': tmpdir}): track = mkpath('track.xxx', parent=tmpdir, content='xy') model = cherrymodel.CherryModel() ok_(model.isplayable(track))
def test_fetchLocal_id3(): """Album art can be fetched with tinytag""" # PNG image data, 1 x 1, 1-bit grayscale, non-interlaced _PNG_IMG_DATA = unhexlify(b''.join(b""" 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 0000 0001 0000 0001 0100 0000 0037 6ef9 2400 0000 1049 4441 5478 9c62 6001 0000 00ff ff03 0000 0600 0557 bfab d400 0000 0049 454e 44ae 4260 82""".split())) fetcher = albumartfetcher.AlbumArtFetcher() with patch('cherrymusicserver.albumartfetcher.TinyTag') as TinyTagMock: TinyTagMock.get().get_image.return_value = _PNG_IMG_DATA with helpers.tempdir('test_albumartfetcher') as tmpd: artpath = helpers.mkpath('test.mp3', parent=tmpd) fetcher.fetchLocal(tmpd) TinyTagMock.get.assert_called_with(artpath, image=True) assert TinyTagMock.get().get_image.called