Esempio n. 1
0
def test_is_docker_image_same_as_yml(category, release_notes_content,
                                     yml_content, filled_expected_result,
                                     pack: Pack):
    """
    Given
    - Case 1: RN containing a docker update, integration YML containing a docker update, where docker image equal in both.
    - Case 2: RN containing a docker update, script YML containing a docker update, where docker image equal in both.
    - Case 3: RN containing a docker update, script YML containing a docker update, where docker image ins't equal in both.
    - Case 4: Release notes without a docker update, YML without a docker update.
    When
    - Running validation on release notes.
    Then
    - Ensure validation correctly identifies valid release notes.
    - Case 1: Should print nothing and return True.
    - Case 2: Should print nothing and return True.
    - Case 3: Should return the prompt "Release notes dockerimage version does not match yml dockerimage version." and
            return False.
    - Case 4: Should print nothing and return True.
    """
    rn = pack.create_release_notes(version='1_0_1',
                                   content=release_notes_content)
    if category == "integration":
        category = pack.create_integration()
    else:
        category = pack.create_script()
    category.yml.update(yml_content)
    validator = ReleaseNotesValidator(rn.path,
                                      modified_files=[category.yml.path],
                                      pack_name=os.path.basename(pack.path))
    assert validator.is_docker_image_same_as_yml() == filled_expected_result
Esempio n. 2
0
    def validate_release_notes(self, file_path, added_files, modified_files, pack_error_ignore_list, is_modified):
        pack_name = get_pack_name(file_path)

        # modified existing RN
        if is_modified:
            error_message, error_code = Errors.modified_existing_release_notes(pack_name)
            if self.handle_error(error_message=error_message, error_code=error_code, file_path=file_path):
                return False

        # added new RN to a new pack
        if pack_name in self.new_packs:
            error_message, error_code = Errors.added_release_notes_for_new_pack(pack_name)
            if self.handle_error(error_message=error_message, error_code=error_code, file_path=file_path):
                return False

        if pack_name != 'NonSupported':
            if not added_files:
                added_files = {file_path}

            release_notes_validator = ReleaseNotesValidator(file_path, pack_name=pack_name,
                                                            modified_files=modified_files,
                                                            added_files=added_files,
                                                            ignored_errors=pack_error_ignore_list,
                                                            print_as_warnings=self.print_ignored_errors)
            return release_notes_validator.is_file_valid()

        return True
Esempio n. 3
0
def get_validator(file_path='', modified_files=None, added_files=None):
    release_notes_validator = ReleaseNotesValidator("")
    release_notes_validator.file_path = file_path
    release_notes_validator.release_notes_path = file_path
    release_notes_validator.latest_release_notes = file_path
    release_notes_validator.modified_files = modified_files
    release_notes_validator.added_files = added_files
    release_notes_validator.pack_name = 'CortexXDR'
    release_notes_validator.ignored_errors = {}
    release_notes_validator.checked_files = set()
    return release_notes_validator
Esempio n. 4
0
def test_init():
    """
    Given
    - Release notes file path

    When
    - Running validation on release notes.

    Then
    - Ensure init returns valid file path and release notes contents.
    """
    filepath = os.path.join(FILES_PATH, 'ReleaseNotes', '1_1_1.md')
    release_notes_validator = ReleaseNotesValidator(filepath)
    release_notes_validator.file_path = 'demisto_sdk/tests/test_files/ReleaseNotes/1_1_1.md'
    assert release_notes_validator.release_notes_path == filepath
    assert release_notes_validator.latest_release_notes == '### Test'
 def test_valid_release_notes_structure(self, source_dummy, target_dummy,
                                        source_release_notes,
                                        target_release_notes, validator,
                                        answer, mocker):
     # type: (str, str, str, str, Type[BaseValidator], Any) -> None
     try:
         copyfile(source_dummy, target_dummy)
         copyfile(source_release_notes, target_release_notes)
         mocker.patch.object(ReleaseNotesValidator,
                             'get_master_diff',
                             side_effect=self.mock_get_master_diff)
         validator = ReleaseNotesValidator(target_dummy)
         assert validator.is_valid_release_notes_structure() is answer
     finally:
         os.remove(target_dummy)
         os.remove(target_release_notes)
Esempio n. 6
0
def test_are_release_notes_complete_rn_config(pack):
    """
    Given:
    - Release notes config file.

    When:
    - Checking if it should have an entry in RN.

    Then:
    - Ensure it is not checked and release notes return valid response.
    """
    rn = pack.create_release_notes('1_0_1', is_bc=True)
    validator = ReleaseNotesValidator(
        rn.path,
        modified_files=[rn.path.replace('md', 'json')],
        pack_name=os.path.basename(pack.path))
    assert validator.are_release_notes_complete()
def get_validator(file_path='', diff=''):
    release_notes_validator = ReleaseNotesValidator("")
    release_notes_validator.file_path = file_path
    release_notes_validator.release_notes_path = file_path
    release_notes_validator.release_notes = file_path
    release_notes_validator.master_diff = diff
    return release_notes_validator
Esempio n. 8
0
 def is_valid_release_notes(self, file_path):
     release_notes_validator = ReleaseNotesValidator(file_path)
     if not release_notes_validator.is_file_valid():
         self._is_valid = False
Esempio n. 9
0
def get_validator(file_path='', modified_files=None, added_files=None):
    release_notes_validator = ReleaseNotesValidator("")
    release_notes_validator.release_notes_file_path = os.path.join(
        FILES_PATH, 'CortexXDR')
    release_notes_validator.release_notes_path = file_path
    release_notes_validator.latest_release_notes = file_path
    release_notes_validator.modified_files = modified_files
    release_notes_validator.added_files = added_files
    release_notes_validator.pack_name = 'CortexXDR'
    release_notes_validator.file_types_that_should_not_appear_in_rn = {
        FileType.TEST_SCRIPT, FileType.TEST_PLAYBOOK, FileType.README,
        FileType.RELEASE_NOTES, None
    }
    release_notes_validator.ignored_errors = {}
    release_notes_validator.checked_files = set()
    release_notes_validator.json_file_path = ''
    release_notes_validator.pack_path = 'Path/CortexXDR'
    release_notes_validator.suppress_print = False
    release_notes_validator.specific_validations = None
    release_notes_validator.predefined_by_support_ignored_errors = {}
    release_notes_validator.predefined_deprecated_ignored_errors = {}
    return release_notes_validator
Esempio n. 10
0
def get_validator(file_path='', modified_files=None, added_files=None):
    release_notes_validator = ReleaseNotesValidator("")
    release_notes_validator.release_notes_file_path = os.path.join(FILES_PATH, 'CortexXDR')
    release_notes_validator.release_notes_path = file_path
    release_notes_validator.latest_release_notes = file_path
    release_notes_validator.modified_files = modified_files
    release_notes_validator.added_files = added_files
    release_notes_validator.pack_name = 'CortexXDR'
    release_notes_validator.file_types_that_should_not_appear_in_rn = {
        FileType.TEST_SCRIPT, FileType.TEST_PLAYBOOK, FileType.README, FileType.RELEASE_NOTES, None}
    release_notes_validator.ignored_errors = {}
    release_notes_validator.checked_files = set()
    return release_notes_validator