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'], 'token': self.token, 'username': self.username } }] for test in test_table: try: cache = PermissionsCache(**test['constructor']) cache.initialize() 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_perf(self): db_path = self.cfg['cache-directory'] + '/object_cache.db' # test_table = [ # { # 'constructor': { # 'path': db_path, # 'workspace_url': self.cfg['workspace-url'], # 'token': self.token, # 'username': self.username # }, # 'add_items': [[ # [1, 'me', 'hi'], # [4, 'you', 'hello'] # ]] # } # ] constructor = { 'path': db_path, 'workspace_url': self.cfg['workspace-url'], 'token': self.token, 'username': self.username } data = {'field1': 'value1', 'field2': 'value2', 'field3': 1234} test_data = ([i, 'eapearson', json.dumps(data)] for i in xrange(0, 1000)) # for test_data in test_table: try: cache = PermissionsCache(**constructor) cache.initialize() start = time.time() print('START') # print(test_data) cache.add_items(test_data) elapsed = time.time() - start print('END %s' % (elapsed / 1000)) all = cache.get_all_items() self.assertGreater(len(all), 0) # 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_fetch_items(self): db_path = self.cfg['cache-directory'] + '/object_cache.db' test_table = [{ 'constructor': { 'path': db_path, 'workspace_url': self.cfg['workspace-url'], 'token': self.token, 'username': self.username }, 'fetch_items': [[[34742, 'eapearson'], [34599, 'eapearson']]] }] for test in test_table: try: cache = PermissionsCache(**test['constructor']) cache.initialize() items = cache.fetch_items(*test['fetch_items']) self.assertEqual(len(items), 2) except ValueError as err: print('ERROR!', err) self.assertTrue(False)
def test_get(self): db_path = self.cfg['cache-directory'] + '/object_cache.db' test_table = [{ 'constructor': { 'path': db_path, 'workspace_url': self.cfg['workspace-url'], 'token': self.token, 'username': self.username }, 'get': [[34742, 34599]] }] for test in test_table: try: cache = PermissionsCache(**test['constructor']) cache.initialize() items = cache.get(*test['get']) self.assertEqual(len(items), 2) items = cache.get(*test['get']) self.assertEqual(len(items), 2) self.assertTrue(True) except ValueError as err: self.assertTrue(False)
def test_get_items(self): db_path = self.cfg['cache-directory'] + '/object_cache.db' test_table = [{ 'constructor': { 'path': db_path, 'workspace_url': self.cfg['workspace-url'], 'token': self.token, 'username': self.username }, 'add_items': [[[34742, 'eapearson', 'hi'], [34742, 'eapearson', 'hello']]], 'get_items': [[[34742, 'eapearson'], [34599, 'eapearson']]] }] for test in test_table: try: cache = PermissionsCache(**test['constructor']) cache.initialize() cache.add_items(*test['add_items']) items = cache.get_items(*test['get_items']) self.assertGreater(len(items), 0) self.assertTrue(True) except ValueError as err: self.assertTrue(False)
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'], 'token': self.token, 'username': self.username }, 'add_items': [[[1, 'me', 'hi'], [4, 'you', 'hello']]] }] for test in test_table: try: cache = PermissionsCache(**test['constructor']) cache.initialize() cache.add_items(*test['add_items']) all = cache.get_all_items() self.assertGreater(len(all), 0) # TODO: test that the items are present and the only ones. self.assertTrue(True) except ValueError as err: print('ERROR!', err) self.assertTrue(False)