def test_get_layout_data():
    """
    Given
        - An layout file called layout-to-test.json

    When
        - parsing layout files

    Then
        - parsing all the data from file successfully
    """
    test_dir = f'{git_path()}/demisto_sdk/commands/create_id_set/tests/test_data/layout-to-test.json'
    result = get_layout_data(test_dir)
    result = result.get('urlRep')
    assert 'kind' in result.keys()
    assert 'name' in result.keys()
    assert 'fromversion' in result.keys()
    assert 'toversion' in result.keys()
    assert 'path' in result.keys()
    assert 'typeID' in result.keys()
示例#2
0
    def test_get_layout_data_no_incident_types_and_fields():
        """
        Given
            - A layout file called layout-to-test.json that doesnt have related incident fields and indicator fields

        When
            - parsing layout files

        Then
            - parsing all the data from file successfully
        """
        test_dir = f'{git_path()}/demisto_sdk/commands/create_id_set/tests/test_data/layout-to-test-no-types-fields.json'
        result = get_layout_data(test_dir)
        result = result.get('urlRep')
        assert 'kind' in result.keys()
        assert 'name' in result.keys()
        assert 'fromversion' in result.keys()
        assert 'toversion' in result.keys()
        assert 'file_path' in result.keys()
        assert 'typeID' in result.keys()
        assert 'incident_and_indicator_types' in result.keys()
        assert 'incident_and_indicator_fields' not in result.keys()
示例#3
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