def test_validate_with_json_schema_fails(mocker, get_job_items, get_schema): mocked_display = mocker.patch("arche.report.display_html", autospec=True) url = f"{SH_URL}/112358/13/21/item/1" res = create_result( "JSON Schema Validation", { Level.ERROR: [( "1 (25%) items have 1 errors", None, { "'price' is a required property": {url} }, )] }, ) res.outcome = Outcome.FAILED schema = { "type": "object", "required": ["price"], "properties": { "price": {} } } a = Arche("source", schema=schema) a._source_items = get_job_items a.validate_with_json_schema() assert len(a.report.results) == 1 assert a.report.results.get("JSON Schema Validation") == res report_html = get_report_from_iframe(mocked_display.mock_calls[0][1][0]) assert "JSON Schema Validation - FAILED" in report_html
def test_validate_with_json_schema_fails(mocker, get_job_items, get_schema): mocked_md = mocker.patch("arche.report.display_markdown", autospec=True) url = f"{SH_URL}/112358/13/21/item/1" res = create_result( "JSON Schema Validation", { Level.ERROR: [( "4 items were checked, 1 error(s)", None, { "'price' is a required property": {url} }, )] }, ) schema = { "type": "object", "required": ["price"], "properties": { "price": {} } } a = Arche("source", schema=schema) a._source_items = get_job_items a.validate_with_json_schema() assert len(a.report.results) == 1 assert a.report.results.get("JSON Schema Validation") == res mocked_md.assert_any_call( f"1 items affected - 'price' is a required property: [1]({url})", raw=True)
def test_validate_with_json_schema_fails(mocker, get_job_items, get_schema): mocked_html = mocker.patch("arche.report.HTML", autospec=True) key = f"112358/13/21" url_base = f"{SH_URL}/{key}/item" res = create_result( "JSON Schema Validation", { Level.ERROR: [( "4 items were checked, 1 error(s)", None, { "'price' is a required property": {f"{key}/1"} }, )] }, ) schema = {"type": "object", "required": ["price"]} a = Arche("source", schema=schema) a._source_items = get_job_items a.validate_with_json_schema() assert len(a.report.results) == 1 assert a.report.results.get("JSON Schema Validation") == res mocked_html.assert_any_call( f"1 items affected - 'price' is a required property: <a href='{url_base}/1'>1</a>" )
def test_validate_with_json_schema(mocker, get_job_items, get_schema): res = create_result("JSON Schema Validation", {}) mocked_call = mocker.patch("arche.report.Report.__call__", autospec=True) a = Arche("source", schema=get_schema) a._source_items = get_job_items a.validate_with_json_schema() mocked_call.assert_called_once_with(a.report, res) assert len(a.report.results) == 1 assert a.report.results.get("JSON Schema Validation") == res
def test_validate_with_json_schema(mocker, get_job_items, get_schema): res = create_result("JSON Schema Validation", {Level.INFO: [("4 items were checked, 0 error(s)", )]}) mocked_show = mocker.patch("arche.rules.result.Result.show", autospec=True) a = Arche("source", schema=get_schema) a._source_items = get_job_items a.validate_with_json_schema() mocked_show.assert_called_once_with(res) assert len(a.report.results) == 1 assert a.report.results.get("JSON Schema Validation") == res