Пример #1
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()
Пример #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()
Пример #3
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()
Пример #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()
Пример #5
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.')
    def test_api_compactlistdir_must_call_cherrymodel_listdir(self):
        mock = MagicMock(spec=CherryModel)
        oldservice = service.get('cherrymodel')
        service.provide('cherrymodel', mock)

        self.http.api_compactlistdir('dir', filterstr='x')
        mock.listdir.assert_called_with('dir', 'x')

        service.provide('cherrymodel', oldservice)
Пример #7
0
    def test_api_compactlistdir_must_call_cherrymodel_listdir(self):
        mock = MagicMock(spec=CherryModel)
        oldservice = service.get('cherrymodel')
        service.provide('cherrymodel', mock)

        self.http.api_compactlistdir('dir', filterstr='x')
        mock.listdir.assert_called_with('dir', 'x')

        service.provide('cherrymodel', oldservice)
Пример #8
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'
Пример #9
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'
Пример #10
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.')
Пример #11
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
Пример #12
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
def init_services():
    realconnector = db.sql.SQLiteConnector(datadir=config['runtime.path.data'])
    service.provide(db.connect.SharedConnectionWrapper, args=(realconnector,))
Пример #14
0
class MockAction(Exception):
    pass

class MockModel:
    def __init__(self):
        pass
    def search(self,value,isFastSearch=False):
        if isFastSearch:
            return [MusicEntry('fast mock result','fast mock result')]
        else:
            return [MusicEntry('mock result','mock result')]
    def motd(self):
        return "motd"
    def updateLibrary(self):
        raise MockAction('updateLibrary')
service.provide('cherrymodel', MockModel)


class CherryPyMock:
    def __init__(self):
        self.session = {'admin': False}

from cherrymusicserver.playlistdb import PlaylistDB
MockPlaylistDB = Mock(spec=PlaylistDB)
service.provide('playlist', MockPlaylistDB)


class TestHTTPHandler(unittest.TestCase):
    def setUp(self):
        self.http = httphandler.HTTPHandler(cherry.config)
        for apicall, func in self.http.handlers.items():
Пример #15
0
def setup_module():
    service.provide('dbconnector', database.sql.MemConnector)
    database.ensure_current_version(useroptiondb.DBNAME, autoconsent=True)
Пример #16
0
def teardown():
    service.provide("dbconnector", None)
Пример #17
0
def setup():
    service.provide("dbconnector", database.sql.TmpConnector)
    database.ensure_current_version(DBNAME)
Пример #18
0
 def __init__(self):
     service.provide('fooservice', self.__class__)
     assert self.myfoo
Пример #19
0
 def setup_services(cls):
     service.provide('filecache', sqlitecache.SQLiteCache)
     service.provide('cherrymodel', cherrymodel.CherryModel)
     service.provide('playlist', playlistdb.PlaylistDB)
     service.provide('users', userdb.UserDB)
     service.provide('useroptions', useroptiondb.UserOptionDB)
     service.provide('dbconnector', database.sql.SQLiteConnector, kwargs={
         'datadir': pathprovider.databaseFilePath(''),
         'extension': 'db',
         'connargs': {'check_same_thread': False},
     })
        pass

    def search(self, value, isFastSearch=False):
        if isFastSearch:
            return [MusicEntry('fast mock result', 'fast mock result')]
        else:
            return [MusicEntry('mock result', 'mock result')]

    def motd(self):
        return "motd"

    def updateLibrary(self):
        raise MockAction('updateLibrary')


service.provide('cherrymodel', MockModel)


class CherryPyMock:
    def __init__(self):
        self.session = {'admin': False}


from cherrymusicserver.playlistdb import PlaylistDB
MockPlaylistDB = Mock(spec=PlaylistDB)
service.provide('playlist', MockPlaylistDB)


@contextmanager
def mock_auth():
    ''' Context where user 1 is logged in '''
Пример #21
0
 def setup_services(cls):
     """setup services: they can be used by other parts of the program
     to easily access different functions of cherrymusic by registering
     themselves as service.user
     """
     service.provide('filecache', sqlitecache.SQLiteCache)
     service.provide('cherrymodel', cherrymodel.CherryModel)
     service.provide('playlist', playlistdb.PlaylistDB)
     service.provide('users', userdb.UserDB)
     service.provide('useroptions', useroptiondb.UserOptionDB)
     service.provide('dbconnector', database.sql.SQLiteConnector, kwargs={
         'datadir': pathprovider.databaseFilePath(''),
         'extension': 'db',
         'connargs': {'check_same_thread': False},
     })
Пример #22
0
def setup_module():
    service.provide('dbconnector', database.sql.MemConnector)
    database.ensure_current_version(useroptiondb.DBNAME, autoconsent=True)
Пример #23
0
 def setupCache(self):
     service.provide('dbconnector', MemConnector)
     database.ensure_current_version(sqlitecache.DBNAME, autoconsent=True)
     self.Cache = sqlitecache.SQLiteCache()
     self.Cache.full_update()
Пример #24
0
def setup():
    service.provide('dbconnector', database.sql.TmpConnector)
    database.ensure_current_version(DBNAME)
Пример #25
0
def teardown():
    service.provide('dbconnector', None)
Пример #26
0
 def setupCache(self):
     service.provide('dbconnector', MemConnector)
     database.ensure_current_version(sqlitecache.DBNAME, autoconsent=True)
     self.Cache = sqlitecache.SQLiteCache()
     self.Cache.full_update()
Пример #27
0
def teardown():
    service.provide('dbconnector', None)