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_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_run_all_rules_job(mocker, source_key, target_key): mocked_check_metadata = mocker.patch("arche.Arche.check_metadata", autospec=True) mocked_compare_metadata = mocker.patch( "arche.Arche.compare_metadata", autospec=True ) mocked_run_general_rules = mocker.patch( "arche.Arche.run_general_rules", autospec=True ) mocked_run_comparison_rules = mocker.patch( "arche.Arche.run_comparison_rules", autospec=True ) mocked_run_schema_rules = mocker.patch( "arche.Arche.run_schema_rules", autospec=True ) arche = Arche(source=source_key, target=target_key) arche._source_items = get_job_items_mock(mocker, key=source_key) arche._target_items = get_job_items_mock(mocker, key=target_key) arche.run_all_rules() mocked_check_metadata.assert_called_once_with(arche.source_items.job) mocked_compare_metadata.assert_called_once_with( arche.source_items.job, arche.target_items.job ) mocked_run_general_rules.assert_called_once_with() mocked_run_comparison_rules.assert_called_once_with() mocked_run_schema_rules.assert_called_once_with(arche)
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_data_quality_report(mocker, get_job_items, get_schema): mocked_dqr = mocker.patch.object(arche, "DataQualityReport", autospec=True, return_value=None) g = Arche("source", schema=get_schema) g._source_items = get_job_items g.report.results = "some_res" g.data_quality_report("s3") mocked_dqr.assert_called_with(g.source_items, g.schema, g.report, "s3")
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
def test_data_quality_report(mocker): mocked_validate = mocker.patch( "arche.rules.json_schema.validate", autospec=True, return_value=None ) mocked_dqr = mocker.patch.object( arche, "DataQualityReport", autospec=True, return_value=None ) g = Arche("source", schema={"$schema": "http://json-schema.org/draft-07/schema"}) g._source_items = get_job_items_mock(mocker) g.report.results = "some_res" g.data_quality_report("s3") mocked_validate.assert_not_called() mocked_dqr.assert_called_with(g.source_items, g.schema, g.report, "s3")
def test_validate_with_json_schema(mocker): mocked_save_result = mocker.patch("arche.Arche.save_result", autospec=True) res = Result("fine") mocked_validate = mocker.patch( "arche.rules.json_schema.validate", autospec=True, return_value=res ) mocked_show = mocker.patch("arche.rules.result.Result.show", autospec=True) arche = Arche( "source", schema={"$schema": "http://json-schema.org/draft-07/schema"} ) arche._source_items = get_job_items_mock(mocker) arche.validate_with_json_schema() mocked_validate.assert_called_once_with( arche.schema, arche.source_items.dicts, False ) mocked_save_result.assert_called_once_with(arche, res) mocked_show.assert_called_once_with(res)
def test_run_all_rules_collection(mocker, get_collection_items): mocked_check_metadata = mocker.patch("arche.Arche.check_metadata", autospec=True) mocked_compare_metadata = mocker.patch("arche.Arche.compare_metadata", autospec=True) mocked_run_general_rules = mocker.patch("arche.Arche.run_general_rules", autospec=True) mocked_run_comparison_rules = mocker.patch( "arche.Arche.run_comparison_rules", autospec=True) mocked_run_schema_rules = mocker.patch("arche.Arche.run_schema_rules", autospec=True) arche = Arche(source="collection_key") arche._source_items = get_collection_items arche.run_all_rules() mocked_check_metadata.assert_not_called() mocked_compare_metadata.assert_not_called() mocked_run_general_rules.assert_called_once_with(arche) mocked_run_comparison_rules.assert_called_once_with() mocked_run_schema_rules.assert_called_once_with(arche)