2024-10-22 06:59:40 -05:00
|
|
|
import dataclasses
|
|
|
|
import json
|
|
|
|
import time
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
import pytest
|
2025-01-17 23:50:13 +05:30
|
|
|
|
2024-10-22 06:59:40 -05:00
|
|
|
from datahub.emitter.aspect import JSON_CONTENT_TYPE
|
|
|
|
from datahub.emitter.mce_builder import make_dashboard_urn
|
|
|
|
from datahub.emitter.mcp import MetadataChangeProposalWrapper
|
2025-05-05 10:54:31 -05:00
|
|
|
from datahub.emitter.rest_emitter import EmitMode
|
2024-10-22 06:59:40 -05:00
|
|
|
from datahub.emitter.serialization_helper import pre_json_transform
|
|
|
|
from datahub.metadata.schema_classes import (
|
|
|
|
AuditStampClass,
|
|
|
|
ChangeAuditStampsClass,
|
|
|
|
DashboardInfoClass,
|
|
|
|
GenericAspectClass,
|
|
|
|
MetadataChangeProposalClass,
|
|
|
|
)
|
|
|
|
from datahub.utilities.urns.urn import guess_entity_type
|
|
|
|
from tests.utils import delete_urns
|
|
|
|
|
|
|
|
generated_urns: List[str] = []
|
|
|
|
|
|
|
|
|
|
|
|
@dataclasses.dataclass
|
|
|
|
class MetadataChangeProposalInvalidWrapper(MetadataChangeProposalWrapper):
|
|
|
|
@staticmethod
|
|
|
|
def _make_generic_aspect(dict) -> GenericAspectClass:
|
|
|
|
serialized = json.dumps(pre_json_transform(dict))
|
|
|
|
return GenericAspectClass(
|
|
|
|
value=serialized.encode(),
|
|
|
|
contentType=JSON_CONTENT_TYPE,
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def __post_init__(self) -> None:
|
|
|
|
if self.entityUrn:
|
|
|
|
self.entityType = guess_entity_type(self.entityUrn)
|
|
|
|
|
|
|
|
def make_mcp(self) -> MetadataChangeProposalClass:
|
|
|
|
serializedAspect = None
|
|
|
|
if self.aspect is not None:
|
|
|
|
serializedAspect = (
|
|
|
|
MetadataChangeProposalInvalidWrapper._make_generic_aspect(self.aspect)
|
|
|
|
)
|
|
|
|
|
|
|
|
mcp = self._make_mcp_without_aspects()
|
|
|
|
mcp.aspect = serializedAspect
|
|
|
|
return mcp
|
|
|
|
|
|
|
|
|
2025-01-23 17:58:06 -08:00
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
2024-10-22 06:59:40 -05:00
|
|
|
def ingest_cleanup_data(auth_session, graph_client, request):
|
|
|
|
yield
|
|
|
|
delete_urns(graph_client, generated_urns)
|
|
|
|
|
|
|
|
|
|
|
|
def test_gms_ignore_unknown_dashboard_info(graph_client):
|
|
|
|
dashboard_urn = make_dashboard_urn(platform="looker", name="test-ignore-unknown")
|
|
|
|
generated_urns.extend([dashboard_urn])
|
|
|
|
|
|
|
|
audit_stamp = pre_json_transform(
|
|
|
|
ChangeAuditStampsClass(
|
|
|
|
created=AuditStampClass(
|
|
|
|
time=int(time.time() * 1000),
|
|
|
|
actor="urn:li:corpuser:datahub",
|
|
|
|
)
|
|
|
|
).to_obj()
|
|
|
|
)
|
|
|
|
|
|
|
|
invalid_dashboard_info = {
|
|
|
|
"title": "Ignore Unknown Title",
|
|
|
|
"description": "Ignore Unknown Description",
|
|
|
|
"lastModified": audit_stamp,
|
|
|
|
"notAValidField": "invalid field value",
|
|
|
|
}
|
|
|
|
mcpw = MetadataChangeProposalInvalidWrapper(
|
|
|
|
entityUrn=dashboard_urn,
|
|
|
|
aspectName="dashboardInfo",
|
|
|
|
aspect=invalid_dashboard_info,
|
|
|
|
)
|
|
|
|
|
|
|
|
mcp = mcpw.make_mcp()
|
|
|
|
assert "notAValidField" in str(mcp)
|
|
|
|
assert "invalid field value" in str(mcp)
|
|
|
|
|
2025-05-05 10:54:31 -05:00
|
|
|
graph_client.emit_mcp(mcpw, emit_mode=EmitMode.SYNC_PRIMARY)
|
2024-10-22 06:59:40 -05:00
|
|
|
|
|
|
|
dashboard_info = graph_client.get_aspect(
|
|
|
|
entity_urn=dashboard_urn,
|
|
|
|
aspect_type=DashboardInfoClass,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert dashboard_info
|
|
|
|
assert dashboard_info.title == invalid_dashboard_info["title"]
|
|
|
|
assert dashboard_info.description == invalid_dashboard_info["description"]
|