def setUp(self): self.testdir = getAbsPath(self.testdirname) setupTestfiles(self.testdir, self.testfiles) cherry.config = cherry.config.replace({'media.basedir': self.testdir}) service.provide('dbconnector', MemConnector) database.ensure_current_version(sqlitecache.DBNAME, autoconsent=True) self.Cache = sqlitecache.SQLiteCache()
def setUp(self): self.testdir = getAbsPath(self.testdirname) setupTestfiles(self.testdir, ()) self.setupConfig() service.provide('dbconnector', MemConnector) database.ensure_current_version(sqlitecache.DBNAME, autoconsent=True) self.Cache = sqlitecache.SQLiteCache() self.Cache.full_update()
def _update_if_necessary(self, update): """perform a database update if update (a list of paths to update is not None. If update is an empty list, perform a full update instead of a partial update """ cache = sqlitecache.SQLiteCache() if update: cache.partial_update(*update) elif update is not None: cache.full_update()
def setUp(self): self.testdir = getAbsPath(self.testdirname) setupTestfiles(self.testdir, self.testfiles) self.setupConfig() service.provide('dbconnector', MemConnector) database.ensure_current_version(sqlitecache.DBNAME, autoconsent=True) self.Cache = sqlitecache.SQLiteCache() self.Cache.full_update() self.setupFileObjects() assert self.fileobjects[''].fullpath == os.path.abspath(self.testdir), \ 'precondition: test rootdir has correct fullpath'
def update_filedb(paths): """ Updates the file database in a separate thread, possibly limited to a sequence of paths inside media.basedir See :cls:`~cherrymusicserver.sqlitecache.SQLiteCache` methods :meth:`~cherrymusicserver.sqlitecache.SQLiteCache.full_update` and :meth:`~cherrymusicserver.sqlitecache.SQLiteCache.parital_update`. """ cache = sqlitecache.SQLiteCache() target = cache.partial_update if paths else cache.full_update updater = threading.Thread(name='Updater', target=target, args=paths) updater.start()
def testRollbackOnException(self): class BoobytrappedConnector(MemConnector): exceptcount = 0 def __init__(self): super(self.__class__, self).__init__() self.Connection = type( str('%s.BoobytrappedConnection' % (self.__class__.__module__)), (self.Connection, ), {'execute': self.__execute}) def __execute(connector, stmt, *parameters): '''triggers an Exception when the 'undeletable' item should be removed. relies on way too much knowledge of Cache internals. :( ''' if stmt.lower().startswith('delete from files') \ and parameters[0][0] == undeletable.uid: connector.exceptcount += 1 raise Exception("boom goes the dynamite") return super(connector.Connection, connector.connection(sqlitecache.DBNAME)).execute( stmt, *parameters) # SPECIAL SETUP connector = BoobytrappedConnector() service.provide('dbconnector', connector) database.ensure_current_version(sqlitecache.DBNAME, autoconsent=True) self.Cache = sqlitecache.SQLiteCache() self.Cache.full_update() removelist = self.get_fileobjects_for('root_dir') for fob in removelist: self.id_fileobj(fob) for fob in reversed(removelist): removeTestfile(fob) undeletable = self.fileobjects[os.path.join('root_dir', 'first_dir', 'first_file')] deletable = [self.fileobjects[os.path.join('root_dir', 'first_file')]] # RUN self.Cache.full_update() removed = [f for f in removelist if not self.fileid_in_db(f.uid)] # ASSERT self.assertTrue(1 <= connector.exceptcount, 'test must have raised at least one exception') self.assertEqual( deletable, removed, # self.assertListEqual(deletable, removed, 'complete rollback must restore all deleted entries.')
def setup_cache(testfiles=()): """ Sets up a SQLiteCache instance bound to current `media.basedir`. The basedir is assumed to exist (as it must) and can be initialized with directories and (empty) files. :param list testfiles: Strings of filenames. Names ending in '/' are directories. """ database.resetdb(sqlitecache.DBNAME) database.ensure_current_version(sqlitecache.DBNAME, autoconsent=True) cache = sqlitecache.SQLiteCache() basedir = cherry.config['media.basedir'] assert not os.listdir(basedir) for filename in testfiles: fullpath = os.path.join(basedir, filename) setupTestfile(TestFile(fullpath)) cache.full_update() return cache
def _update_if_necessary(self, update): cache = sqlitecache.SQLiteCache() if update: cache.partial_update(*update) elif update is not None: cache.full_update()
def setupCache(self): service.provide('dbconnector', MemConnector) database.ensure_current_version(sqlitecache.DBNAME, autoconsent=True) self.Cache = sqlitecache.SQLiteCache() self.Cache.full_update()