def test_hidden_names_search(cherrypy, cache): model = cherrymodel.CherryModel() cache.searchfor.return_value = [cherrymodel.MusicEntry('.hidden', dir=True)] assert not model.search('something') cache.searchfor.return_value = [cherrymodel.MusicEntry('nothidden', dir=True)] assert model.search('something')
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 makeMusicEntries(n): return [cherrymodel.MusicEntry(str(i)) for i in range(n)]