def test_is_valid_name_prefix(self, current_file, pack_metadata, answer,
                                  mocker):
        """
            Given
            - A set of indicator fields

            When
            - Running is_valid_incident_field_name_prefix on it.

            Then
            - Ensure validate fails when the field name does not start with the pack name prefix.
        """
        from demisto_sdk.commands.common.hook_validations import \
            field_base_validator
        with patch.object(StructureValidator, '__init__', lambda a, b: None):
            structure = StructureValidator("")
            structure.current_file = current_file
            structure.old_file = None
            structure.file_path = "random_path"
            structure.is_valid = True
            structure.prev_ver = 'master'
            structure.branch_name = ''
            validator = FieldBaseValidator(structure, set(), set())
            validator.current_file = current_file
            mocker.patch.object(field_base_validator,
                                'get_pack_metadata',
                                return_value=pack_metadata)
            assert validator.is_valid_field_name_prefix() == answer
 def test_is_changed_type(self, current_type, old_type, is_valid):
     structure = StructureValidator("")
     structure.current_file = {"type": current_type}
     structure.old_file = {"type": old_type}
     validator = IncidentFieldValidator(structure)
     assert validator.is_changed_type() == is_valid, f'is_changed_type({current_type}, {old_type})' \
                                                     f' returns {not is_valid}.'
    def test_is_valid_name_sanity(self, current_file, answer):
        import os
        import sys
        with patch.object(StructureValidator, '__init__', lambda a, b: None):
            structure = StructureValidator("")
            structure.current_file = current_file
            structure.old_file = None
            structure.file_path = "random_path"
            structure.is_valid = True
            structure.prev_ver = 'master'
            structure.branch_name = ''
            validator = FieldBaseValidator(structure, set(), set())
            validator.current_file = current_file

            with open("file", 'w') as temp_out:
                old_stdout = sys.stdout
                sys.stdout = temp_out
                validator.is_valid_name()
                sys.stdout = old_stdout

            with open('file', 'r') as temp_out:
                output = temp_out.read()
                assert ('IF100' in str(output)) is answer
            # remove the temp file
            os.system('rm -rf file')
def test_is_changed_from_version(current_from_version, old_from_version,
                                 answer):
    structure = StructureValidator("")
    structure.old_file = old_from_version
    structure.current_file = current_from_version
    validator = IncidentTypeValidator(structure)
    assert validator.is_changed_from_version() is answer
Exemple #5
0
 def test_is_changed_from_version(self, current_from_version, old_from_version, answer):
     structure = StructureValidator("")
     structure.old_file = old_from_version
     structure.current_file = current_from_version
     validator = FieldBaseValidator(structure, set(), set())
     assert validator.is_changed_from_version() is answer
     structure.quiet_bc = True
     assert validator.is_changed_from_version() is False
 def test_is_changed_type(self, current_type, old_type, is_valid):
     structure = StructureValidator("")
     structure.current_file = {"type": current_type}
     structure.old_file = {"type": old_type}
     validator = FieldBaseValidator(structure, set(), set())
     assert validator.is_changed_type() == is_valid, f'is_changed_type({current_type}, {old_type})' \
                                                     f' returns {not is_valid}.'
     structure.quiet_bc = True
     assert validator.is_changed_type() is False
def mock_structure(file_path=None, current_file=None, old_file=None):
    # type: (Optional[str], Optional[dict], Optional[dict]) -> StructureValidator
    with patch.object(StructureValidator, '__init__', lambda a, b: None):
        structure = StructureValidator(file_path)
        structure.is_valid = True
        structure.scheme_name = 'integration'
        structure.file_path = file_path
        structure.current_file = current_file
        structure.old_file = old_file
        return structure
 def test_is_valid_system_flag_sanity(self, current_file, answer):
     with patch.object(StructureValidator, '__init__', lambda a, b: None):
         structure = StructureValidator("")
         structure.current_file = current_file
         structure.old_file = None
         structure.file_path = "random_path"
         structure.is_valid = True
         validator = IncidentFieldValidator(structure)
         validator.current_file = current_file
         assert validator.is_valid_system_flag() is answer
 def test_is_valid_cliname_invalid(self, cliname, group):
     current_file = {"cliName": cliname, "group": group}
     with patch.object(StructureValidator, '__init__', lambda a, b: None):
         structure = StructureValidator("")
         structure.current_file = current_file
         structure.old_file = None
         structure.file_path = "random_path"
         structure.is_valid = True
         validator = IncidentFieldValidator(structure)
         validator.current_file = current_file
         assert not validator.is_valid_cliname()
 def test_matching_cliname_regex_invalid(self, cliname):
     with patch.object(StructureValidator, '__init__', lambda a, b: None):
         current_file = {"cliName": cliname}
         structure = StructureValidator("")
         structure.current_file = current_file
         structure.old_file = None
         structure.file_path = "random_path"
         structure.is_valid = True
         validator = IncidentFieldValidator(structure)
         validator.current_file = current_file
         assert not validator.is_matching_cliname_regex()
