def test_metadata_validator_valid(self, mocker, metadata): mocker.patch.object(PackUniqueFilesValidator, '_read_file_content', return_value=TestPackMetadataValidator.read_file(metadata)) mocker.patch.object(PackUniqueFilesValidator, '_is_pack_file_exists', return_value=True) validator = PackUniqueFilesValidator('fake') assert validator.validate_pack_meta_file()
def test_metadata_validator_valid(self, mocker, metadata): mocker.patch.object(tools, 'get_dict_from_file', return_value=({'approved_list': []}, 'json')) mocker.patch.object(PackUniqueFilesValidator, '_read_file_content', return_value=TestPackMetadataValidator.read_file(metadata)) mocker.patch.object(PackUniqueFilesValidator, '_is_pack_file_exists', return_value=True) validator = PackUniqueFilesValidator('fake') assert validator.validate_pack_meta_file()
def test_metadata_validator_invalid__non_breaking(self, mocker, metadata): mocker.patch.object(tools, 'get_dict_from_file', return_value=({'approved_list': []}, 'json')) mocker.patch.object(PackUniqueFilesValidator, '_read_file_content', return_value=TestPackMetadataValidator.read_file(metadata)) mocker.patch.object(PackUniqueFilesValidator, '_is_pack_file_exists', return_value=True) mocker.patch.object(BaseValidator, 'check_file_flags', return_value='') mocker.patch.object(PackUniqueFilesValidator, '_is_integration_pack', return_value=True) validator = PackUniqueFilesValidator('fake') assert not validator.validate_pack_meta_file()
def test_metadata_validator_empty_categories(self, mocker): metadata = os.path.join(self.__class__.FILES_PATH, 'pack_metadata_empty_categories.json') mocker.patch.object(tools, 'get_dict_from_file', return_value=({'approved_list': []}, 'json')) mocker.patch.object(PackUniqueFilesValidator, '_read_file_content', return_value=TestPackMetadataValidator.read_file(metadata)) mocker.patch.object(PackUniqueFilesValidator, '_is_pack_file_exists', return_value=True) mocker.patch.object(BaseValidator, 'check_file_flags', return_value='') mocker.patch.object(PackUniqueFilesValidator, '_is_integration_pack', return_value=True) validator = PackUniqueFilesValidator('fake') assert not validator.validate_pack_meta_file() assert "[PA129] - pack_metadata.json - Missing categories" in validator.get_errors()
def test_metadata_validator_valid(self, mocker): mocker.patch.object(PackUniqueFilesValidator, '_read_file_content', return_value=TestPackMetadataValidator.read_file( os.path.join( TestPackMetadataValidator.FILES_PATH, 'valid_pack_metadata.json'))) mocker.patch.object(PackUniqueFilesValidator, '_is_pack_file_exists', return_value=True) validator = PackUniqueFilesValidator('fake') assert validator.validate_pack_meta_file()
def test_metadata_validator_invalid__breaking(self, mocker, metadata): """ Given A pack metadata file with invalid contents that should halt validations When Calling validate_pack_meta_file Then Ensure BlockingValidationFailureException is raised """ mocker.patch.object(tools, 'get_dict_from_file', return_value=({'approved_list': []}, 'json')) mocker.patch.object(PackUniqueFilesValidator, '_read_file_content', return_value=TestPackMetadataValidator.read_file(metadata)) mocker.patch.object(PackUniqueFilesValidator, '_is_pack_file_exists', return_value=True) mocker.patch.object(BaseValidator, 'check_file_flags', return_value='') validator = PackUniqueFilesValidator('fake') with pytest.raises(BlockingValidationFailureException): assert not validator.validate_pack_meta_file()
def test_metadata_validator_invalid_version_add_error(self, mocker): """ Given: - pack metadata.json file with wrong version type When: - validating meta data structure Then: - Ensure false is returned and the correct error is added to the validation object error list """ metadata = os.path.join(self.FILES_PATH, 'pack_metadata_invalid_format_version.json') mocker.patch.object(tools, 'get_dict_from_file', return_value=({'approved_list': []}, 'json')) mocker.patch.object(PackUniqueFilesValidator, '_read_file_content', return_value=TestPackMetadataValidator.read_file(metadata)) mocker.patch.object(PackUniqueFilesValidator, '_is_pack_file_exists', return_value=True) mocker.patch.object(BaseValidator, 'check_file_flags', return_value='') validator = PackUniqueFilesValidator('fake') assert not validator.validate_pack_meta_file() assert "[PA130] - Pack metadata version format is not valid. Please fill in a valid format (example: 0.0.0)" in validator.get_errors()