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 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_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_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))