def test_initialize(self): db_path = self.cfg['cache-directory'] + '/object_cache.db' test_table = [{ 'constructor': { 'path': db_path, 'workspace_url': self.cfg['workspace-url'] } }] for test in test_table: try: app_cache = ObjectCache(**test['constructor']) app_cache.initialize() self.assertTrue(True) except ValueError as err: self.assertTrue(False)
def test_caching(self): db_path = self.cfg['cache-directory'] + '/object_cache.db' test_table = [{ 'constructor': { 'path': db_path, 'workspace_url': self.cfg['workspace-url'] }, 'get': [[[34742, 1, None], [34599, 1, None]]] }] for test in test_table: try: object_cache = ObjectCache(**test['constructor']) object_cache.initialize() items = object_cache.get_items(*test['get']) self.assertTrue(True) except ValueError as err: self.assertTrue(False)
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_add_items(self): db_path = self.cfg['cache-directory'] + '/object_cache.db' test_table = [{ 'constructor': { 'path': db_path, 'workspace_url': self.cfg['workspace-url'] }, 'add_items': [[[1, 2, 3, 'hi'], [4, 5, 6, 'hello']]] }] for test in test_table: try: object_cache = ObjectCache(**test['constructor']) object_cache.initialize() object_cache.add_items(*test['add_items']) all = object_cache.get_all_items() # TODO: test that the items are present and the only ones. self.assertTrue(True) except ValueError as err: print('ERROR!', err) self.assertTrue(False)
def test_get2(self): db_path = self.cfg['cache-directory'] + '/object_cache.db' now = int(round(time.time() * 1000)) now2 = now + 10000 test_table = [{ 'constructor': { 'path': db_path, 'workspace_url': self.cfg['workspace-url'], 'token': self.token }, 'get1': [[[34742, 1, now], [34599, 1, now]]], 'get2': [[[34742, 1, now2], [34599, 1, 1532558773000]]] }] for test in test_table: try: object_cache = ObjectCache(**test['constructor']) object_cache.initialize() items = object_cache.get(*test['get1']) items2 = object_cache.get(*test['get2']) self.assertTrue(True) except ValueError as err: self.assertTrue(False)