2023-10-03 23:17:49 -04:00
|
|
|
from typing import Any, Dict
|
2022-12-08 04:39:50 +05:30
|
|
|
|
|
|
|
import pytest
|
|
|
|
from freezegun import freeze_time
|
|
|
|
|
2022-12-23 04:17:57 +05:30
|
|
|
from datahub.ingestion.graph.client import DatahubClientConfig
|
|
|
|
from datahub.ingestion.run.pipeline import Pipeline
|
2022-12-08 04:39:50 +05:30
|
|
|
from datahub.ingestion.source.metadata import business_glossary
|
|
|
|
from tests.test_helpers import mce_helpers
|
|
|
|
|
|
|
|
FROZEN_TIME = "2020-04-14 07:00:00"
|
|
|
|
|
|
|
|
|
2022-12-23 04:17:57 +05:30
|
|
|
def get_default_recipe(
|
2023-04-27 08:18:52 +05:30
|
|
|
glossary_yml_file_path: str, event_output_file_path: str, enable_auto_id: bool
|
2022-12-23 04:17:57 +05:30
|
|
|
) -> Dict[str, Any]:
|
|
|
|
return {
|
|
|
|
"source": {
|
|
|
|
"type": "datahub-business-glossary",
|
2023-04-27 08:18:52 +05:30
|
|
|
"config": {
|
|
|
|
"file": glossary_yml_file_path,
|
|
|
|
"enable_auto_id": enable_auto_id,
|
|
|
|
},
|
2022-12-23 04:17:57 +05:30
|
|
|
},
|
|
|
|
"sink": {
|
|
|
|
"type": "file",
|
|
|
|
"config": {
|
|
|
|
"filename": event_output_file_path,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-27 08:18:52 +05:30
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"enable_auto_id, golden_file",
|
|
|
|
[
|
|
|
|
(False, "glossary_events_golden.json"),
|
|
|
|
(True, "glossary_events_auto_id_golden.json"),
|
|
|
|
],
|
|
|
|
)
|
2022-12-08 04:39:50 +05:30
|
|
|
@freeze_time(FROZEN_TIME)
|
|
|
|
@pytest.mark.integration
|
2023-04-27 08:18:52 +05:30
|
|
|
def test_glossary_ingest(
|
|
|
|
mock_datahub_graph, pytestconfig, tmp_path, mock_time, enable_auto_id, golden_file
|
|
|
|
):
|
2022-12-08 04:39:50 +05:30
|
|
|
test_resources_dir = pytestconfig.rootpath / "tests/integration/business-glossary"
|
|
|
|
|
2022-12-23 04:17:57 +05:30
|
|
|
output_mces_path: str = f"{tmp_path}/glossary_events.json"
|
2023-04-27 08:18:52 +05:30
|
|
|
golden_mces_path: str = f"{test_resources_dir}/{golden_file}"
|
2022-12-23 04:17:57 +05:30
|
|
|
|
|
|
|
pipeline = Pipeline.create(
|
|
|
|
get_default_recipe(
|
|
|
|
glossary_yml_file_path=f"{test_resources_dir}/business_glossary.yml",
|
|
|
|
event_output_file_path=output_mces_path,
|
2023-04-27 08:18:52 +05:30
|
|
|
enable_auto_id=enable_auto_id,
|
2022-12-23 04:17:57 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
pipeline.ctx.graph = mock_datahub_graph(
|
|
|
|
DatahubClientConfig()
|
|
|
|
) # Mock to resolve domain
|
|
|
|
pipeline.run()
|
|
|
|
pipeline.raise_from_status()
|
|
|
|
|
2022-12-08 04:39:50 +05:30
|
|
|
# Verify the output.
|
|
|
|
mce_helpers.check_golden_file(
|
|
|
|
pytestconfig,
|
2022-12-23 04:17:57 +05:30
|
|
|
output_path=output_mces_path,
|
|
|
|
golden_path=golden_mces_path,
|
2022-12-08 04:39:50 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN_TIME)
|
|
|
|
def test_auto_id_creation_on_reserved_char():
|
|
|
|
id_: str = business_glossary.create_id(["pii", "secure % password"], None, False)
|
|
|
|
assert id_ == "24baf9389cc05c162c7148c96314d733"
|