Exemple #1
0
    def test_multiple_files(self):
        test_utils.create_files(['My.txt', 'file.dat', 'test.sh', 'file2.txt'])
        test_utils.create_dir('documents')
        test_utils.create_files(['another.txt'], 'documents')

        provider = FilesProvider(test_utils.temp_folder, file_extensions=['txt'])
        self.assertEqual(['file2.txt', 'My.txt'], provider.get_values({}))
    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 _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(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)
Exemple #5
0
 def test_no_files(self):
     provider = FilesProvider(test_utils.temp_folder)
     self.assertEqual([], provider.get_values({}))
Exemple #6
0
 def test_invalid_file_dir(self):
     provider = FilesProvider('some_missing_folder')
     self.assertEqual([], provider.get_values({}))
Exemple #7
0
 def read_provider_values(self, file_type=None, file_extensions=None):
     provider = FilesProvider(test_utils.temp_folder,
                              file_type=file_type,
                              file_extensions=file_extensions)
     values = provider.get_values({})
     return values