def mock_structure(file_path=None, current_file=None, old_file=None):
    with patch.object(StructureValidator, '__init__', lambda a, b: None):
        structure = StructureValidator(file_path)
        structure.is_valid = True
        structure.scheme_name = 'classifier'
        structure.file_path = file_path
        structure.current_file = current_file
        structure.old_file = old_file
        structure.prev_ver = 'master'
        structure.branch_name = ''
        return structure
Exemple #12
0
def get_validator(current_file=None, old_file=None, file_path=""):
    with patch.object(StructureValidator, '__init__', lambda a, b: None):
        structure = StructureValidator("")
        structure.current_file = current_file
        structure.old_file = old_file
        structure.file_path = file_path
        structure.is_valid = True
        validator = ScriptValidator(structure)
        validator.old_script = old_file
        validator.current_script = current_file
    return validator
def mock_structure(file_path=None, current_file=None, old_file=None):
    # type: (Optional[str], Optional[dict], Optional[dict]) -> StructureValidator
    with patch.object(StructureValidator, '__init__', lambda a, b: None):
        structure = StructureValidator(file_path)
        structure.is_valid = True
        structure.scheme_name = 'playbook'
        structure.file_path = file_path
        structure.current_file = current_file
        structure.old_file = old_file
        structure.prev_ver = 'master'
        structure.branch_name = ''
        return structure
 def test_is_valid_content_flag_sanity(self, current_file, answer):
     with patch.object(StructureValidator, '__init__', lambda a, b: None):
         structure = StructureValidator("")
         structure.current_file = current_file
         structure.old_file = None
         structure.file_path = "random_path"
         structure.is_valid = True
         structure.prev_ver = 'master'
         structure.branch_name = ''
         validator = FieldBaseValidator(structure, set(), set())
         validator.current_file = current_file
         assert validator.is_valid_content_flag() is answer
 def test_is_cliname_is_builtin_key_invalid(self, cliname, group):
     with patch.object(StructureValidator, '__init__', lambda a, b: None):
         current_file = {"cliName": cliname, "group": group}
         structure = StructureValidator("")
         structure.current_file = current_file
         structure.old_file = None
         structure.file_path = "random_path"
         structure.is_valid = True
         structure.prev_ver = 'master'
         structure.branch_name = ''
         validator = IncidentFieldValidator(structure)
         validator.current_file = current_file
         assert not validator.is_cliname_is_builtin_key()
 def test_is_valid_cli_name_invalid(self, cliname, group):
     current_file = {"cliName": cliname, "group": group}
     with patch.object(StructureValidator, '__init__', lambda a, b: None):
         structure = StructureValidator("")
         structure.current_file = current_file
         structure.old_file = None
         structure.file_path = "random_path"
         structure.is_valid = True
         structure.prev_ver = 'master'
         structure.branch_name = ''
         validator = FieldBaseValidator(structure, set(), {'id'})
         validator.current_file = current_file
         assert not validator.is_valid_cli_name()
 def test_matching_cliname_regex_invalid(self, cliname):
     with patch.object(StructureValidator, '__init__', lambda a, b: None):
         current_file = {"cliName": cliname}
         structure = StructureValidator("")
         structure.current_file = current_file
         structure.old_file = None
         structure.file_path = "random_path"
         structure.is_valid = True
         structure.prev_ver = 'master'
         structure.branch_name = ''
         validator = FieldBaseValidator(structure, set(), set())
         validator.current_file = current_file
         assert not validator.is_matching_cli_name_regex()
