def test_get_health_bad(client): expected = { 'cache': [{ 'test_name': 'pinging', 'result': 'failed', 'reason': 'exception raised' }] } runtime.redis_cache = make_cache({'host': 'invalid'}) response = client.simulate_get('/health') assert response.status_code == 400 data = response.json assert data == expected
def __init__(self, app, device, context): self.app_name = app self.app = get_db_app(app) self.device = self.app.get_device(device) if (self.app is not None and device) else None if self.device is not None: self.device_fields = self.device.get_plaintext_fields() self.device_type = self.device.type else: self.device_fields = {} self.device_type = None self.device_id = device self.context = context self._cache = make_cache(walkoff.config.Config.CACHE)
def make_redis(): redis_host = os.environ.get('REDIS_HOST') redis_port = os.environ.get('REDIS_PORT', 6379) options = os.environ.get('REDIS_OPTIONS', {}) config = {'host': redis_host, 'port': redis_port} config.update(options) logger.info('Creating Redis Cache with options {}'.format(config)) redis_cache = make_cache(config) try: redis_cache.ping() except Exception as e: logger.fatal('Could not connect to Redis cache.', exc_info=True) raise return redis_cache
def test_bad_import_no_requires(self): class CustomCacheAdapter(object): def __init__(self): import something_strange self.cache = {} @classmethod def from_json(cls, json_in): return cls() walkoff.cache.cache_translation['__something_strange'] = CustomCacheAdapter config = {'type': '__something_strange', 'directory': walkoff.config.Config.CACHE_PATH} self.assertIsInstance(make_cache(config), DiskCacheAdapter)
def test_get_health_bad(client): expected = { 'cache': [ { 'test_name': 'pinging', 'result': 'failed', 'reason': 'exception raised' } ] } runtime.redis_cache = make_cache({'host': 'invalid'}) response = client.simulate_get('/health') assert response.status_code == 400 data = response.json assert data == expected
def test_bad_import_no_requires(self): class CustomCacheAdapter(object): def __init__(self): import something_strange self.cache = {} @classmethod def from_json(cls, json_in): return cls() mapping = self.mapping.copy() mapping['__something_strange'] = CustomCacheAdapter config = {'type': '__something_strange'} self.assertIsInstance(make_cache(config, cache_mapping=mapping), RedisCacheAdapter)
def make_external_accumulator(config, workflow_execution_id, **kwargs): cache = make_cache(config.CACHE) return ExternallyCachedAccumulator(cache, workflow_execution_id)
def test_redis(self): config = {'type': 'redis'} cache = make_cache(config, cache_mapping=self.mapping) self.assertIsInstance(cache, MockRedisCacheAdapter)
def __setstate__(self, state): self.__dict__.update(state) self.__dict__['_cache'] = make_cache(walkoff.config.Config.CACHE)
def test_disk_type_strange_capitalization(self): config = {'type': 'DiSk', 'directory': walkoff.config.Config.CACHE_PATH} cache = make_cache(config) self.assertIsInstance(cache, DiskCacheAdapter) self.assertEqual(cache.directory, walkoff.config.Config.CACHE_PATH)
def test_unknown_type(self): config = {'type': '__invalid__', 'directory': walkoff.config.Config.CACHE_PATH} cache = make_cache(config) self.assertIsInstance(cache, DiskCacheAdapter) self.assertEqual(cache.directory, walkoff.config.Config.CACHE_PATH)
def test_no_type(self): config = {'directory': walkoff.config.Config.CACHE_PATH} cache = make_cache(config) self.assertIsInstance(cache, DiskCacheAdapter) self.assertEqual(cache.directory, walkoff.config.Config.CACHE_PATH)
def test_make_external_accumulator(self): acc = make_external_accumulator(Config, self.workflow) self.assertIsInstance(acc, ExternallyCachedAccumulator) cache = make_cache(Config.CACHE) self.assertIs(acc._cache, cache)
def test_no_type(self): config = {} cache = make_cache(config, cache_mapping=self.mapping) self.assertIsInstance(cache, MockRedisCacheAdapter)
def test_unknown_type(self): config = {'type': '__invalid__'} cache = make_cache(config, cache_mapping=self.mapping) self.assertIsInstance(cache, RedisCacheAdapter)