def test_del_variable(self): """Zookeeper cache init del variable.""" cache_ = ZookeeperCache("['127.0.0.1']") variable = cache_.var_to_delete del variable.value self.assertEqual( variable.value, "ERROR: Node NOT EXISTS or was DELETED!")
def test_add_variable(self): """Zookeeper cache add variable.""" cache_ = ZookeeperCache("['127.0.0.1']") variable = cache_.var_to_add self.assertIsInstance( variable, Variable )
def test_set_variable(self): """Zookeeper cache init set variable.""" cache_ = ZookeeperCache("['127.0.0.1']") variable = cache_.my_var random_int = randint(0, 100) variable.value = random_int self.assertEqual(variable.value, random_int) random_int = randint(0, 100) variable.value = str(random_int) self.assertEqual(variable.value, str(random_int))
def __init__(self, env, cache_manager=None): # Get all environment variables self.iam = Container() self.iam.token = env.get('IAM_TOKEN') self.iam.client_id = env.get('IAM_CLIENT_ID') self.iam.client_secret = env.get('IAM_CLIENT_SECRET') self.marathon = Container() self.marathon.user = env.get('MARATHON_USER'), self.marathon.passwd = env.get('MARATHON_PASSWD') # CACHE self.cache_dir = '/tmp' if cache_manager == 'ZOOKEEPER': self.cache = ZookeeperCache(env.get('ZOOKEEPER_HOST_LIST')) elif cache_manager == 'MARATHON': self.cache = MarathonCache(self.marathon.user, self.marathon.passwd) else: self.cache = MemoryCache() # LOAD PROXY CONFIG FILE with open(CONFIG_FILE_PATH) as config_file: proxy_config = json.load(config_file) # Configuration containers self.config = Container() self.config.local_cache = Container() self.config.lock_file = Container() self.config.tts = Container() self.config.iam = Container() self.config.user = Container() # Configuration variables self.config.local_cache.expiration_time = proxy_config.get( 'local_cache_expiration_time') self.config.audience = proxy_config.get('audience') self.config.lock_file.age = proxy_config.get('lock_file_age') self.config.lock_file.path = "{}/lock".format(self.cache_dir) self.config.tts.url = proxy_config.get('tts') self.config.tts.output_data = '{}/output.json'.format(self.cache_dir) self.config.iam.endpoint = proxy_config.get('iam_endpoint') self.config.iam.token_endpoint = self.config.iam.endpoint + 'token' self.config.iam.introspect_endpoint = self.config.iam.endpoint + 'introspect' self.config.iam.credential_endpoint = proxy_config.get( 'credential_endpoint') self.config.user.cert = "{}/usercert.crt".format(self.cache_dir) self.config.user.key = "{}/userkey.key".format(self.cache_dir) self.config.user.passwd = "{}/userpasswd.txt".format(self.cache_dir) self.config.user.proxy = "{}/userproxy.pem".format(self.cache_dir) self.exchanged_token = ""
def test_get_variable(self): """Zookeeper cache init get variable.""" cache_ = ZookeeperCache("['127.0.0.1']") variable_name = "myvar" + str(randint(0, 100)) variable = cache_.add_variable(variable_name) self.assertEqual(variable.value, None)
def test_init(self): """Zookeeper cache init.""" cache_ = ZookeeperCache("['127.0.0.1']") self.assertIsInstance(cache_, CacheManager)