Beispiel #1
0
    def __init__(self, config):
        #BEGIN_CONSTRUCTOR
        self.config = config

        config, err = Validation.validate_config(config)
        if err:
            raise ValueError(err)

        self.call_config = config

        def setwal(db):
            db.cursor().execute("pragma journal_mode=wal")
            # custom auto checkpoint interval (use zero to disable)
            db.wal_autocheckpoint(0)

        apsw.connection_hooks.append(setwal)


        # TODO: move into Model?

        user_profile_cache = UserProfileCache(
            path=config['caches']['userprofile']['path'],
            user_profile_url=config['services']['UserProfile'])
        user_profile_cache.initialize()

        # The app cache can be populated upon load.
        app_cache = AppCache(
            path=config['caches']['app']['path'],
            narrative_method_store_url=config['services']['NarrativeMethodStore']
        )
        app_cache.initialize()

        object_cache = ObjectCache(
            path=config['caches']['object']['path'],
            workspace_url=config['services']['Workspace']
        )
        object_cache.initialize()

        workspace_cache = PermissionsCache(
            path=config['caches']['workspace']['path'],
            workspace_url=config['services']['Workspace']
        )
        workspace_cache.initialize()

        #END_CONSTRUCTOR
        pass
 def test_initialize(self):
     db_path = self.cfg['cache-directory'] + '/app_cache.db'
     test_table = [{
         'constructor': {
             'path':
             db_path,
             'narrative_method_store_url':
             self.cfg['narrative-method-store-url']
         }
     }]
     for test in test_table:
         try:
             app_cache = AppCache(**test['constructor'])
             app_cache.initialize()
             self.assertTrue(True)
         except ValueError as err:
             self.assertTrue(False)
 def test_get(self):
     db_path = self.cfg['cache-directory'] + '/app_cache.db'
     test_table = [{
         'constructor': {
             'path':
             db_path,
             'narrative_method_store_url':
             self.cfg['narrative-method-store-url']
         },
         'input': ['ug_kb_ea_utils/run_Fastq_Multx'],
         'expect': {
             'found': True,
         }
     }, {
         'constructor': {
             'path':
             db_path,
             'narrative_method_store_url':
             self.cfg['narrative-method-store-url']
         },
         'input': ['does_not_exist'],
         'expect': {
             'found': False,
         }
     }]
     for test in test_table:
         try:
             app_cache = AppCache(**test['constructor'])
             app_cache.initialize()
             app_cache.load_all()
             app, found = app_cache.get(*test['input'])
             if (test['expect']['found']):
                 self.assertTrue(found)
                 self.assertIsNotNone(app)
             else:
                 self.assertFalse(found)
         except ValueError as err:
             self.assertTrue(False)
 def test_load(self):
     db_path = self.cfg['cache-directory'] + '/app_cache.db'
     test_table = [{
         'constructor': {
             'path':
             db_path,
             'narrative_method_store_url':
             self.cfg['narrative-method-store-url']
         },
         'load_for_tag': {
             'input': ['dev']
         },
         'expect': {
             'success': True,
             'exception': False
         }
     }, {
         'constructor': {
             'path':
             db_path,
             'narrative_method_store_url':
             self.cfg['narrative-method-store-url']
         },
         'load_for_tag': {
             'input': ['beta']
         },
         'expect': {
             'success': True,
             'exception': False
         }
     }, {
         'constructor': {
             'path':
             db_path,
             'narrative_method_store_url':
             self.cfg['narrative-method-store-url']
         },
         'load_for_tag': {
             'input': ['release']
         },
         'expect': {
             'success': True,
             'exception': False
         }
     }, {
         'constructor': {
             'path':
             db_path,
             'narrative_method_store_url':
             self.cfg['narrative-method-store-url']
         },
         'load_for_tag': {
             'input': ['foo']
         },
         'expect': {
             'success': False,
             'exception': True,
             'exceptionClass': ServiceError,
             'error': {
                 'message': 'Repo-tag [foo] is not supported',
                 'code': -32500,
                 'name': 'JSONRPCError'
             }
         }
     }]
     for test in test_table:
         try:
             app_cache = AppCache(**test['constructor'])
             app_cache.initialize()
             app_cache.load_for_tag(*test['load_for_tag']['input'])
             self.assertTrue(test['expect']['success'])
         except Exception as err:
             # print('ERR', err)
             self.assertTrue(test['expect']['exception'])
             self.assertIsInstance(err, test['expect']['exceptionClass'])
             self.assertIsInstance(str(err), str)
             # print('ERR code', err.args[1])
             # print(test['expect']['error'])
             for key, value in enumerate(test['expect']['error']):
                 self.assertEquals(getattr(err, key), value)