def validate_added_files(self, added_files): """Validate the added files from your branch. In case we encounter an invalid file we set the self._is_valid param to False. Args: added_files (set): A set of the modified files in the current branch. """ for file_path in added_files: print("Validating {}".format(file_path)) structure_validator = StructureValidator(file_path, is_added_file=True) if not structure_validator.is_file_valid(): self._is_valid = False if not self.id_set_validator.is_file_valid_in_set(file_path): self._is_valid = False if self.id_set_validator.is_file_has_used_id(file_path): self._is_valid = False if re.match(TEST_PLAYBOOK_REGEX, file_path, re.IGNORECASE): if not self.conf_json_validator.is_test_in_conf_json(collect_ids(file_path)): self._is_valid = False elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \ re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE) or \ re.match(IMAGE_REGEX, file_path, re.IGNORECASE): image_validator = ImageValidator(file_path) if not image_validator.is_valid(): self._is_valid = False description_validator = DescriptionValidator(file_path) if not description_validator.is_valid(): self._is_valid = False integration_validator = IntegrationValidator(file_path) if not integration_validator.is_valid_integration(): self._is_valid = False elif re.match(BETA_INTEGRATION_REGEX, file_path, re.IGNORECASE) or \ re.match(BETA_INTEGRATION_YML_REGEX, file_path, re.IGNORECASE): description_validator = DescriptionValidator(file_path) if not description_validator.is_valid_beta_description(): self._is_valid = False integration_validator = IntegrationValidator(file_path) if not integration_validator.is_valid_beta_integration(is_new=True): self._is_valid = False elif re.match(IMAGE_REGEX, file_path, re.IGNORECASE): image_validator = ImageValidator(file_path) if not image_validator.is_valid(): self._is_valid = False elif re.match(INCIDENT_FIELD_REGEX, file_path, re.IGNORECASE) or \ re.match(INCIDENT_FIELDS_REGEX, file_path, re.IGNORECASE): incident_field_validator = IncidentFieldValidator(file_path) if not incident_field_validator.is_valid(): self._is_valid = False
def test_is_valid_content_flag_sanity(): validator = IncidentFieldValidator('temp_file', check_git=False) validator.current_incident_field = { 'content': True } assert validator.is_valid_content_flag() assert validator.is_valid()
def test_is_valid_system_flag_invalid(): validator = IncidentFieldValidator('temp_file', check_git=False) validator.current_incident_field = { 'system': True, 'content': True, } assert not validator.is_valid_system_flag() assert not validator.is_valid()
def test_is_valid_name_sanity(): validator = IncidentFieldValidator('temp_file', check_git=False) validator.current_incident_field = { 'cliName': 'sanity name', 'name': 'sanity name', 'id': 'incident', 'content': True, } assert validator.is_valid_name() assert validator.is_valid()
def test_is_valid_content_flag_invalid_values(): validator = IncidentFieldValidator('temp_file', check_git=False) validator.current_incident_field = { 'content': False } assert not validator.is_valid_content_flag() assert not validator.is_valid() validator.current_incident_field = { 'something': True } assert not validator.is_valid_content_flag() assert not validator.is_valid()
def validate_modified_files(self, modified_files, is_backward_check=True, old_branch='master'): """Validate the modified files from your branch. In case we encounter an invalid file we set the self._is_valid param to False. Args: modified_files (set): A set of the modified files in the current branch. is_backward_check (bool): When set to True will run backward compatibility checks old_branch (str): Old git branch to compare backward compatibility check to """ for file_path in modified_files: old_file_path = None if isinstance(file_path, tuple): old_file_path, file_path = file_path is_python_file = FilesValidator.is_py_script_or_integration(file_path) print('Validating {}'.format(file_path)) if not checked_type(file_path): print_warning('- Skipping validation of non-content entity file.') continue structure_validator = StructureValidator(file_path, is_added_file=not (False or is_backward_check), is_renamed=old_file_path is not None) if not structure_validator.is_file_valid(): self._is_valid = False if not self.id_set_validator.is_file_valid_in_set(file_path): self._is_valid = False elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \ re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE): image_validator = ImageValidator(file_path) if not image_validator.is_valid(): self._is_valid = False description_validator = DescriptionValidator(file_path) if not description_validator.is_valid(): self._is_valid = False integration_validator = IntegrationValidator(file_path, old_file_path=old_file_path, old_git_branch=old_branch) if is_backward_check and not integration_validator.is_backward_compatible(): self._is_valid = False if not integration_validator.is_valid_integration(): self._is_valid = False if is_python_file: docker_image_validator = DockerImageValidator(file_path, is_modified_file=True) if not docker_image_validator.is_docker_image_valid(): self._is_valid = False elif re.match(BETA_INTEGRATION_REGEX, file_path, re.IGNORECASE) or \ re.match(BETA_INTEGRATION_YML_REGEX, file_path, re.IGNORECASE): description_validator = DescriptionValidator(file_path) if not description_validator.is_valid_beta_description(): self._is_valid = False integration_validator = IntegrationValidator(file_path, old_file_path=old_file_path) if not integration_validator.is_valid_beta_integration(): self._is_valid = False if is_python_file: docker_image_validator = DockerImageValidator(file_path, is_modified_file=True) if not docker_image_validator.is_docker_image_valid(): self._is_valid = False elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE): script_validator = ScriptValidator(file_path, old_file_path=old_file_path, old_git_branch=old_branch) if is_backward_check and not script_validator.is_backward_compatible(): self._is_valid = False if not script_validator.is_valid_script(): self._is_valid = False if is_python_file: docker_image_validator = DockerImageValidator(file_path, is_modified_file=True) if not docker_image_validator.is_docker_image_valid(): self._is_valid = False elif re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_PY_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_JS_REGEX, file_path, re.IGNORECASE): yml_path, _ = get_script_package_data(os.path.dirname(file_path)) script_validator = ScriptValidator(yml_path, old_file_path=old_file_path, old_git_branch=old_branch) if is_backward_check and not script_validator.is_backward_compatible(): self._is_valid = False if is_python_file: docker_image_validator = DockerImageValidator(file_path, is_modified_file=True) if not docker_image_validator.is_docker_image_valid(): self._is_valid = False elif re.match(IMAGE_REGEX, file_path, re.IGNORECASE): image_validator = ImageValidator(file_path) if not image_validator.is_valid(): self._is_valid = False elif re.match(INCIDENT_FIELD_REGEX, file_path, re.IGNORECASE): incident_field_validator = IncidentFieldValidator(file_path, old_file_path=old_file_path, old_git_branch=old_branch) if not incident_field_validator.is_valid(): self._is_valid = False if is_backward_check and not incident_field_validator.is_backward_compatible(): self._is_valid = False
def test_is_valid_name_bad_name(): validator = IncidentFieldValidator('temp_file', check_git=False) validator.current_incident_field = { 'cliName': 'sanity name', 'name': 'Incident', 'content': True, } assert not validator.is_valid_name() assert not validator.is_valid() validator.current_incident_field = { 'cliName': 'sanity name', 'name': 'case', 'content': True, } assert not validator.is_valid_name() assert not validator.is_valid() validator.current_incident_field = { 'cliName': 'sanity name', 'name': 'Playbook', 'content': True, } assert not validator.is_valid_name() assert not validator.is_valid() validator.current_incident_field = { 'cliName': 'sanity name', 'name': 'Alerting feature', 'content': True, } assert not validator.is_valid_name() assert not validator.is_valid() validator.current_incident_field = { 'cliName': 'sanity name', 'name': 'INciDeNts', 'content': True, } assert not validator.is_valid_name() assert not validator.is_valid()