def test_listdir_bad_symlinks(): "cherrymodel.listdir should work when cached files don't exist anymore" model = cherrymodel.CherryModel() with tempdir('test_listdir_bad_symlinks') as tmpdir: with cherryconfig({'media.basedir': tmpdir}): os.symlink('not_there', os.path.join(tmpdir, 'badlink')) eq_([], model.listdir(''))
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 testSkipDirSymlinksBelowBasedirRoot(self): with tempdir('') as tmpd: link = os.path.join(self.testdir, 'root_dir', 'link') target = tmpd os.symlink(target, link) try: self.assertFalse( link in self.enumeratedTestdir(), 'deeply nested dir link must not be returned') finally: os.remove(link)
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.available_decoder_formats.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_listdir_unreadable(): "cherrymodel.listdir should return empty when dir is unreadable" model = cherrymodel.CherryModel() with tempdir('test_listdir_unreadable') as tmpdir: with cherryconfig({'media.basedir': tmpdir}): os.chmod(tmpdir, 0o311) try: open(os.path.join(tmpdir, 'file.mp3'), 'a').close() eq_([], model.listdir('')) finally: # Ensure tmpdir can be cleaned up, even if test fails os.chmod(tmpdir, 0o755)
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_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
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 wrapper(*args, **kwargs): with tempdir(testname) as basedir: testfunc = cherrytest({'media.basedir': basedir})(func) testfunc(*args, **kwargs)