|
| 1 | +# Copyright 2021 Acryl Data, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from unittest.mock import Mock |
| 16 | + |
| 17 | +from datahub.metadata.schema_classes import DomainPropertiesClass |
| 18 | +from datahub.utilities.urns.urn import Urn |
| 19 | +from datahub_actions.utils.name_resolver import DomainNameResolver |
| 20 | + |
| 21 | + |
| 22 | +def test_domain_name_resolver_without_graph(): |
| 23 | + # Test DomainNameResolver fallback behavior when DataHubGraph is None |
| 24 | + resolver = DomainNameResolver() |
| 25 | + domain_urn = Urn.from_string("urn:li:domain:marketing-domain") |
| 26 | + entity_name = resolver.get_entity_name(domain_urn, None) |
| 27 | + assert entity_name == "marketing-domain" |
| 28 | + |
| 29 | + |
| 30 | +def test_domain_name_resolver_with_graph(): |
| 31 | + resolver = DomainNameResolver() |
| 32 | + domain_urn = Urn.from_string("urn:li:domain:marketing-domain") |
| 33 | + mock_graph = Mock() |
| 34 | + |
| 35 | + # Test scenario 1: Graph available but no properties found |
| 36 | + mock_graph.get_aspect.return_value = None |
| 37 | + entity_name = resolver.get_entity_name(domain_urn, mock_graph) |
| 38 | + mock_graph.get_aspect.assert_called_with(str(domain_urn), DomainPropertiesClass) |
| 39 | + assert entity_name == "marketing-domain" |
| 40 | + |
| 41 | + # Reset mock for next scenario |
| 42 | + mock_graph.reset_mock() |
| 43 | + |
| 44 | + # Test scenario 2: Graph returns properties with name |
| 45 | + mock_properties = DomainPropertiesClass(name="Marketing Domain") |
| 46 | + mock_graph.get_aspect.return_value = mock_properties |
| 47 | + entity_name = resolver.get_entity_name(domain_urn, mock_graph) |
| 48 | + mock_graph.get_aspect.assert_called_with(str(domain_urn), DomainPropertiesClass) |
| 49 | + assert entity_name == "Marketing Domain" |
0 commit comments