def _create_values_provider(self, values_config, type, constant): if constant: return NoneValuesProvider() if self._is_plain_server_file(): return FilesProvider(self._list_files_dir, self.file_type, self.file_extensions) if (type != 'list') and (type != PARAM_TYPE_MULTISELECT): return NoneValuesProvider() if is_empty(values_config): return EmptyValuesProvider() if isinstance(values_config, list): return ConstValuesProvider(values_config) elif 'script' in values_config: script = values_config['script'] if '${' not in script: return ScriptValuesProvider(script) return DependantScriptValuesProvider(script, self._parameters_supplier) else: message = 'Unsupported "values" format for ' + self.name raise Exception(message)
def test_multiselect_when_single_not_matching_element(self): parameter = self.create_parameter('param') parameter.type = 'multiselect' parameter.values_provider = ConstValuesProvider( ['val1', 'val2', 'val3']) error = model_helper.validate_parameter(parameter, {'param': ['X']}) self.assert_error(error)
def test_multiselect_when_not_list_value(self): parameter = self.create_parameter('param') parameter.type = 'multiselect' parameter.values_provider = ConstValuesProvider( ['val1', 'val2', 'val3']) error = model_helper.validate_parameter(parameter, {'param': 'val1'}) self.assert_error(error)
def test_multiselect_when_empty_list(self): parameter = self.create_parameter('param') parameter.type = 'multiselect' parameter.values_provider = ConstValuesProvider( ['val1', 'val2', 'val3']) error = model_helper.validate_parameter(parameter, {'param': []}) self.assertIsNone(error)
def test_list_parameter_when_matches(self): parameter = self.create_parameter('param') parameter.type = 'list' parameter.values_provider = ConstValuesProvider( ['val1', 'val2', 'val3']) error = model_helper.validate_parameter(parameter, {'param': 'val2'}) self.assertIsNone(error)
def _create_values_provider(self, values_config, type, constant): if constant: return NoneValuesProvider() if self._is_plain_server_file(): return FilesProvider(self._list_files_dir, self.file_type, self.file_extensions) if (type in [PARAM_TYPE_MULTISELECT, PARAM_TYPE_LIST]): if is_empty(values_config): return EmptyValuesProvider() if isinstance(values_config, list): return ConstValuesProvider(values_config) if PARAM_TYPE_DEPENDANT_LIST in values_config: return DependantValuesProvider( self.name, values_config[PARAM_TYPE_DEPENDANT_LIST], self._parameters_supplier) if 'script' in values_config: script = replace_auth_vars(values_config['script'], self._username, self._audit_name) if '${' not in script: return ScriptValuesProvider(script) return DependantScriptValuesProvider(script, self._parameters_supplier) elif (type in ["text"]): if is_empty(values_config): return NoneValuesProvider() if 'script' in values_config: script = values_config['script'] if '${' not in script: return ScriptValuesProvider(script) return DependantScriptValuesProvider(script, self._parameters_supplier) else: return NoneValuesProvider() message = 'Unsupported "values" format for ' + self.name raise Exception(message)
def _create_values_provider(values, parameter, parameters): if values: if isinstance(values, list): return ConstValuesProvider(values) elif 'script' in values: script = values['script'] if '${' not in script: return ScriptValuesProvider(script) return DependantScriptValuesProvider(script, parameters) else: raise Exception('Unsupported "values" format for ' + parameter.name) else: return EmptyValuesProvider()
def _create_values_provider(self, values_config, type, constant): if constant or ((type != 'list') and (type != 'multiselect')): return NoneValuesProvider() if is_empty(values_config): return EmptyValuesProvider() if isinstance(values_config, list): return ConstValuesProvider(values_config) elif 'script' in values_config: script = values_config['script'] if '${' not in script: return ScriptValuesProvider(script) return DependantScriptValuesProvider(script, self._parameters_supplier) else: message = 'Unsupported "values" format for ' + self.name raise Exception(message)
def _create_values_provider(self, values_config, type, constant): if constant: return NoneValuesProvider() if self._is_plain_server_file(): return FilesProvider(self._list_files_dir, self.file_type, self.file_extensions, self.excluded_files_matcher) if (type != 'list') and (type != PARAM_TYPE_MULTISELECT) and ( type != PARAM_TYPE_EDITABLE_LIST): return NoneValuesProvider() if is_empty(values_config): return EmptyValuesProvider() if isinstance(values_config, list): return ConstValuesProvider(values_config) elif 'script' in values_config: original_script = values_config['script'] has_variables = ('${' in original_script) script = replace_auth_vars(original_script, self._username, self._audit_name) shell = read_bool_from_config('shell', values_config, default=not has_variables) if '${' not in script: return ScriptValuesProvider(script, shell) return DependantScriptValuesProvider(script, self._parameters_supplier, shell) else: message = 'Unsupported "values" format for ' + self.name raise Exception(message)