Exemple #18
0
def mock_structure(file_path=None, current_file=None, old_file=None, quiet_bc=False):
    with patch.object(StructureValidator, '__init__', lambda a, b: None):
        structure = StructureValidator(file_path)
        structure.is_valid = True
        structure.scheme_name = 'widget'
        structure.file_path = file_path
        structure.current_file = current_file
        structure.old_file = old_file
        structure.prev_ver = 'master'
        structure.branch_name = ''
        structure.quiet_bc = quiet_bc
        structure.specific_validations = None
        return structure
Exemple #19
0
def get_validator(current_file=None, old_file=None, file_path="Packs/exists"):
    with patch.object(StructureValidator, '__init__', lambda a, b: None):
        structure = StructureValidator("")
        structure.current_file = current_file
        structure.old_file = old_file
        structure.file_path = file_path
        structure.is_valid = True
        structure.prev_ver = 'master'
        structure.branch_name = ''
        structure.quiet_bc = False
        structure.specific_validations = None
        validator = WizardValidator(structure)
        validator.current_file = current_file
    return validator
def get_validator(current_file=None, old_file=None, file_path=""):
    with patch.object(StructureValidator, '__init__', lambda a, b: None):
        structure = StructureValidator("")
        structure.current_file = current_file
        structure.old_file = old_file
        structure.file_path = file_path
        structure.is_valid = True
        structure.prev_ver = 'master'
        structure.branch_name = ''
        structure.quiet_bc = False
        validator = ScriptValidator(structure)
        validator.old_script = old_file
        validator.current_script = current_file
    return validator
def mock_structure(file_path=None, current_file=None, old_file=None):
    with patch.object(StructureValidator, '__init__', lambda a, b: None):
        structure = StructureValidator(file_path)
        structure.is_valid = True
        structure.scheme_name = 'list'
        structure.file_path = file_path
        file = open(file_path, "r")
        structure.current_file = json.loads(file.read())
        file.close()
        structure.old_file = old_file
        structure.prev_ver = 'master'
        structure.branch_name = ''
        structure.quiet_bc = False
        return structure
Exemple #22
0
 def test_is_cliname_is_builtin_key(self, cliname, group):
     with patch.object(StructureValidator, '__init__', lambda a, b: None):
         current_file = {"cliName": cliname, "group": group}
         structure = StructureValidator("")
         structure.current_file = current_file
         structure.old_file = None
         structure.file_path = "random_path"
         structure.is_valid = True
         structure.prev_ver = 'master'
         structure.branch_name = ''
         structure.specific_validations = None
         validator = FieldBaseValidator(structure, set(), set())
         validator.current_file = current_file
         assert validator.is_cli_name_is_builtin_key()
Exemple #23
0
 def test_is_valid_cliname(self, _id, cliname, group):
     current_file = {'id': _id, 'cliName': cliname, 'group': group}
     with patch.object(StructureValidator, '__init__', lambda a, b: None):
         structure = StructureValidator("")
         structure.current_file = current_file
         structure.old_file = None
         structure.file_path = "random_path"
         structure.is_valid = True
         structure.prev_ver = 'master'
         structure.branch_name = ''
         structure.specific_validations = None
         validator = FieldBaseValidator(structure, set(), set())
         validator.current_file = current_file
         assert validator.is_valid_cli_name()
def mock_structure(file_path=None, current_file=None, old_file=None):
    with patch.object(StructureValidator, '__init__', lambda a, b: None):
        structure = StructureValidator(file_path)
        structure.is_valid = True
        structure.scheme_name = 'genericfield'
        structure.file_path = file_path
        structure.current_file = current_file
        structure.old_file = old_file
        structure.prev_ver = 'master'
        structure.branch_name = ''
        structure.quiet_bc = False
        structure.skip_schema_check = False
        structure.pykwalify_logs = False
        structure.scheme_name = namedtuple('scheme_name',
                                           'value')(value='genericfield')
        structure.checked_files = set()
        structure.ignored_errors = dict()
        structure.suppress_print = True
        structure.json_file_path = None
        return structure
Exemple #25
0
 def test_is_id_not_modified(self, current_file, old_file, answer, error):
     validator = StructureValidator(file_path=current_file)
     with open(old_file) as f:
         validator.old_file = yaml.load(f)
         assert validator.is_id_not_modified() is answer, error
Exemple #26
0
 def test_fromversion_update_validation_yml_structure(
         self, path, old_file_path, answer):
     validator = StructureValidator(file_path=path)
     with open(old_file_path) as f:
         validator.old_file = yaml.load(f)
         assert validator.is_valid_fromversion_on_modified() is answer