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()
Esempio n. 2
0
 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()
Esempio n. 4
0
 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 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(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'
Esempio n. 7
0
 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'
Esempio n. 8
0
    def setUp(self):
        service.provide('dbconnector', MemConnector)
        database.ensure_current_version(userdb.DBNAME)
        self.users = userdb.UserDB()
        self.users.addUser('user', 'password', False)

        #unittest2 compability
        if not hasattr(self,'assertTupleEqual'):
            def assertTupEq(t1,t2,msg):
                if not all(i==j for i,j in zip(t1,t2)):
                    raise AssertionError(msg)
            self.assertTupleEqual = assertTupEq
Esempio n. 9
0
    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.')
Esempio n. 10
0
    def setUp(self):
        service.provide('dbconnector', MemConnector)
        database.ensure_current_version(userdb.DBNAME)
        self.users = userdb.UserDB()
        self.users.addUser('user', 'password', False)

        #unittest2 compability
        if not hasattr(self, 'assertTupleEqual'):

            def assertTupEq(t1, t2, msg):
                if not all(i == j for i, j in zip(t1, t2)):
                    raise AssertionError(msg)

            self.assertTupleEqual = assertTupEq
Esempio n. 11
0
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
Esempio n. 12
0
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
Esempio n. 13
0
def migrate_databases():
    """ Makes sure CherryMusic's databases are up to date, migrating them if
        necessary.

        This might prompt the user for consent if a migration requires it and
        terminate the program if no consent is obtained.

        See :mod:`~cherrymusicserver.databases`.
    """
    db_is_ready = database.ensure_current_version(
        consentcallback=_get_user_consent_for_db_schema_update)
    if not db_is_ready:
        log.i(_("database schema update aborted. quitting."))
        sys.exit(1)
Esempio n. 14
0
def migrate_databases():
    """ Makes sure CherryMusic's databases are up to date, migrating them if
        necessary.

        This might prompt the user for consent if a migration requires it and
        terminate the program if no consent is obtained.

        See :mod:`~cherrymusicserver.databases`.
    """
    db_is_ready = database.ensure_current_version(
        consentcallback=_get_user_consent_for_db_schema_update)
    if not db_is_ready:
        log.i(_("database schema update aborted. quitting."))
        sys.exit(1)
Esempio n. 15
0
 def setup_databases(self, update, dropfiledb, setup):
     if dropfiledb:
         update = ()
         database.resetdb(sqlitecache.DBNAME)
     if setup:
         update = update or ()
     db_is_ready = database.ensure_current_version(
         consentcallback=self._get_user_consent_for_db_schema_update)
     if not db_is_ready:
         log.i("database schema update aborted. quitting.")
         sys.exit(1)
     if update is not None:
         cacheupdate = threading.Thread(name="Updater",
                                        target=self._update_if_necessary,
                                        args=(update,))
         cacheupdate.start()
         # self._update_if_necessary(update)
         if not setup:
             sys.exit(0)
Esempio n. 16
0
 def setup_databases(self, update, dropfiledb, setup):
     """ delete or update the file db if so requested.
     check if the db schema is up to date
     """
     if dropfiledb:
         update = ()
         database.resetdb(sqlitecache.DBNAME)
     if setup:
         update = update or ()
     db_is_ready = database.ensure_current_version(
         consentcallback=self._get_user_consent_for_db_schema_update)
     if not db_is_ready:
         log.i(_("database schema update aborted. quitting."))
         sys.exit(1)
     if update is not None:
         cacheupdate = threading.Thread(name="Updater",
                                        target=self._update_if_necessary,
                                        args=(update,))
         cacheupdate.start()
         # self._update_if_necessary(update)
         if not setup:
             CherryMusic.stopAndCleanUp()
Esempio n. 17
0
def setup_module():
    service.provide('dbconnector', database.sql.MemConnector)
    database.ensure_current_version(useroptiondb.DBNAME, autoconsent=True)
Esempio n. 18
0
 def setupCache(self):
     service.provide('dbconnector', MemConnector)
     database.ensure_current_version(sqlitecache.DBNAME, autoconsent=True)
     self.Cache = sqlitecache.SQLiteCache()
     self.Cache.full_update()
Esempio n. 19
0
 def setupCache(self):
     service.provide('dbconnector', MemConnector)
     database.ensure_current_version(sqlitecache.DBNAME, autoconsent=True)
     self.Cache = sqlitecache.SQLiteCache()
     self.Cache.full_update()
Esempio n. 20
0
def setup_module():
    service.provide('dbconnector', database.sql.MemConnector)
    database.ensure_current_version(useroptiondb.DBNAME, autoconsent=True)
Esempio n. 21
0
def setup():
    service.provide('dbconnector', database.sql.TmpConnector)
    database.ensure_current_version(DBNAME)
Esempio n. 22
0
def setup():
    service.provide("dbconnector", database.sql.TmpConnector)
    database.ensure_current_version(DBNAME)