def test_default_value_from_env(self): test_utils.set_env_value('my_env_var', 'sky') parameter_model = _create_parameter_model({ 'name': 'def_param', 'default': '$$my_env_var'}) self.assertEqual('sky', parameter_model.default)
def test_env_variables_when_pty(self): test_utils.set_env_value('some_env', 'test') config = create_config_model( 'config_x', script_command='tests/scripts/printenv.sh', requires_terminal=True, parameters=[ create_script_param_config('id'), create_script_param_config('name', env_var='My_Name', param='-n'), create_script_param_config('verbose', param='--verbose', no_value=True), ]) executor._process_creator = create_process_wrapper self.create_executor(config, { 'id': '918273', 'name': 'UserX', 'verbose': True }) self.executor.start() data = read_until_closed(self.executor.get_raw_output_stream(), 100) output = ''.join(data) variables = parse_env_variables(output) self.assertEqual('918273', variables.get('PARAM_ID')) self.assertEqual('UserX', variables.get('My_Name')) self.assertEqual('true', variables.get('PARAM_VERBOSE')) self.assertEqual('test', variables.get('some_env'))
def test_default_value_from_env_when_missing(self): test_utils.set_env_value('my_env_var', 'earth') self.assertRaisesRegex( Exception, 'Environment variable my_env_var2 is not set', _create_parameter_model, {'name': 'def_param', 'default': '$$my_env_var2'})
def test_proxy_credentials(self): test_utils.set_env_value('HTTP_PROXY', 'http://*****:*****@localhost:12345') self.run_initialize() self.assert_proxy('localhost', 12345, username='******', password='******')
def test_replace_any_when_multiple(self): set_env_value('key1', 'Hello') set_env_value('key2', 'world') set_env_value('key3', '!') resolved_val = resolve_env_vars('$$key1 $$key2!$$key3') self.assertEqual('Hello world!!', resolved_val)
def test_replace_any_when_repeating(self): set_env_value('my_key', 'abc') resolved_val = resolve_env_vars('$$my_key,$$my_key.$$my_key') self.assertEqual('abc,abc.abc', resolved_val)
def test_replace_any_when_single_in_middle(self): set_env_value('my_key', 'my_password') resolved_val = resolve_env_vars('start/$$my_key/end') self.assertEqual('start/my_password/end', resolved_val)
def test_replace_any_when_exact(self): set_env_value('my_key', 'my_password') resolved_val = resolve_env_vars('$$my_key') self.assertEqual('my_password', resolved_val)
def test_env_variable(self): test_utils.set_env_value('test_val', 'text') default = self.resolve_default('$$test_val') self.assertEqual(default, 'text')
def test_http_proxy_uppercase(self): test_utils.set_env_value('HTTP_PROXY', 'http://localhost:12345') self.run_initialize() self.assert_proxy('localhost', 12345)
def test_https_proxy_lowercase(self): test_utils.set_env_value('https_proxy', 'https://my.proxy.com:8080/path') self.run_initialize() self.assert_proxy('my.proxy.com', 8080)
def test_default_port(self): test_utils.set_env_value('HTTP_PROXY', 'http://192.168.1.1') self.run_initialize() self.assert_proxy('192.168.1.1', 3128)
def test_script_value_when_env_var(self): test_utils.set_env_value('my_command', 'echo "Hello world"') default = self.resolve_default({'script': '$$my_command'}, working_dir=test_utils.temp_folder) self.assertEqual('Hello world', default)
def test_replace_full_match(self): set_env_value('my_key', 'my_password') resolved_val = resolve_env_vars('$$my_key', full_match=True) self.assertEqual('my_password', resolved_val)
def test_no_pycurl(self): test_utils.set_env_value('HTTP_PROXY', 'http://192.168.1.1') with mock.patch.dict(sys.modules, {'pycurl': None}): tornado_client_config.initialize() self.assert_proxy(None, None)