def test_json_output_with_json_file(self, repo): """ Given - A ui applicable error. - An existing and an empty json_outputs file. When - Running json_output method. Then - Ensure the json outputs file is created and it hold the json error in the `outputs` field. - Ensure it's not failing because the file is empty. """ pack = repo.create_pack('PackName') integration = pack.create_integration('MyInt') integration.create_default_integration() json_path = os.path.join(repo.path, 'valid_json.json') open(json_path, "x") base = BaseValidator(json_file_path=json_path) ui_applicable_error_message, ui_applicable_error_code = Errors.wrong_display_name( 'param1', 'param2') expected_json_1 = [{ 'filePath': integration.yml.path, 'fileType': 'yml', 'entityType': 'integration', 'errorType': 'Settings', 'name': 'Sample', 'severity': 'error', 'errorCode': ui_applicable_error_code, 'message': ui_applicable_error_message, 'ui': True, 'relatedField': '<parameter-name>.display', 'linter': 'validate' }] with ChangeCWD(repo.path): # create new file base.json_output(integration.yml.path, ui_applicable_error_code, ui_applicable_error_message, False) with open(base.json_file_path, 'r') as f: json_output = json.load(f) assert json_output.sort() == expected_json_1.sort()
def test_json_output_with_unified_yml_image_error(self, repo): """ Given - A ui applicable image error that occurred in a unified yml. - An existing and an empty json_outputs file. When - Running json_output method. Then - Ensure the json outputs file is created and it hold the json error in the `outputs` field. - Ensure the entityType is 'image'. """ pack = repo.create_pack('PackName') integration = pack.create_integration('MyInt') integration.create_default_integration() json_path = os.path.join(repo.path, 'valid_json.json') open(json_path, "x") base = BaseValidator(json_file_path=json_path) ui_applicable_error_message, ui_applicable_error_code = Errors.image_too_large( ) expected_json_1 = [{ 'filePath': integration.yml.path, 'fileType': 'yml', 'entityType': 'image', 'errorType': 'Settings', 'name': 'Sample', 'severity': 'error', 'errorCode': ui_applicable_error_code, 'message': ui_applicable_error_message, 'ui': True, 'relatedField': 'image', 'validate': 'linter' }] with ChangeCWD(repo.path): # create new file base.json_output(integration.yml.path, ui_applicable_error_code, ui_applicable_error_message, False) with open(base.json_file_path, 'r') as f: json_output = json.load(f) assert json_output.sort() == expected_json_1.sort()
def test_json_output(repo): """ Given - Scenario 1: - A ui applicable error. - No pre existing json_outputs file. - Scenario 2: - A non ui applicable warning. - A pre existing json_outputs file. When - Running json_output method. Then - Scenario 1: - Ensure the json outputs file is created and it hold the json error in the `outputs` field. - Scenario 2: - Ensure the json outputs file is modified and holds the json warning in the `outputs` field. """ pack = repo.create_pack('PackName') integration = pack.create_integration('MyInt') integration.create_default_integration() json_path = os.path.join(repo.path, 'valid_json.json') base = BaseValidator(json_file_path=json_path) ui_applicable_error_message, ui_applicable_error_code = Errors.wrong_display_name( 'param1', 'param2') non_ui_applicable_error_message, non_ui_applicable_error_code = Errors.wrong_subtype( ) expected_json_1 = { integration.yml.path: { "file-type": "yml", "entity-type": "integration", "display-name": "Sample", "outputs": [{ "severity": "error", "code": ui_applicable_error_code, "message": ui_applicable_error_message, "ui": True, 'related-field': '<parameter-name>.display' }] } } expected_json_2 = { integration.yml.path: { "file-type": "yml", "entity-type": "integration", "display-name": "Sample", "outputs": [{ "severity": "error", "code": ui_applicable_error_code, "message": ui_applicable_error_message, "ui": True, 'related-field': '<parameter-name>.display' }, { "severity": "warning", "code": non_ui_applicable_error_code, "message": non_ui_applicable_error_message, "ui": False, 'related-field': 'subtype' }] } } with ChangeCWD(repo.path): # create new file base.json_output(integration.yml.path, ui_applicable_error_code, ui_applicable_error_message, False) with open(base.json_file_path, 'r') as f: json_output = json.load(f) assert json_output == expected_json_1 # update existing file base.json_output(integration.yml.path, non_ui_applicable_error_code, non_ui_applicable_error_message, True) with open(base.json_file_path, 'r') as f: json_output = json.load(f) assert json_output == expected_json_2
def test_json_output(self, repo): """ Given - Scenario 1: - A ui applicable error. - No pre existing json_outputs file. - Scenario 2: - A non ui applicable warning. - A pre existing json_outputs file. When - Running json_output method. Then - Scenario 1: - Ensure the json outputs file is created and it hold the json error in the `outputs` field. - Scenario 2: - Ensure the json outputs file is modified and holds the json warning in the `outputs` field. """ pack = repo.create_pack('PackName') integration = pack.create_integration('MyInt') integration.create_default_integration() json_path = os.path.join(repo.path, 'valid_json.json') base = BaseValidator(json_file_path=json_path) ui_applicable_error_message, ui_applicable_error_code = Errors.wrong_display_name( 'param1', 'param2') non_ui_applicable_error_message, non_ui_applicable_error_code = Errors.wrong_subtype( ) expected_json_1 = [{ 'filePath': integration.yml.path, 'fileType': 'yml', 'entityType': 'integration', 'errorType': 'Settings', 'name': 'Sample', 'severity': 'error', 'errorCode': ui_applicable_error_code, 'message': ui_applicable_error_message, 'ui': True, 'relatedField': '<parameter-name>.display' }] expected_json_2 = [{ 'filePath': integration.yml.path, 'fileType': 'yml', 'entityType': 'integration', 'errorType': 'Settings', 'name': 'Sample', 'severity': 'error', 'errorCode': ui_applicable_error_code, 'message': ui_applicable_error_message, 'ui': True, 'relatedField': '<parameter-name>.display', 'linter': 'validate' }, { 'filePath': integration.yml.path, 'fileType': 'yml', 'entityType': 'integration', 'errorType': 'Settings', 'name': 'Sample', 'severity': 'warning', 'errorCode': non_ui_applicable_error_code, 'message': non_ui_applicable_error_message, 'ui': False, 'relatedField': 'subtype', 'linter': 'validate' }] with ChangeCWD(repo.path): # create new file base.json_output(integration.yml.path, ui_applicable_error_code, ui_applicable_error_message, False) with open(base.json_file_path) as f: json_output = json.load(f) assert json_output.sort() == expected_json_1.sort() # update existing file base.json_output(integration.yml.path, non_ui_applicable_error_code, non_ui_applicable_error_message, True) with open(base.json_file_path) as f: json_output = json.load(f) assert json_output == expected_json_2