def test_updated_docker_image_on_sane_doc_reports(): validator = ScriptValidator('Scripts/SaneDocReport/SaneDocReport.yml', check_git=False) validator.old_script = {'dockerimage': '1.0.0'} validator.current_script = {'dockerimage': '1.0.1'} assert validator.is_backward_compatible( ), "The script validator didn't pass sane-doc-reports"
def test_added_docker_image_on_existing_script(): validator = ScriptValidator('temp_file', check_git=False) validator.old_script = { } validator.current_script = { 'dockerimage': 'test_updated' } assert validator.is_docker_image_changed(), "The script validator couldn't find the docker image as changed"
def test_updated_docker_image_on_sane_doc_reports_fail_name(): validator = ScriptValidator('SaneDocReport.yml', check_git=False) validator.old_script = { 'dockerimage': '1.0.0' } validator.current_script = { 'dockerimage': '1.0.1' } assert not validator.is_backward_compatible(), "The script validator passed sane-doc-reports eventough it shouldn't"
def validate_modified_files(self, modified_files, is_backward_check=True): """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. """ for file_path in modified_files: old_file_path = None if isinstance(file_path, tuple): old_file_path, file_path = file_path print("Validating {}".format(file_path)) structure_validator = StructureValidator(file_path, is_added_file=not(False or is_backward_check), is_renamed=True if old_file_path else False) 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) if is_backward_check and not integration_validator.is_backward_compatible(): self._is_valid = False elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE): script_validator = ScriptValidator(file_path) if is_backward_check and not script_validator.is_backward_compatible(): 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) if is_backward_check and not script_validator.is_backward_compatible(): 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
def test_is_changed_subtype_python2_to_3(): validator = ScriptValidator("temp_file", check_git=False) validator.current_script = { "type": "python", "subtype": "python3" } validator.old_script = { "type": "python", "subtype": "python2" } assert validator.is_changed_subtype() is True, \ "Did not find changed subtype while it was changed"
def test_is_changed_subtype_python3(): validator = ScriptValidator("temp_file", check_git=False) validator.current_script = { "type": "python", "subtype": "python3" } validator.old_script = { "type": "python", "subtype": "python3" } assert validator.is_changed_subtype() is False, \ "found changed subtype while it was not changed"
def test_is_valid_subtype_python2(): validator = ScriptValidator("temp_file", check_git=False) validator.current_script = { "type": "python", "subtype": "python2" } validator.old_script = { "type": "python", "subtype": "python2" } assert validator.is_valid_subtype() is True, \ "found invalid subtype while it is valid - python2"
def test_is_valid_subtype_blabla(): validator = ScriptValidator("temp_file", check_git=False) validator.current_script = { "type": "python", "subtype": "blabla" } validator.old_script = { "type": "python", "subtype": "blabla" } assert validator.is_valid_subtype() is False, \ "found valid subtype while it is invalid - blabla"
def test_added_new_context_path(): validator = ScriptValidator('temp_file', check_git=False) validator.old_script = {'outputs': [{'contextPath': 'test1'}]} validator.current_script = { 'outputs': [{ 'contextPath': 'test1' }, { 'contextPath': 'test2' }] } assert validator.is_context_path_changed() is False, 'The script validator found an existing context path as ' \ 'changed although it is not, but new context path added to a command'
def test_deleted_context_path(): validator = ScriptValidator('temp_file', check_git=False) validator.old_script = { 'outputs': [{ 'contextPath': 'test1' }, { 'contextPath': 'test2' }] } validator.current_script = {'outputs': [{'contextPath': 'test1'}]} assert validator.is_context_path_changed( ), "The script validator couldn't find the context path as deleted"
def test_duplicate_arg_in_script(): validator = ScriptValidator("temp_file", check_git=False) validator.yaml_data = { "args": [ { "name": "test" }, { "name": "test" } ] } assert validator.is_there_duplicates_args(), "The script validator didn't found the duplicate arg"
def test_duplicate_arg_in_script(): validator = ScriptValidator('temp_file', check_git=False) validator.current_script = { 'args': [ { 'name': 'test1' }, { 'name': 'test1' } ] } assert validator.is_there_duplicates_args(), "The script validator didn't found the duplicate arg"
def test_no_duplicate_arg_in_script(): validator = ScriptValidator('temp_file', check_git=False) validator.current_script = { 'args': [ { 'name': 'test1' }, { 'name': 'test2' } ] } assert validator.is_there_duplicates_args() is False, 'The script validator found duplicate arg although ' \ 'there no such'
def test_changed_arg_in_script(): validator = ScriptValidator('temp_file', check_git=False) validator.old_script = {'args': [{'name': 'test1'}, {'name': 'test2'}]} validator.current_script = { 'args': [{ 'name': 'test2' }, { 'name': 'test1' }, { 'name': 'test3' }] } assert validator.is_arg_changed() is False, "The script validator didn't found the arg list has breaking " \ 'backward compatibility although an arg was renamed'
def test_no_duplicate_arg_in_script(): validator = ScriptValidator("temp_file", check_git=False) validator.yaml_data = { "args": [ { "name": "test" }, { "name": "test1" } ] } assert validator.is_there_duplicates_args() is False, "The script validator found duplicate arg although " \ "there no such"
def test_configuration_extraction(): validator = ScriptValidator('temp_file', check_git=False) script_json = { 'args': [{ 'name': 'test', 'required': False }, { 'name': 'test1', 'required': True }] } expected = {'test': False, 'test1': True} assert validator._get_arg_to_required_dict( script_json) == expected, 'Failed to extract configuration'
def test_not_changed_context_path(): validator = ScriptValidator('temp_file', check_git=False) validator.old_script = { 'outputs': [ { 'contextPath': 'test' } ] } validator.current_script = { 'outputs': [ { 'contextPath': 'test' } ] } assert validator.is_context_path_changed() is False, "The script validator couldn't find the context " \ 'path as not touched'
def test_added_required_field_in_integration(): validator = ScriptValidator('temp_file', check_git=False) validator.old_script = { 'args': [ { 'name': 'test', 'required': False } ] } validator.current_script = { 'args': [ { 'name': 'test', 'required': True } ] } assert validator.is_added_required_args(), "The script validator couldn't find the new required args"
def test_not_changed_required_field_scenario2_in_integration(): validator = ScriptValidator('temp_file', check_git=False) validator.old_script = { 'args': [ { 'name': 'test', 'required': False } ] } validator.current_script = { 'args': [ { 'name': 'test', 'required': False } ] } assert validator.is_added_required_args() is False, 'The script validator found a backward compatibility ' \ 'change although no such change was done'
def test_deleted_arg_from_script(): validator = ScriptValidator('temp_file', check_git=False) validator.old_script = { 'args': [ { 'name': 'test1' }, { 'name': 'test2' } ] } validator.current_script = { 'args': [ { 'name': 'test1' } ] } assert validator.is_arg_changed(), "The script validator couldn't find deleted arg name"
def test_changed_required_field_to_not_required_in_integration(): validator = ScriptValidator('temp_file', check_git=False) validator.old_script = { 'args': [ { 'name': 'test', 'required': True } ] } validator.current_script = { 'args': [ { 'name': 'test', 'required': False } ] } assert validator.is_added_required_args() is False, 'The script validator found the change to not required ' \ 'as a one who breaks backward compatability'
def validate_modified_files(self, modified_files): """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. """ for file_path in modified_files: old_file_path = None if isinstance(file_path, tuple): old_file_path, file_path = file_path print("Validating {}".format(file_path)) structure_validator = StructureValidator( file_path, is_added_file=False, is_renamed=True if old_file_path else False) 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) if not integration_validator.is_backward_compatible(): self._is_valid = False elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE): script_validator = ScriptValidator(file_path) if not script_validator.is_backward_compatible(): 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) if not script_validator.is_backward_compatible(): 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
def test_added_arg_to_script(): validator = ScriptValidator('temp_file', check_git=False) validator.old_script = { 'args': [ { 'name': 'test1' } ] } validator.current_script = { 'args': [ { 'name': 'test1' }, { 'name': 'test2' } ] } assert validator.is_arg_changed() is False, 'The script validator found the arg list has breaking backward ' \ 'compatibility although just new option was added'
def test_updated_docker_image_on_sane_doc_reports_fail_subtype(): validator = ScriptValidator('Scripts/SaneDocReport/SaneDocReport.yml', check_git=False) validator.current_script = {"type": "python", "subtype": "python3"} validator.old_script = {"type": "python", "subtype": "python2"} assert validator.is_changed_subtype() is True, \ "Did not find changed subtype while it was changed" assert validator.is_backward_compatible( ) is False, "The script validator passed sane-doc-reports"
def test_not_changed_context_path(): validator = ScriptValidator("temp_file", check_git=False) validator.change_string = "not changed context path" assert validator.is_context_path_changed() is False, "The script validator couldn't find the context " \ "path as not touched"
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_untouched_arg_list_in_script(): validator = ScriptValidator("temp_file", check_git=False) validator.change_string = "not changed arg list" assert validator.is_arg_changed() is False, "The script validator found the arg list has breaking backward " \ "compatability although it was not touched"
def test_moved_arg_in_script(): validator = ScriptValidator("temp_file", check_git=False) validator.change_string = "+ - name: sadf\n- - name: sadf" assert validator.is_arg_changed() is False, "The script validator found the arg list has breaking backward " \ "compatability although just reordered the existing arg list"
def test_added_arg_to_script(): validator = ScriptValidator("temp_file", check_git=False) validator.change_string = "+ - name: sadf" assert validator.is_arg_changed() is False, "The script validator found the arg list has breaking backward " \ "compatability although just new option was added"
def test_deleted_arg_from_script(): validator = ScriptValidator("temp_file", check_git=False) validator.change_string = "- - name: sadf" assert validator.is_arg_changed(), "The script validator couldn't find deleted arg name"
def test_added_new_context_path(): validator = ScriptValidator("temp_file", check_git=False) validator.change_string = "+ - contextPath: sadf" assert validator.is_context_path_changed() is False, "The script validator found an existing context path as " \ "changed although it is not, but new context path added to a command"