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_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 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 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): 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
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): # 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 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
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()
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 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
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()
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