def test_get_script_or_integration_package_data():
    unifier = IntegrationScriptUnifier(f"{git_path()}/demisto_sdk/tests/test_files/Unifier/SampleNoPyFile")
    with pytest.raises(Exception):
        unifier.get_script_or_integration_package_data()
    unifier = IntegrationScriptUnifier(f"{git_path()}/demisto_sdk/tests/test_files/CalculateGeoDistance")
    with open(f"{git_path()}/demisto_sdk/tests/test_files/CalculateGeoDistance/CalculateGeoDistance.py", "r") as \
            code_file:
        code = code_file.read()
    yml_path, code_data = unifier.get_script_or_integration_package_data()
    assert yml_path == f"{git_path()}/demisto_sdk/tests/test_files/CalculateGeoDistance/CalculateGeoDistance.yml"
    assert code_data == code
Example #2
0
    def is_file_valid_in_set(self, file_path, file_type, ignored_errors=None):
        """Check if the file is valid in the id_set

        Args:
            file_path (string): Path to the file.
            file_type (string): The file type.
            ignored_errors (list): a list of ignored errors for the specific file

        Returns:
            bool. Whether the file is valid in the id_set or not.
        """
        self.ignored_errors = ignored_errors
        is_valid = True
        if self.is_circle:  # No need to check on local env because the id_set will contain this info after the commit
            click.echo(f"id set validations for: {file_path}")

            if re.match(constants.PACKS_SCRIPT_YML_REGEX, file_path,
                        re.IGNORECASE):
                unifier = IntegrationScriptUnifier(os.path.dirname(file_path))
                yml_path, code = unifier.get_script_or_integration_package_data(
                )
                script_data = get_script_data(yml_path, script_code=code)
                is_valid = self._is_non_real_command_found(script_data)
            elif file_type == constants.FileType.INCIDENT_TYPE:
                incident_type_data = OrderedDict(
                    get_incident_type_data(file_path))
                is_valid = self._is_incident_type_default_playbook_found(
                    incident_type_data)
            elif file_type == constants.FileType.INCIDENT_FIELD:
                incident_field_data = OrderedDict(
                    get_incident_field_data(file_path, []))
                is_valid = self._is_incident_field_scripts_found(
                    incident_field_data, file_path)
            elif file_type == constants.FileType.LAYOUTS_CONTAINER:
                layouts_container_data = OrderedDict(
                    get_layoutscontainer_data(file_path))
                is_valid = self._is_layouts_container_scripts_found(
                    layouts_container_data, file_path)
            elif file_type == constants.FileType.LAYOUT:
                layout_data = OrderedDict(get_layout_data(file_path))
                is_valid = self._is_layout_scripts_found(
                    layout_data, file_path)
            elif file_type == constants.FileType.INTEGRATION:
                integration_data = get_integration_data(file_path)
                is_valid = self._is_integration_classifier_and_mapper_found(
                    integration_data)
            elif file_type == constants.FileType.CLASSIFIER:
                classifier_data = get_classifier_data(file_path)
                is_valid = self._is_classifier_incident_types_found(
                    classifier_data)
            elif file_type == constants.FileType.MAPPER:
                mapper_data = get_mapper_data(file_path)
                is_valid = self._is_mapper_incident_types_found(mapper_data)
            elif file_type == constants.FileType.PLAYBOOK:
                playbook_data = get_playbook_data(file_path)
                playbook_answers = [
                    self._are_playbook_entities_versions_valid(
                        playbook_data, file_path),
                    self.is_subplaybook_name_valid(playbook_data, file_path)
                ]
                is_valid = all(playbook_answers)
        return is_valid