def test_compare_with_customized_rules(mocker, get_job_items): mocked_save_result = mocker.patch("arche.Arche.save_result", autospec=True) mocked_coverage = mocker.patch( "arche.rules.category_coverage.compare_coverage_per_category", autospec=True ) mocked_price_url = mocker.patch( "arche.rules.price.compare_prices_for_same_urls", autospec=True ) mocked_name_url = mocker.patch( "arche.rules.price.compare_names_for_same_urls", autospec=True ) mocked_price_name = mocker.patch( "arche.rules.price.compare_prices_for_same_names", autospec=True ) source_items = get_job_items_mock(mocker) target_items = get_job_items_mock(mocker) arche = Arche("source") arche.compare_with_customized_rules(source_items, target_items, {}) mocked_coverage.assert_called_once_with( source_items.key, target_items.key, source_items.df, target_items.df, {} ) mocked_price_url.assert_called_once_with(source_items.df, target_items.df, {}) mocked_name_url.assert_called_once_with(source_items.df, target_items.df, {}) mocked_price_name.assert_called_once_with(source_items.df, target_items.df, {}) assert mocked_save_result.call_count == 4
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_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)