2022-09-10 18:35:58 -07:00
|
|
|
import dataclasses
|
|
|
|
from dataclasses import dataclass
|
2021-07-21 12:56:31 -07:00
|
|
|
from os import PathLike
|
2024-03-26 17:18:54 -07:00
|
|
|
from typing import Any, Dict, List, Union
|
2021-07-21 12:56:31 -07:00
|
|
|
|
2021-10-05 16:31:58 +02:00
|
|
|
import pytest
|
2022-03-31 06:39:02 +05:30
|
|
|
from freezegun import freeze_time
|
2021-10-05 16:31:58 +02:00
|
|
|
|
2022-06-18 13:30:04 -07:00
|
|
|
from datahub.configuration.common import DynamicTypedConfig
|
2022-08-19 09:08:17 -07:00
|
|
|
from datahub.ingestion.run.pipeline import Pipeline
|
|
|
|
from datahub.ingestion.run.pipeline_config import PipelineConfig, SourceConfig
|
2022-12-19 13:40:48 -05:00
|
|
|
from datahub.ingestion.source.dbt.dbt_common import DBTEntitiesEnabled, EmitDirective
|
2023-12-14 23:01:51 +05:30
|
|
|
from datahub.ingestion.source.dbt.dbt_core import DBTCoreConfig, DBTCoreSource
|
2025-05-19 08:39:53 +02:00
|
|
|
from datahub.testing import mce_helpers
|
|
|
|
from tests.test_helpers import test_connection_helpers
|
2022-03-31 06:39:02 +05:30
|
|
|
|
|
|
|
FROZEN_TIME = "2022-02-03 07:00:00"
|
|
|
|
GMS_PORT = 8080
|
|
|
|
GMS_SERVER = f"http://localhost:{GMS_PORT}"
|
2021-03-22 23:11:29 -07:00
|
|
|
|
2024-03-12 12:54:03 -07:00
|
|
|
_default_dbt_source_args = {
|
|
|
|
# Needed to avoid needing to access datahub server.
|
|
|
|
"write_semantics": "OVERRIDE",
|
|
|
|
}
|
|
|
|
|
2021-03-22 23:11:29 -07:00
|
|
|
|
2023-12-14 23:01:51 +05:30
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def test_resources_dir(pytestconfig):
|
2024-03-12 12:54:03 -07:00
|
|
|
# TODO: Move this into a constant based on __file__.
|
2023-12-14 23:01:51 +05:30
|
|
|
return pytestconfig.rootpath / "tests/integration/dbt"
|
|
|
|
|
|
|
|
|
2022-09-10 18:35:58 -07:00
|
|
|
@dataclass
|
2021-07-21 12:56:31 -07:00
|
|
|
class DbtTestConfig:
|
2022-09-10 18:35:58 -07:00
|
|
|
run_id: str
|
|
|
|
output_file: Union[str, PathLike]
|
|
|
|
golden_file: Union[str, PathLike]
|
|
|
|
manifest_file: str = "dbt_manifest.json"
|
2022-09-19 15:26:12 -07:00
|
|
|
catalog_file: str = "dbt_catalog.json"
|
|
|
|
sources_file: str = "dbt_sources.json"
|
2024-03-26 17:18:54 -07:00
|
|
|
run_results_files: List[str] = dataclasses.field(default_factory=list)
|
2022-09-10 18:35:58 -07:00
|
|
|
source_config_modifiers: Dict[str, Any] = dataclasses.field(default_factory=dict)
|
|
|
|
sink_config_modifiers: Dict[str, Any] = dataclasses.field(default_factory=dict)
|
|
|
|
|
|
|
|
def set_paths(
|
2021-07-21 12:56:31 -07:00
|
|
|
self,
|
2022-09-10 18:35:58 -07:00
|
|
|
dbt_metadata_uri_prefix: PathLike,
|
|
|
|
test_resources_dir: PathLike,
|
|
|
|
tmp_path: PathLike,
|
|
|
|
) -> None:
|
2024-03-26 17:18:54 -07:00
|
|
|
manifest_path = f"{dbt_metadata_uri_prefix}/{self.manifest_file}"
|
|
|
|
catalog_path = f"{dbt_metadata_uri_prefix}/{self.catalog_file}"
|
|
|
|
sources_path = f"{dbt_metadata_uri_prefix}/{self.sources_file}"
|
|
|
|
run_results_paths = [
|
|
|
|
f"{dbt_metadata_uri_prefix}/{file}" for file in self.run_results_files
|
|
|
|
]
|
|
|
|
target_platform = "postgres"
|
2021-07-21 12:56:31 -07:00
|
|
|
|
2022-09-10 18:35:58 -07:00
|
|
|
self.output_path = f"{tmp_path}/{self.output_file}"
|
2021-07-21 12:56:31 -07:00
|
|
|
|
2022-09-10 18:35:58 -07:00
|
|
|
self.golden_path = f"{test_resources_dir}/{self.golden_file}"
|
2021-07-21 12:56:31 -07:00
|
|
|
self.source_config = dict(
|
|
|
|
{
|
2024-03-26 17:18:54 -07:00
|
|
|
"manifest_path": manifest_path,
|
|
|
|
"catalog_path": catalog_path,
|
|
|
|
"sources_path": sources_path,
|
|
|
|
"run_results_paths": run_results_paths,
|
|
|
|
"target_platform": target_platform,
|
2022-01-05 16:32:05 -08:00
|
|
|
"enable_meta_mapping": False,
|
2024-03-12 12:54:03 -07:00
|
|
|
**_default_dbt_source_args,
|
2022-01-05 16:32:05 -08:00
|
|
|
"meta_mapping": {
|
2022-06-24 04:43:12 -07:00
|
|
|
"owner": {
|
|
|
|
"match": "^@(.*)",
|
|
|
|
"operation": "add_owner",
|
|
|
|
"config": {"owner_type": "user"},
|
|
|
|
},
|
2022-01-05 16:32:05 -08:00
|
|
|
"business_owner": {
|
|
|
|
"match": ".*",
|
|
|
|
"operation": "add_owner",
|
|
|
|
"config": {"owner_type": "user"},
|
|
|
|
},
|
|
|
|
"has_pii": {
|
|
|
|
"match": True,
|
|
|
|
"operation": "add_tag",
|
|
|
|
"config": {"tag": "has_pii_test"},
|
|
|
|
},
|
|
|
|
"int_property": {
|
|
|
|
"match": 1,
|
|
|
|
"operation": "add_tag",
|
|
|
|
"config": {"tag": "int_meta_property"},
|
|
|
|
},
|
|
|
|
"double_property": {
|
|
|
|
"match": 2.5,
|
|
|
|
"operation": "add_term",
|
|
|
|
"config": {"term": "double_meta_property"},
|
|
|
|
},
|
|
|
|
"data_governance.team_owner": {
|
|
|
|
"match": "Finance",
|
|
|
|
"operation": "add_term",
|
|
|
|
"config": {"term": "Finance_test"},
|
|
|
|
},
|
|
|
|
},
|
2022-04-25 19:56:45 +02:00
|
|
|
"query_tag_mapping": {
|
|
|
|
"tag": {
|
|
|
|
"match": ".*",
|
|
|
|
"operation": "add_tag",
|
|
|
|
"config": {"tag": "{{ $match }}"},
|
|
|
|
}
|
|
|
|
},
|
2021-07-21 12:56:31 -07:00
|
|
|
},
|
2022-09-10 18:35:58 -07:00
|
|
|
**self.source_config_modifiers,
|
2021-07-21 12:56:31 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
self.sink_config = dict(
|
|
|
|
{
|
|
|
|
"filename": self.output_path,
|
|
|
|
},
|
2022-09-10 18:35:58 -07:00
|
|
|
**self.sink_config_modifiers,
|
2021-07-21 12:56:31 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-09-10 18:35:58 -07:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
# test manifest, catalog, sources are generated from https://github.com/kevinhu/sample-dbt
|
|
|
|
"dbt_test_config",
|
|
|
|
[
|
2021-11-05 09:27:41 -07:00
|
|
|
DbtTestConfig(
|
|
|
|
"dbt-test-with-schemas-dbt-enabled",
|
|
|
|
"dbt_enabled_with_schemas_mces.json",
|
|
|
|
"dbt_enabled_with_schemas_mces_golden.json",
|
2022-04-13 18:58:36 -05:00
|
|
|
source_config_modifiers={
|
|
|
|
"enable_meta_mapping": True,
|
|
|
|
"owner_extraction_pattern": r"^@(?P<owner>(.*))",
|
|
|
|
},
|
2021-11-05 09:27:41 -07:00
|
|
|
),
|
2022-04-13 18:58:36 -05:00
|
|
|
DbtTestConfig(
|
|
|
|
"dbt-test-with-complex-owner-patterns",
|
|
|
|
"dbt_test_with_complex_owner_patterns_mces.json",
|
|
|
|
"dbt_test_with_complex_owner_patterns_mces_golden.json",
|
|
|
|
manifest_file="dbt_manifest_complex_owner_patterns.json",
|
|
|
|
source_config_modifiers={
|
|
|
|
"node_name_pattern": {
|
|
|
|
"deny": ["source.sample_dbt.pagila.payment_p2020_06"]
|
|
|
|
},
|
|
|
|
"owner_extraction_pattern": "(.*)(?P<owner>(?<=\\().*?(?=\\)))",
|
|
|
|
"strip_user_ids_from_email": True,
|
2021-10-26 07:31:19 +02:00
|
|
|
},
|
|
|
|
),
|
2022-05-17 16:53:16 -07:00
|
|
|
DbtTestConfig(
|
|
|
|
"dbt-test-with-data-platform-instance",
|
|
|
|
"dbt_test_with_data_platform_instance_mces.json",
|
|
|
|
"dbt_test_with_data_platform_instance_mces_golden.json",
|
|
|
|
source_config_modifiers={
|
|
|
|
"platform_instance": "dbt-instance-1",
|
|
|
|
},
|
|
|
|
),
|
2022-11-14 23:46:38 +05:30
|
|
|
DbtTestConfig(
|
|
|
|
"dbt-test-with-non-incremental-lineage",
|
|
|
|
"dbt_test_with_non_incremental_lineage_mces.json",
|
|
|
|
"dbt_test_with_non_incremental_lineage_mces_golden.json",
|
|
|
|
source_config_modifiers={
|
|
|
|
"incremental_lineage": "False",
|
|
|
|
},
|
|
|
|
),
|
2022-06-12 18:29:44 +02:00
|
|
|
DbtTestConfig(
|
|
|
|
"dbt-test-with-target-platform-instance",
|
|
|
|
"dbt_test_with_target_platform_instance_mces.json",
|
|
|
|
"dbt_test_with_target_platform_instance_mces_golden.json",
|
|
|
|
source_config_modifiers={
|
|
|
|
"target_platform_instance": "ps-instance-1",
|
|
|
|
},
|
2022-09-19 15:26:12 -07:00
|
|
|
),
|
|
|
|
DbtTestConfig(
|
2023-01-18 08:35:03 -08:00
|
|
|
"dbt-column-meta-mapping", # this also tests snapshot support
|
2022-09-19 15:26:12 -07:00
|
|
|
"dbt_test_column_meta_mapping.json",
|
|
|
|
"dbt_test_column_meta_mapping_golden.json",
|
2024-03-26 17:18:54 -07:00
|
|
|
catalog_file="sample_dbt_catalog_1.json",
|
|
|
|
manifest_file="sample_dbt_manifest_1.json",
|
|
|
|
sources_file="sample_dbt_sources_1.json",
|
2022-09-19 15:26:12 -07:00
|
|
|
source_config_modifiers={
|
|
|
|
"enable_meta_mapping": True,
|
|
|
|
"column_meta_mapping": {
|
|
|
|
"terms": {
|
|
|
|
"match": ".*",
|
|
|
|
"operation": "add_terms",
|
|
|
|
"config": {"separator": ","},
|
|
|
|
},
|
|
|
|
"is_sensitive": {
|
|
|
|
"match": True,
|
|
|
|
"operation": "add_tag",
|
|
|
|
"config": {"tag": "sensitive"},
|
|
|
|
},
|
2023-03-28 21:51:31 +05:30
|
|
|
"maturity": {
|
|
|
|
"match": ".*",
|
|
|
|
"operation": "add_term",
|
|
|
|
"config": {"term": "maturity_{{ $match }}"},
|
|
|
|
},
|
2022-09-19 15:26:12 -07:00
|
|
|
},
|
2023-01-18 08:35:03 -08:00
|
|
|
"entities_enabled": {
|
|
|
|
"test_definitions": "NO",
|
|
|
|
"test_results": "NO",
|
|
|
|
},
|
2024-03-26 17:18:54 -07:00
|
|
|
},
|
|
|
|
),
|
|
|
|
DbtTestConfig(
|
|
|
|
"dbt-model-performance",
|
|
|
|
"dbt_test_model_performance.json",
|
|
|
|
"dbt_test_test_model_performance_golden.json",
|
|
|
|
catalog_file="sample_dbt_catalog_2.json",
|
|
|
|
manifest_file="sample_dbt_manifest_2.json",
|
|
|
|
sources_file="sample_dbt_sources_2.json",
|
|
|
|
run_results_files=["sample_dbt_run_results_2.json"],
|
2024-04-02 07:29:27 -07:00
|
|
|
source_config_modifiers={},
|
2022-06-12 18:29:44 +02:00
|
|
|
),
|
2024-07-31 09:23:02 -07:00
|
|
|
DbtTestConfig(
|
|
|
|
"dbt-prefer-sql-parser-lineage",
|
|
|
|
"dbt_test_prefer_sql_parser_lineage.json",
|
|
|
|
"dbt_test_prefer_sql_parser_lineage_golden.json",
|
|
|
|
catalog_file="sample_dbt_catalog_2.json",
|
|
|
|
manifest_file="sample_dbt_manifest_2.json",
|
|
|
|
sources_file="sample_dbt_sources_2.json",
|
|
|
|
run_results_files=["sample_dbt_run_results_2.json"],
|
|
|
|
source_config_modifiers={
|
|
|
|
"prefer_sql_parser_lineage": True,
|
|
|
|
"skip_sources_in_lineage": True,
|
2024-08-13 13:54:50 -07:00
|
|
|
# "entities_enabled": {"sources": "NO"},
|
2024-07-31 09:23:02 -07:00
|
|
|
},
|
|
|
|
),
|
2022-09-10 18:35:58 -07:00
|
|
|
],
|
|
|
|
ids=lambda dbt_test_config: dbt_test_config.run_id,
|
|
|
|
)
|
|
|
|
@pytest.mark.integration
|
2022-11-14 23:46:38 +05:30
|
|
|
@freeze_time(FROZEN_TIME)
|
2023-12-14 23:01:51 +05:30
|
|
|
def test_dbt_ingest(
|
|
|
|
dbt_test_config,
|
|
|
|
test_resources_dir,
|
|
|
|
pytestconfig,
|
|
|
|
tmp_path,
|
|
|
|
mock_time,
|
|
|
|
requests_mock,
|
|
|
|
):
|
2022-09-10 18:35:58 -07:00
|
|
|
config: DbtTestConfig = dbt_test_config
|
|
|
|
test_resources_dir = pytestconfig.rootpath / "tests/integration/dbt"
|
2021-07-21 12:56:31 -07:00
|
|
|
|
2024-05-15 22:31:05 -07:00
|
|
|
with open(test_resources_dir / "dbt_manifest.json") as f:
|
2023-01-18 08:35:03 -08:00
|
|
|
requests_mock.get("http://some-external-repo/dbt_manifest.json", text=f.read())
|
2022-09-10 18:35:58 -07:00
|
|
|
|
2024-05-15 22:31:05 -07:00
|
|
|
with open(test_resources_dir / "dbt_catalog.json") as f:
|
2023-01-18 08:35:03 -08:00
|
|
|
requests_mock.get("http://some-external-repo/dbt_catalog.json", text=f.read())
|
2022-03-31 06:39:02 +05:30
|
|
|
|
2024-05-15 22:31:05 -07:00
|
|
|
with open(test_resources_dir / "dbt_sources.json") as f:
|
2023-01-18 08:35:03 -08:00
|
|
|
requests_mock.get("http://some-external-repo/dbt_sources.json", text=f.read())
|
2022-09-10 18:35:58 -07:00
|
|
|
|
|
|
|
config.set_paths(
|
|
|
|
dbt_metadata_uri_prefix=test_resources_dir,
|
|
|
|
test_resources_dir=test_resources_dir,
|
|
|
|
tmp_path=tmp_path,
|
|
|
|
)
|
|
|
|
|
|
|
|
pipeline = Pipeline.create(
|
|
|
|
{
|
|
|
|
"run_id": config.run_id,
|
|
|
|
"source": {"type": "dbt", "config": config.source_config},
|
|
|
|
"sink": {
|
|
|
|
"type": "file",
|
|
|
|
"config": config.sink_config,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
pipeline.run()
|
|
|
|
pipeline.raise_from_status()
|
|
|
|
mce_helpers.check_golden_file(
|
|
|
|
pytestconfig,
|
|
|
|
output_path=config.output_path,
|
|
|
|
golden_path=config.golden_path,
|
|
|
|
)
|
|
|
|
|
2022-03-31 06:39:02 +05:30
|
|
|
|
2023-12-14 23:01:51 +05:30
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"config_dict, is_success",
|
|
|
|
[
|
|
|
|
(
|
|
|
|
{
|
|
|
|
"manifest_path": "dbt_manifest.json",
|
|
|
|
"catalog_path": "dbt_catalog.json",
|
|
|
|
"target_platform": "postgres",
|
|
|
|
},
|
|
|
|
True,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
{
|
|
|
|
"manifest_path": "dbt_manifest.json",
|
|
|
|
"catalog_path": "dbt_catalog-this-file-does-not-exist.json",
|
|
|
|
"target_platform": "postgres",
|
|
|
|
},
|
|
|
|
False,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2022-06-18 13:30:04 -07:00
|
|
|
@pytest.mark.integration
|
|
|
|
@freeze_time(FROZEN_TIME)
|
2023-12-14 23:01:51 +05:30
|
|
|
def test_dbt_test_connection(test_resources_dir, config_dict, is_success):
|
|
|
|
config_dict["manifest_path"] = str(
|
|
|
|
(test_resources_dir / config_dict["manifest_path"]).resolve()
|
|
|
|
)
|
|
|
|
config_dict["catalog_path"] = str(
|
|
|
|
(test_resources_dir / config_dict["catalog_path"]).resolve()
|
|
|
|
)
|
|
|
|
report = test_connection_helpers.run_test_connection(DBTCoreSource, config_dict)
|
|
|
|
if is_success:
|
|
|
|
test_connection_helpers.assert_basic_connectivity_success(report)
|
|
|
|
else:
|
|
|
|
test_connection_helpers.assert_basic_connectivity_failure(
|
|
|
|
report, "No such file or directory"
|
|
|
|
)
|
|
|
|
|
2022-06-18 13:30:04 -07:00
|
|
|
|
2023-12-14 23:01:51 +05:30
|
|
|
@pytest.mark.integration
|
|
|
|
@freeze_time(FROZEN_TIME)
|
|
|
|
def test_dbt_tests(test_resources_dir, pytestconfig, tmp_path, mock_time, **kwargs):
|
2022-06-18 13:30:04 -07:00
|
|
|
# Run the metadata ingestion pipeline.
|
|
|
|
output_file = tmp_path / "dbt_test_events.json"
|
|
|
|
golden_path = test_resources_dir / "dbt_test_events_golden.json"
|
|
|
|
|
|
|
|
pipeline = Pipeline(
|
|
|
|
config=PipelineConfig(
|
|
|
|
source=SourceConfig(
|
|
|
|
type="dbt",
|
2022-11-21 14:14:33 -05:00
|
|
|
config=DBTCoreConfig(
|
2024-03-12 12:54:03 -07:00
|
|
|
**_default_dbt_source_args,
|
2022-06-18 13:30:04 -07:00
|
|
|
manifest_path=str(
|
|
|
|
(test_resources_dir / "jaffle_shop_manifest.json").resolve()
|
|
|
|
),
|
|
|
|
catalog_path=str(
|
|
|
|
(test_resources_dir / "jaffle_shop_catalog.json").resolve()
|
|
|
|
),
|
|
|
|
target_platform="postgres",
|
2024-09-27 18:11:06 +01:00
|
|
|
run_results_paths=[
|
|
|
|
str(
|
|
|
|
(
|
|
|
|
test_resources_dir / "jaffle_shop_test_results.json"
|
|
|
|
).resolve()
|
|
|
|
)
|
|
|
|
],
|
2022-06-18 13:30:04 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
sink=DynamicTypedConfig(type="file", config={"filename": str(output_file)}),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
pipeline.run()
|
|
|
|
pipeline.raise_from_status()
|
|
|
|
# Verify the output.
|
|
|
|
mce_helpers.check_golden_file(
|
|
|
|
pytestconfig,
|
|
|
|
output_path=output_file,
|
|
|
|
golden_path=golden_path,
|
|
|
|
ignore_paths=[],
|
|
|
|
)
|
2022-07-27 08:02:00 +08:00
|
|
|
|
|
|
|
|
2022-08-07 06:42:53 +02:00
|
|
|
@pytest.mark.integration
|
|
|
|
@freeze_time(FROZEN_TIME)
|
2023-12-14 23:01:51 +05:30
|
|
|
def test_dbt_tests_only_assertions(
|
|
|
|
test_resources_dir, pytestconfig, tmp_path, mock_time, **kwargs
|
|
|
|
):
|
2022-08-07 06:42:53 +02:00
|
|
|
# Run the metadata ingestion pipeline.
|
|
|
|
output_file = tmp_path / "test_only_assertions.json"
|
|
|
|
|
|
|
|
pipeline = Pipeline(
|
|
|
|
config=PipelineConfig(
|
|
|
|
source=SourceConfig(
|
|
|
|
type="dbt",
|
2022-11-21 14:14:33 -05:00
|
|
|
config=DBTCoreConfig(
|
2024-03-12 12:54:03 -07:00
|
|
|
**_default_dbt_source_args,
|
2022-08-07 06:42:53 +02:00
|
|
|
manifest_path=str(
|
|
|
|
(test_resources_dir / "jaffle_shop_manifest.json").resolve()
|
|
|
|
),
|
|
|
|
catalog_path=str(
|
|
|
|
(test_resources_dir / "jaffle_shop_catalog.json").resolve()
|
|
|
|
),
|
|
|
|
target_platform="postgres",
|
2024-09-27 18:11:06 +01:00
|
|
|
run_results_paths=[
|
|
|
|
str(
|
|
|
|
(
|
|
|
|
test_resources_dir / "jaffle_shop_test_results.json"
|
|
|
|
).resolve()
|
|
|
|
)
|
|
|
|
],
|
2022-08-07 06:42:53 +02:00
|
|
|
entities_enabled=DBTEntitiesEnabled(
|
|
|
|
test_results=EmitDirective.ONLY
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
sink=DynamicTypedConfig(type="file", config={"filename": str(output_file)}),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
pipeline.run()
|
|
|
|
pipeline.raise_from_status()
|
|
|
|
# Verify the output.
|
|
|
|
# No datasets were emitted, and more than 20 events were emitted
|
|
|
|
assert (
|
|
|
|
mce_helpers.assert_entity_urn_not_like(
|
|
|
|
entity_type="dataset",
|
|
|
|
regex_pattern="urn:li:dataset:\\(urn:li:dataPlatform:dbt",
|
|
|
|
file=output_file,
|
|
|
|
)
|
|
|
|
> 20
|
|
|
|
)
|
2024-09-25 13:10:11 -07:00
|
|
|
number_of_valid_assertions_in_test_results = 24
|
2022-08-07 06:42:53 +02:00
|
|
|
assert (
|
|
|
|
mce_helpers.assert_entity_urn_like(
|
|
|
|
entity_type="assertion", regex_pattern="urn:li:assertion:", file=output_file
|
|
|
|
)
|
|
|
|
== number_of_valid_assertions_in_test_results
|
|
|
|
)
|
2022-09-16 15:07:59 -07:00
|
|
|
|
2022-08-07 06:42:53 +02:00
|
|
|
# no assertionInfo should be emitted
|
2022-09-16 15:07:59 -07:00
|
|
|
with pytest.raises(
|
|
|
|
AssertionError, match="Failed to find aspect_name assertionInfo for urns"
|
|
|
|
):
|
2022-08-07 06:42:53 +02:00
|
|
|
mce_helpers.assert_for_each_entity(
|
|
|
|
entity_type="assertion",
|
|
|
|
aspect_name="assertionInfo",
|
|
|
|
aspect_field_matcher={},
|
|
|
|
file=output_file,
|
|
|
|
)
|
|
|
|
|
|
|
|
# all assertions must have an assertionRunEvent emitted (except for one assertion)
|
|
|
|
assert (
|
|
|
|
mce_helpers.assert_for_each_entity(
|
|
|
|
entity_type="assertion",
|
|
|
|
aspect_name="assertionRunEvent",
|
|
|
|
aspect_field_matcher={},
|
|
|
|
file=output_file,
|
|
|
|
exception_urns=["urn:li:assertion:2ff754df689ea951ed2e12cbe356708f"],
|
|
|
|
)
|
|
|
|
== number_of_valid_assertions_in_test_results
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.integration
|
|
|
|
@freeze_time(FROZEN_TIME)
|
|
|
|
def test_dbt_only_test_definitions_and_results(
|
2023-12-14 23:01:51 +05:30
|
|
|
test_resources_dir, pytestconfig, tmp_path, mock_time, **kwargs
|
2022-08-07 06:42:53 +02:00
|
|
|
):
|
|
|
|
# Run the metadata ingestion pipeline.
|
|
|
|
output_file = tmp_path / "test_only_definitions_and_assertions.json"
|
|
|
|
|
|
|
|
pipeline = Pipeline(
|
|
|
|
config=PipelineConfig(
|
|
|
|
source=SourceConfig(
|
|
|
|
type="dbt",
|
2022-11-21 14:14:33 -05:00
|
|
|
config=DBTCoreConfig(
|
2024-03-12 12:54:03 -07:00
|
|
|
**_default_dbt_source_args,
|
2022-08-07 06:42:53 +02:00
|
|
|
manifest_path=str(
|
|
|
|
(test_resources_dir / "jaffle_shop_manifest.json").resolve()
|
|
|
|
),
|
|
|
|
catalog_path=str(
|
|
|
|
(test_resources_dir / "jaffle_shop_catalog.json").resolve()
|
|
|
|
),
|
|
|
|
target_platform="postgres",
|
2024-09-27 18:11:06 +01:00
|
|
|
run_results_paths=[
|
|
|
|
str(
|
|
|
|
(
|
|
|
|
test_resources_dir / "jaffle_shop_test_results.json"
|
|
|
|
).resolve()
|
|
|
|
)
|
|
|
|
],
|
2022-08-07 06:42:53 +02:00
|
|
|
entities_enabled=DBTEntitiesEnabled(
|
|
|
|
sources=EmitDirective.NO,
|
|
|
|
seeds=EmitDirective.NO,
|
|
|
|
models=EmitDirective.NO,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
sink=DynamicTypedConfig(type="file", config={"filename": str(output_file)}),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
pipeline.run()
|
|
|
|
pipeline.raise_from_status()
|
|
|
|
# Verify the output. No datasets were emitted
|
|
|
|
assert (
|
|
|
|
mce_helpers.assert_entity_urn_not_like(
|
|
|
|
entity_type="dataset",
|
|
|
|
regex_pattern="urn:li:dataset:\\(urn:li:dataPlatform:dbt",
|
|
|
|
file=output_file,
|
|
|
|
)
|
|
|
|
> 20
|
|
|
|
)
|
2024-09-25 13:10:11 -07:00
|
|
|
number_of_assertions = 25
|
2022-08-07 06:42:53 +02:00
|
|
|
assert (
|
|
|
|
mce_helpers.assert_entity_urn_like(
|
|
|
|
entity_type="assertion", regex_pattern="urn:li:assertion:", file=output_file
|
|
|
|
)
|
|
|
|
== number_of_assertions
|
|
|
|
)
|
|
|
|
# all assertions must have an assertionInfo emitted
|
|
|
|
assert (
|
|
|
|
mce_helpers.assert_for_each_entity(
|
|
|
|
entity_type="assertion",
|
|
|
|
aspect_name="assertionInfo",
|
|
|
|
aspect_field_matcher={},
|
|
|
|
file=output_file,
|
|
|
|
)
|
|
|
|
== number_of_assertions
|
|
|
|
)
|
|
|
|
# all assertions must have an assertionRunEvent emitted (except for one assertion)
|
|
|
|
assert (
|
|
|
|
mce_helpers.assert_for_each_entity(
|
|
|
|
entity_type="assertion",
|
|
|
|
aspect_name="assertionRunEvent",
|
|
|
|
aspect_field_matcher={},
|
|
|
|
file=output_file,
|
|
|
|
exception_urns=["urn:li:assertion:2ff754df689ea951ed2e12cbe356708f"],
|
|
|
|
)
|
|
|
|
== number_of_assertions - 1
|
|
|
|
)
|