| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | #  Copyright 2021 Collate | 
					
						
							|  |  |  | #  Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  | #  you may not use this file except in compliance with the License. | 
					
						
							|  |  |  | #  You may obtain a copy of the License at | 
					
						
							|  |  |  | #  http://www.apache.org/licenses/LICENSE-2.0 | 
					
						
							|  |  |  | #  Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  | #  distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  | #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  | #  See the License for the specific language governing permissions and | 
					
						
							|  |  |  | #  limitations under the License. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | OpenMetadata high-level API Table test | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  | import logging | 
					
						
							|  |  |  | import time | 
					
						
							| 
									
										
										
										
											2023-07-07 00:51:23 -07:00
										 |  |  | from datetime import datetime | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | from unittest import TestCase | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  | from metadata.generated.schema.entity.data.database import Database | 
					
						
							|  |  |  | from metadata.generated.schema.entity.data.databaseSchema import DatabaseSchema | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  | from metadata.generated.schema.entity.data.table import ( | 
					
						
							|  |  |  |     Column, | 
					
						
							|  |  |  |     ColumnName, | 
					
						
							|  |  |  |     DataType, | 
					
						
							|  |  |  |     Table, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  | from metadata.generated.schema.entity.services.databaseService import DatabaseService | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  | from metadata.generated.schema.entity.teams.team import Team | 
					
						
							|  |  |  | from metadata.generated.schema.entity.teams.user import User | 
					
						
							| 
									
										
										
										
											2023-07-07 00:51:23 -07:00
										 |  |  | from metadata.generated.schema.tests.testCase import TestCase as TestCaseEntity | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  | from metadata.generated.schema.tests.testCase import TestCaseParameterValue | 
					
						
							|  |  |  | from metadata.generated.schema.tests.testDefinition import ( | 
					
						
							|  |  |  |     EntityType, | 
					
						
							|  |  |  |     TestCaseParameterDefinition, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  | from metadata.generated.schema.type.basic import Markdown | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  | from metadata.generated.schema.type.entityReference import EntityReference | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  | from metadata.generated.schema.type.tagLabel import ( | 
					
						
							|  |  |  |     LabelType, | 
					
						
							|  |  |  |     State, | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |     TagFQN, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |     TagLabel, | 
					
						
							|  |  |  |     TagSource, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  | from metadata.ingestion.models.patch_request import ( | 
					
						
							|  |  |  |     ALLOWED_COMMON_PATCH_FIELDS, | 
					
						
							|  |  |  |     RESTRICT_UPDATE_LIST, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  | from metadata.ingestion.models.table_metadata import ColumnTag | 
					
						
							| 
									
										
										
										
											2022-10-15 14:56:30 +02:00
										 |  |  | from metadata.utils.helpers import find_column_in_table | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-22 14:28:42 +05:30
										 |  |  | from ..integration_base import ( | 
					
						
							|  |  |  |     generate_name, | 
					
						
							|  |  |  |     get_create_entity, | 
					
						
							|  |  |  |     get_create_service, | 
					
						
							|  |  |  |     get_create_team_entity, | 
					
						
							|  |  |  |     get_create_test_case, | 
					
						
							|  |  |  |     get_create_test_definition, | 
					
						
							|  |  |  |     get_create_test_suite, | 
					
						
							|  |  |  |     get_create_user_entity, | 
					
						
							|  |  |  |     int_admin_ometa, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  | PII_TAG_LABEL = TagLabel( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |     tagFQN=TagFQN("PII.Sensitive"), | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |     labelType=LabelType.Automated, | 
					
						
							|  |  |  |     state=State.Suggested.value, | 
					
						
							|  |  |  |     source=TagSource.Classification, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TIER_TAG_LABEL = TagLabel( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |     tagFQN=TagFQN("Tier.Tier2"), | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |     labelType=LabelType.Automated, | 
					
						
							|  |  |  |     state=State.Suggested.value, | 
					
						
							|  |  |  |     source=TagSource.Classification, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class OMetaTableTest(TestCase): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Run this integration test with the local API available | 
					
						
							|  |  |  |     Install the ingestion package before running the tests | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     service_entity_id = None | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |     table: Table = None | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |     patch_test_table: Table = None | 
					
						
							| 
									
										
										
										
											2023-07-07 00:51:23 -07:00
										 |  |  |     test_case: TestCaseEntity = None | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |     db_entity: Database = None | 
					
						
							|  |  |  |     db_schema_entity: DatabaseSchema = None | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |     user_1: User = None | 
					
						
							|  |  |  |     user_2: User = None | 
					
						
							|  |  |  |     team_1: Team = None | 
					
						
							|  |  |  |     team_2: Team = None | 
					
						
							|  |  |  |     owner_user_1: EntityReference = None | 
					
						
							|  |  |  |     owner_user_2: EntityReference = None | 
					
						
							|  |  |  |     owner_team_1: EntityReference = None | 
					
						
							|  |  |  |     owner_team_2: EntityReference = None | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |     metadata = int_admin_ometa() | 
					
						
							|  |  |  |     service_name = generate_name() | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |     service_type = "databaseService" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def check_es_index(cls) -> None: | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Wait until the index has been updated with the test user. | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         logging.info("Checking ES index status...") | 
					
						
							|  |  |  |         tries = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         res = None | 
					
						
							|  |  |  |         while not res and tries <= 5:  # Kill in 5 seconds | 
					
						
							|  |  |  |             res = cls.metadata.es_search_from_fqn( | 
					
						
							|  |  |  |                 entity_type=User, | 
					
						
							|  |  |  |                 fqn_search_string="Levy", | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             if not res: | 
					
						
							|  |  |  |                 tries += 1 | 
					
						
							|  |  |  |                 time.sleep(1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def setUpClass(cls) -> None: | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Prepare ingredients | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         # Create the service entity | 
					
						
							|  |  |  |         create_service = get_create_service( | 
					
						
							|  |  |  |             entity=DatabaseService, name=cls.service_name | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         cls.service_entity = cls.metadata.create_or_update(data=create_service) | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         # Create the database entity | 
					
						
							|  |  |  |         create_db = get_create_entity( | 
					
						
							|  |  |  |             entity=Database, reference=cls.service_entity.fullyQualifiedName | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         cls.db_entity = cls.metadata.create_or_update(data=create_db) | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         # Create the schema entity | 
					
						
							|  |  |  |         create_schema = get_create_entity( | 
					
						
							|  |  |  |             entity=DatabaseSchema, reference=cls.db_entity.fullyQualifiedName | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         cls.db_schema_entity = cls.metadata.create_or_update(data=create_schema) | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         # Create the table entity | 
					
						
							|  |  |  |         cls.create = get_create_entity( | 
					
						
							|  |  |  |             entity=Table, reference=cls.db_schema_entity.fullyQualifiedName | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         cls.table = cls.metadata.create_or_update(data=cls.create) | 
					
						
							|  |  |  |         cls.patch_test_table = cls.metadata.create_or_update(data=cls.create) | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         # Create test case | 
					
						
							|  |  |  |         cls.test_definition = cls.metadata.create_or_update( | 
					
						
							|  |  |  |             get_create_test_definition( | 
					
						
							|  |  |  |                 parameter_definition=[TestCaseParameterDefinition(name="foo")], | 
					
						
							|  |  |  |                 entity_type=EntityType.TABLE, | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         cls.test_suite = cls.metadata.create_or_update_executable_test_suite( | 
					
						
							|  |  |  |             get_create_test_suite( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |                 executable_entity_reference=cls.table.fullyQualifiedName.root | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |             ) | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         cls.test_case = cls.metadata.create_or_update( | 
					
						
							|  |  |  |             get_create_test_case( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |                 entity_link=f"<#E::table::{cls.table.fullyQualifiedName.root}>", | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |                 test_suite=cls.test_suite.fullyQualifiedName, | 
					
						
							|  |  |  |                 test_definition=cls.test_definition.fullyQualifiedName, | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |                 parameter_values=[TestCaseParameterValue(name="foo", value="10")], | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |             ) | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |         cls.user_1 = cls.metadata.create_or_update( | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |             data=get_create_user_entity( | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |                 name="random.user", email="random.user@getcollate.io" | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |             ) | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         cls.user_2 = cls.metadata.create_or_update(data=get_create_user_entity()) | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         cls.team_1 = cls.metadata.create_or_update( | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |             data=get_create_team_entity( | 
					
						
							|  |  |  |                 name="Team 1", users=[cls.user_1.id, cls.user_2.id] | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             ) | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.team_2 = cls.metadata.create_or_update( | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |             data=get_create_team_entity(name="Team 2", users=[cls.user_2.id]) | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.owner_user_1 = EntityReference(id=cls.user_1.id, type="user") | 
					
						
							|  |  |  |         cls.owner_user_2 = EntityReference(id=cls.user_2.id, type="user") | 
					
						
							|  |  |  |         cls.owner_team_1 = EntityReference(id=cls.team_1.id, type="team") | 
					
						
							|  |  |  |         cls.owner_team_2 = EntityReference(id=cls.team_2.id, type="team") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Leave some time for indexes to get updated, otherwise this happens too fast | 
					
						
							|  |  |  |         cls.check_es_index() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def tearDownClass(cls) -> None: | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Clean up | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         service_id = str( | 
					
						
							|  |  |  |             cls.metadata.get_by_name( | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |                 entity=DatabaseService, fqn=cls.service_name | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             ).id.root | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.metadata.delete( | 
					
						
							|  |  |  |             entity=DatabaseService, | 
					
						
							|  |  |  |             entity_id=service_id, | 
					
						
							|  |  |  |             recursive=True, | 
					
						
							|  |  |  |             hard_delete=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |         cls.metadata.delete( | 
					
						
							|  |  |  |             entity=User, | 
					
						
							|  |  |  |             entity_id=cls.user_1.id, | 
					
						
							|  |  |  |             hard_delete=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.metadata.delete( | 
					
						
							|  |  |  |             entity=User, | 
					
						
							|  |  |  |             entity_id=cls.user_2.id, | 
					
						
							|  |  |  |             hard_delete=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.metadata.delete( | 
					
						
							|  |  |  |             entity=Team, | 
					
						
							|  |  |  |             entity_id=cls.team_1.id, | 
					
						
							|  |  |  |             hard_delete=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.metadata.delete( | 
					
						
							|  |  |  |             entity=Team, | 
					
						
							|  |  |  |             entity_id=cls.team_2.id, | 
					
						
							|  |  |  |             hard_delete=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |     def test_patch_table(self): | 
					
						
							|  |  |  |         new_patched_table = self.patch_test_table.copy(deep=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Test adding a new column to the table | 
					
						
							|  |  |  |         new_patched_table.columns.append( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             Column(name=ColumnName("new_column"), dataType=DataType.BIGINT), | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         ) | 
					
						
							|  |  |  |         # Test if table and column descriptions are getting patched | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         new_patched_table.description = Markdown("This should get patched") | 
					
						
							|  |  |  |         new_patched_table.columns[0].description = Markdown( | 
					
						
							|  |  |  |             root="This column description should get patched" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |         # Test if table and column tags are getting patched | 
					
						
							|  |  |  |         new_patched_table.tags = [PII_TAG_LABEL] | 
					
						
							|  |  |  |         new_patched_table.columns[0].tags = [PII_TAG_LABEL] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Test if table owners are getting patched (user and team) | 
					
						
							|  |  |  |         new_patched_table.owner = self.owner_user_1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         patched_table = self.metadata.patch( | 
					
						
							|  |  |  |             entity=type(self.patch_test_table), | 
					
						
							|  |  |  |             source=self.patch_test_table, | 
					
						
							|  |  |  |             destination=new_patched_table, | 
					
						
							|  |  |  |             allowed_fields=ALLOWED_COMMON_PATCH_FIELDS, | 
					
						
							|  |  |  |             restrict_update_fields=RESTRICT_UPDATE_LIST, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert patched_table.description.root == "This should get patched" | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         assert ( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             patched_table.columns[0].description.root | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |             == "This column description should get patched" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert patched_table.tags[0].tagFQN == PII_TAG_LABEL.tagFQN | 
					
						
							|  |  |  |         assert patched_table.columns[0].tags[0].tagFQN == PII_TAG_LABEL.tagFQN | 
					
						
							|  |  |  |         assert patched_table.owner.id == self.owner_user_1.id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # After this we'll again update the descriptions, tags and owner | 
					
						
							|  |  |  |         new_patched_table = patched_table.copy(deep=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Descriptions should not override already present descriptions | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         new_patched_table.description = Markdown("This should NOT get patched") | 
					
						
							|  |  |  |         new_patched_table.columns[0].description = Markdown( | 
					
						
							|  |  |  |             root="This column description should NOT get patched" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |         # Only adding the tags is allowed | 
					
						
							|  |  |  |         new_patched_table.tags = [PII_TAG_LABEL, TIER_TAG_LABEL] | 
					
						
							|  |  |  |         new_patched_table.columns[0].tags = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Already existing owner should not get patched | 
					
						
							|  |  |  |         new_patched_table.owner = self.owner_user_2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         patched_table = self.metadata.patch( | 
					
						
							|  |  |  |             entity=type(patched_table), | 
					
						
							|  |  |  |             source=patched_table, | 
					
						
							|  |  |  |             destination=new_patched_table, | 
					
						
							|  |  |  |             allowed_fields=ALLOWED_COMMON_PATCH_FIELDS, | 
					
						
							|  |  |  |             restrict_update_fields=RESTRICT_UPDATE_LIST, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert patched_table.description.root != "This should NOT get patched" | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         assert ( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             patched_table.columns[0].description.root | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |             != "This column description should NOT get patched" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert patched_table.tags[0].tagFQN == PII_TAG_LABEL.tagFQN | 
					
						
							|  |  |  |         assert patched_table.tags[1].tagFQN == TIER_TAG_LABEL.tagFQN | 
					
						
							|  |  |  |         assert patched_table.columns[0].tags[0].tagFQN == PII_TAG_LABEL.tagFQN | 
					
						
							|  |  |  |         assert patched_table.owner.id == self.owner_user_1.id | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |     def test_patch_description(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Update description and force | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         updated: Table = self.metadata.patch_description( | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             entity=Table, source=self.table, description="New description" | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert updated.description.root == "New description" | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         not_updated = self.metadata.patch_description( | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             entity=Table, source=self.table, description="Not passing force" | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         assert not not_updated | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         force_updated: Table = self.metadata.patch_description( | 
					
						
							|  |  |  |             entity=Table, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.table, | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |             description="Forced new", | 
					
						
							|  |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert force_updated.description.root == "Forced new" | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-07 00:51:23 -07:00
										 |  |  |     def test_patch_description_TestCase(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Update description and force | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         new_description = "Description " + str(datetime.now()) | 
					
						
							|  |  |  |         updated: TestCaseEntity = self.metadata.patch_description( | 
					
						
							|  |  |  |             entity=TestCaseEntity, | 
					
						
							|  |  |  |             source=self.test_case, | 
					
						
							|  |  |  |             description=new_description, | 
					
						
							|  |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert updated.description.root == new_description | 
					
						
							| 
									
										
										
										
											2023-07-07 00:51:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         not_updated = self.metadata.patch_description( | 
					
						
							|  |  |  |             entity=TestCaseEntity, | 
					
						
							|  |  |  |             source=self.test_case, | 
					
						
							|  |  |  |             description="Not passing force", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         assert not not_updated | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         force_updated: TestCaseEntity = self.metadata.patch_description( | 
					
						
							|  |  |  |             entity=TestCaseEntity, | 
					
						
							|  |  |  |             source=self.test_case, | 
					
						
							|  |  |  |             description="Forced new", | 
					
						
							|  |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert force_updated.description.root == "Forced new" | 
					
						
							| 
									
										
										
										
											2023-07-07 00:51:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |     def test_patch_column_description(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Update column description and force | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         updated: Table = self.metadata.patch_column_description( | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             table=self.table, | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |             description="New column description", | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             column_fqn=self.table.fullyQualifiedName.root + ".another", | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         updated_col = find_column_in_table(column_name="another", table=updated) | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert updated_col.description.root == "New column description" | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         not_updated = self.metadata.patch_column_description( | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             table=self.table, | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |             description="Not passing force", | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             column_fqn=self.table.fullyQualifiedName.root + ".another", | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         assert not not_updated | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         force_updated: Table = self.metadata.patch_column_description( | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             table=self.table, | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |             description="Forced new", | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             column_fqn=self.table.fullyQualifiedName.root + ".another", | 
					
						
							| 
									
										
										
										
											2022-07-19 12:58:58 +02:00
										 |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         updated_col = find_column_in_table(column_name="another", table=force_updated) | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert updated_col.description.root == "Forced new" | 
					
						
							| 
									
										
										
										
											2022-10-15 14:56:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |     def test_patch_tags(self): | 
					
						
							| 
									
										
										
										
											2022-10-15 14:56:30 +02:00
										 |  |  |         """
 | 
					
						
							|  |  |  |         Update table tags | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |         updated: Table = self.metadata.patch_tags( | 
					
						
							| 
									
										
										
										
											2022-10-15 14:56:30 +02:00
										 |  |  |             entity=Table, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.table, | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |             tag_labels=[PII_TAG_LABEL, TIER_TAG_LABEL],  # Shipped by default | 
					
						
							| 
									
										
										
										
											2022-10-15 14:56:30 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert updated.tags[0].tagFQN.root == "PII.Sensitive" | 
					
						
							|  |  |  |         assert updated.tags[1].tagFQN.root == "Tier.Tier2" | 
					
						
							| 
									
										
										
										
											2022-10-15 14:56:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_patch_column_tags(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Update column tags | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |         updated: Table = self.metadata.patch_column_tags( | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             table=self.table, | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |             column_tags=[ | 
					
						
							|  |  |  |                 ColumnTag( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |                     column_fqn=self.table.fullyQualifiedName.root + ".id", | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |                     tag_label=PII_TAG_LABEL,  # Shipped by default | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2022-10-15 14:56:30 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  |         updated_col = find_column_in_table(column_name="id", table=updated) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert updated_col.tags[0].tagFQN.root == "PII.Sensitive" | 
					
						
							| 
									
										
										
										
											2022-10-15 14:56:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |         updated_again: Table = self.metadata.patch_column_tags( | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             table=self.table, | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |             column_tags=[ | 
					
						
							|  |  |  |                 ColumnTag( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |                     column_fqn=self.table.fullyQualifiedName.root + ".id", | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |                     tag_label=TIER_TAG_LABEL,  # Shipped by default | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2022-10-15 14:56:30 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  |         updated_again_col = find_column_in_table(column_name="id", table=updated_again) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         assert updated_again_col.tags[0].tagFQN.root == "PII.Sensitive" | 
					
						
							|  |  |  |         assert updated_again_col.tags[1].tagFQN.root == "Tier.Tier2" | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_patch_owner(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Update owner | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         # Database, no existing owner, owner is a User -> Modified | 
					
						
							|  |  |  |         updated: Database = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Database, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.db_entity, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             owner=self.owner_user_1, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is not None | 
					
						
							|  |  |  |         assert updated.owner.id == self.owner_user_1.id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Database, existing owner, owner is a User, no force -> Unmodified | 
					
						
							|  |  |  |         updated: Database = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Database, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.db_entity, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             owner=self.owner_user_2, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Database, existing owner, owner is a User, force -> Modified | 
					
						
							|  |  |  |         updated: Database = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Database, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.db_entity, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             owner=self.owner_user_2, | 
					
						
							|  |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is not None | 
					
						
							|  |  |  |         assert updated.owner.id == self.owner_user_2.id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Database, existing owner, no owner, no force -> Unmodified | 
					
						
							|  |  |  |         updated: Database = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Database, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.db_entity, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |         ) | 
					
						
							|  |  |  |         assert updated is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Database, existing owner, no owner, force -> Modified | 
					
						
							|  |  |  |         updated: Database = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Database, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.db_entity, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is not None | 
					
						
							|  |  |  |         assert updated.owner is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # DatabaseSchema, no existing owner, owner is Team -> Modified | 
					
						
							|  |  |  |         updated: DatabaseSchema = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=DatabaseSchema, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.db_schema_entity, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             owner=self.owner_team_1, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is not None | 
					
						
							|  |  |  |         assert updated.owner.id == self.owner_team_1.id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # DatabaseSchema, existing owner, owner is Team, no force -> Unmodified | 
					
						
							|  |  |  |         updated: DatabaseSchema = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=DatabaseSchema, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.db_schema_entity, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             owner=self.owner_team_2, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # DatabaseSchema, existing owner, owner is Team, force -> Modified | 
					
						
							|  |  |  |         updated: DatabaseSchema = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=DatabaseSchema, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.db_schema_entity, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             owner=self.owner_team_2, | 
					
						
							|  |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is not None | 
					
						
							|  |  |  |         assert updated.owner.id == self.owner_team_2.id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # DatabaseSchema, existing owner, no owner, no force -> Unmodified | 
					
						
							|  |  |  |         updated: DatabaseSchema = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=DatabaseSchema, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.db_schema_entity, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |         ) | 
					
						
							|  |  |  |         assert updated is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # DatabaseSchema, existing owner, no owner, force -> Modified | 
					
						
							|  |  |  |         updated: DatabaseSchema = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=DatabaseSchema, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.db_schema_entity, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is not None | 
					
						
							|  |  |  |         assert updated.owner is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Table, no existing owner, owner is a Team -> Modified | 
					
						
							|  |  |  |         updated: Table = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Table, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.table, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             owner=self.owner_team_1, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is not None | 
					
						
							|  |  |  |         assert updated.owner.id == self.owner_team_1.id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Table, existing owner, owner is a Team, no force -> Unmodified | 
					
						
							|  |  |  |         updated: Table = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Table, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.table, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             owner=self.owner_team_2, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Table, existing owner, owner is a Team, force -> Modified | 
					
						
							|  |  |  |         updated: Table = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Table, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.table, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             owner=self.owner_team_2, | 
					
						
							|  |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is not None | 
					
						
							|  |  |  |         assert updated.owner.id == self.owner_team_2.id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Table, existing owner, no owner, no force -> Unmodified | 
					
						
							|  |  |  |         updated: Table = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Table, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.table, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |         ) | 
					
						
							|  |  |  |         assert updated is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Table, existing owner, no owner, no force -> Modified | 
					
						
							|  |  |  |         updated: Table = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Table, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=self.table, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is not None | 
					
						
							|  |  |  |         assert updated.owner is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Table with non-existent id, force -> Unmodified | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |         non_existent_table = self.table.copy(deep=True) | 
					
						
							|  |  |  |         non_existent_table.id = "9facb7b3-1dee-4017-8fca-1254b700afef" | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |         updated: Table = self.metadata.patch_owner( | 
					
						
							|  |  |  |             entity=Table, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             source=non_existent_table, | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |             force=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         assert updated is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Table, no owner, invalid owner type -> Unmodified | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |         # Enable after https://github.com/open-metadata/OpenMetadata/issues/11715 | 
					
						
							|  |  |  |         # updated: Table = self.metadata.patch_owner( | 
					
						
							|  |  |  |         #     entity=Table, | 
					
						
							|  |  |  |         #     source=self.table, | 
					
						
							|  |  |  |         #     owner=EntityReference(id=self.table.id, type="table"), | 
					
						
							|  |  |  |         #     force=True, | 
					
						
							|  |  |  |         # ) | 
					
						
							|  |  |  |         # assert updated is None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_patch_nested_col(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         create a table with nested cols and run patch on it | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2024-01-25 11:16:22 +05:30
										 |  |  |         create = get_create_entity( | 
					
						
							|  |  |  |             entity=Table, reference=self.db_schema_entity.fullyQualifiedName | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         created: Table = self.metadata.create_or_update(create) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |         with_tags: Table = self.metadata.patch_column_tags( | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             table=created, | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |             column_tags=[ | 
					
						
							|  |  |  |                 ColumnTag( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |                     column_fqn=created.fullyQualifiedName.root + ".struct.id", | 
					
						
							| 
									
										
										
										
											2023-10-02 14:44:41 +02:00
										 |  |  |                     tag_label=TIER_TAG_LABEL, | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             with_tags.columns[2].children[0].tags[0].tagFQN.root, | 
					
						
							|  |  |  |             TIER_TAG_LABEL.tagFQN.root, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         with_description: Table = self.metadata.patch_column_description( | 
					
						
							|  |  |  |             table=created, | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             column_fqn=created.fullyQualifiedName.root + ".struct.name", | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             description="I am so nested", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             with_description.columns[2].children[1].description.root, | 
					
						
							| 
									
										
										
										
											2023-05-23 06:47:11 -07:00
										 |  |  |             "I am so nested", | 
					
						
							| 
									
										
										
										
											2023-03-06 06:32:58 -08:00
										 |  |  |         ) |