| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | #  Copyright 2021 Schlameel | 
					
						
							|  |  |  | #  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 Glossary test | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | import logging | 
					
						
							|  |  |  | import time | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  | from copy import deepcopy | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | from unittest import TestCase | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from metadata.generated.schema.api.data.createGlossary import CreateGlossaryRequest | 
					
						
							|  |  |  | from metadata.generated.schema.api.data.createGlossaryTerm import ( | 
					
						
							|  |  |  |     CreateGlossaryTermRequest, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | from metadata.generated.schema.api.teams.createUser import CreateUserRequest | 
					
						
							|  |  |  | from metadata.generated.schema.entity.data.glossary import Glossary | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  | from metadata.generated.schema.entity.data.glossaryTerm import ( | 
					
						
							|  |  |  |     GlossaryTerm, | 
					
						
							|  |  |  |     TermReference, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | from metadata.generated.schema.entity.services.connections.metadata.openMetadataConnection import ( | 
					
						
							|  |  |  |     OpenMetadataConnection, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | from metadata.generated.schema.entity.teams.user import User | 
					
						
							|  |  |  | from metadata.generated.schema.security.client.openMetadataJWTClientConfig import ( | 
					
						
							|  |  |  |     OpenMetadataJWTClientConfig, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | from metadata.generated.schema.type import basic | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  | from metadata.generated.schema.type.basic import ( | 
					
						
							|  |  |  |     Email, | 
					
						
							|  |  |  |     EntityName, | 
					
						
							|  |  |  |     FullyQualifiedEntityName, | 
					
						
							|  |  |  |     Markdown, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | from metadata.generated.schema.type.entityReference import EntityReference | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  | from metadata.generated.schema.type.entityReferenceList import EntityReferenceList | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | from metadata.ingestion.ometa.ometa_api import OpenMetadata | 
					
						
							|  |  |  | from metadata.ingestion.ometa.utils import model_str | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  | from metadata.utils import fqn | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class OMetaGlossaryTest(TestCase): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Run this integration test with the local API available | 
					
						
							|  |  |  |     Install the ingestion package before running the tests | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     service_entity_id = None | 
					
						
							|  |  |  |     glossary_entity_id: basic.Uuid = None | 
					
						
							|  |  |  |     create_glossary: CreateGlossaryRequest = None | 
					
						
							|  |  |  |     create_glossary_term_1: CreateGlossaryTermRequest = None | 
					
						
							|  |  |  |     create_glossary_term_2: CreateGlossaryTermRequest = None | 
					
						
							|  |  |  |     create_glossary_term_3: CreateGlossaryTermRequest = None | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |     glossary: Glossary = None | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |     glossary_term_1: GlossaryTerm = None | 
					
						
							|  |  |  |     glossary_term_2: GlossaryTerm = None | 
					
						
							|  |  |  |     glossary_term_3: GlossaryTerm = None | 
					
						
							|  |  |  |     user_1: User = None | 
					
						
							|  |  |  |     user_2: User = None | 
					
						
							|  |  |  |     user_3: User = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     server_config = OpenMetadataConnection( | 
					
						
							|  |  |  |         hostPort="http://localhost:8585/api", | 
					
						
							|  |  |  |         authProvider="openmetadata", | 
					
						
							|  |  |  |         securityConfig=OpenMetadataJWTClientConfig( | 
					
						
							|  |  |  |             jwtToken="eyJraWQiOiJHYjM4OWEtOWY3Ni1nZGpzLWE5MmotMDI0MmJrOTQzNTYiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImlzQm90IjpmYWxzZSwiaXNzIjoib3Blbi1tZXRhZGF0YS5vcmciLCJpYXQiOjE2NjM5Mzg0NjIsImVtYWlsIjoiYWRtaW5Ab3Blbm1ldGFkYXRhLm9yZyJ9.tS8um_5DKu7HgzGBzS1VTA5uUjKWOCU0B_j08WXBiEC0mr0zNREkqVfwFDD-d24HlNEbrqioLsBuFRiwIWKc1m_ZlVQbG7P36RUxhuv2vbSp80FKyNM-Tj93FDzq91jsyNmsQhyNv_fNr3TXfzzSPjHt8Go0FMMP66weoKMgW2PbXlhVKwEuXUHyakLLzewm9UMeQaEiRzhiTMU3UkLXcKbYEJJvfNFcLwSl9W8JCO_l0Yj3ud-qt_nQYEZwqW6u5nfdQllN133iikV4fM5QZsMCnm8Rq1mvLR0y9bmJiD7fwM1tmJ791TUWqmKaTnP49U493VanKpUAfzIiOiIbhg" | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     metadata = OpenMetadata(server_config) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert metadata.health_check() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @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) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def setUpClass(cls) -> None: | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Prepare ingredients | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.user_1 = cls.metadata.create_or_update( | 
					
						
							|  |  |  |             data=CreateUserRequest( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |                 name=EntityName("test.user.1"), | 
					
						
							|  |  |  |                 email=Email(root="test.user.1@getcollate.io"), | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.user_2 = cls.metadata.create_or_update( | 
					
						
							|  |  |  |             data=CreateUserRequest( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |                 name=EntityName("test.user.2"), | 
					
						
							|  |  |  |                 email=Email(root="test.user.2@getcollate.io"), | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.user_3 = cls.metadata.create_or_update( | 
					
						
							|  |  |  |             data=CreateUserRequest( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |                 name=EntityName("test.user.3"), | 
					
						
							|  |  |  |                 email=Email(root="test.user.3@getcollate.io"), | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.check_es_index() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.create_glossary = CreateGlossaryRequest( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             name=EntityName("test-glossary"), | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             displayName="test-glossary", | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             description=Markdown("Description of test glossary"), | 
					
						
							| 
									
										
										
										
											2024-07-29 23:06:39 -07:00
										 |  |  |             owners=EntityReferenceList( | 
					
						
							|  |  |  |                 root=[ | 
					
						
							|  |  |  |                     EntityReference( | 
					
						
							|  |  |  |                         id=cls.user_1.id, | 
					
						
							|  |  |  |                         type="user", | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 ], | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.create_glossary_term_1 = CreateGlossaryTermRequest( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             glossary=FullyQualifiedEntityName(cls.create_glossary.name.root), | 
					
						
							|  |  |  |             name=EntityName("GT1"), | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             displayName="Glossary Term 1", | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             description=Markdown("Test glossary term 1"), | 
					
						
							| 
									
										
										
										
											2024-07-29 23:06:39 -07:00
										 |  |  |             owners=EntityReferenceList( | 
					
						
							|  |  |  |                 root=[ | 
					
						
							|  |  |  |                     EntityReference( | 
					
						
							|  |  |  |                         id=cls.user_1.id, | 
					
						
							|  |  |  |                         type="user", | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 ], | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.create_glossary_term_2 = CreateGlossaryTermRequest( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             glossary=FullyQualifiedEntityName(cls.create_glossary.name.root), | 
					
						
							|  |  |  |             name=EntityName("GT2"), | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             displayName="Glossary Term 2", | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             description=Markdown("Test glossary term 2"), | 
					
						
							|  |  |  |             synonyms=[ | 
					
						
							|  |  |  |                 EntityName("GT2S1"), | 
					
						
							|  |  |  |                 EntityName("GT2S2"), | 
					
						
							|  |  |  |                 EntityName("GT2S3"), | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2024-07-29 23:06:39 -07:00
										 |  |  |             owners=EntityReferenceList( | 
					
						
							|  |  |  |                 root=[ | 
					
						
							|  |  |  |                     EntityReference( | 
					
						
							|  |  |  |                         id=cls.user_1.id, | 
					
						
							|  |  |  |                         type="user", | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 ], | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.create_glossary_term_3 = CreateGlossaryTermRequest( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             glossary=FullyQualifiedEntityName(cls.create_glossary.name.root), | 
					
						
							|  |  |  |             name=EntityName("GT3"), | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             displayName="Glossary Term 3", | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             description=Markdown("Test glossary term 3"), | 
					
						
							|  |  |  |             synonyms=[ | 
					
						
							|  |  |  |                 EntityName("GT2S1"), | 
					
						
							|  |  |  |                 EntityName("GT2S2"), | 
					
						
							|  |  |  |                 EntityName("GT2S3"), | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2024-07-29 23:06:39 -07:00
										 |  |  |             owners=EntityReferenceList( | 
					
						
							|  |  |  |                 root=[ | 
					
						
							|  |  |  |                     EntityReference( | 
					
						
							|  |  |  |                         id=cls.user_1.id, | 
					
						
							|  |  |  |                         type="user", | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 ], | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Leave some time for indexes to get updated, otherwise this happens too fast | 
					
						
							|  |  |  |         cls.check_es_index() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def tearDownClass(cls) -> None: | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Clean up | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.metadata.delete( | 
					
						
							|  |  |  |             entity=User, | 
					
						
							|  |  |  |             entity_id=cls.user_1.id, | 
					
						
							|  |  |  |             recursive=True, | 
					
						
							|  |  |  |             hard_delete=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.metadata.delete( | 
					
						
							|  |  |  |             entity=User, | 
					
						
							|  |  |  |             entity_id=cls.user_2.id, | 
					
						
							|  |  |  |             hard_delete=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cls.metadata.delete( | 
					
						
							|  |  |  |             entity=User, | 
					
						
							|  |  |  |             entity_id=cls.user_3.id, | 
					
						
							|  |  |  |             hard_delete=True, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if cls.glossary_term_3 is not None: | 
					
						
							|  |  |  |             cls.metadata.delete( | 
					
						
							|  |  |  |                 entity=GlossaryTerm, | 
					
						
							|  |  |  |                 entity_id=cls.glossary_term_3.id, | 
					
						
							|  |  |  |                 hard_delete=True, | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if cls.glossary_term_2 is not None: | 
					
						
							|  |  |  |             cls.metadata.delete( | 
					
						
							|  |  |  |                 entity=GlossaryTerm, | 
					
						
							|  |  |  |                 entity_id=cls.glossary_term_2.id, | 
					
						
							|  |  |  |                 hard_delete=True, | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if cls.glossary_term_1 is not None: | 
					
						
							|  |  |  |             cls.metadata.delete( | 
					
						
							|  |  |  |                 entity=GlossaryTerm, | 
					
						
							|  |  |  |                 entity_id=cls.glossary_term_1.id, | 
					
						
							|  |  |  |                 hard_delete=True, | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # glossary: Glossary = cls.metadata.get_by_name( | 
					
						
							|  |  |  |         #     entity=Glossary, | 
					
						
							|  |  |  |         #     fqn=model_str(cls.create_glossary.name), | 
					
						
							|  |  |  |         # ) | 
					
						
							|  |  |  |         if cls.glossary_entity_id is not None: | 
					
						
							|  |  |  |             cls.metadata.delete( | 
					
						
							|  |  |  |                 entity=Glossary, | 
					
						
							|  |  |  |                 entity_id=cls.glossary_entity_id, | 
					
						
							|  |  |  |                 hard_delete=True, | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_create_glossary(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Create a Glossary | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         self.glossary = self.metadata.create_or_update(self.create_glossary) | 
					
						
							|  |  |  |         self.assertIsNotNone(self.glossary) | 
					
						
							|  |  |  |         self.assertEqual(self.create_glossary.name, self.glossary.name) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         if self.glossary_entity_id is None: | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |             self.glossary_entity_id = self.glossary.id | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_create_glossary_term(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Test the creation of a glossary term | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if OMetaGlossaryTest.glossary_entity_id is None: | 
					
						
							|  |  |  |             glossary: Glossary = self.metadata.create_or_update(self.create_glossary) | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_entity_id = glossary.id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Create without parent | 
					
						
							|  |  |  |         res: GlossaryTerm = self.metadata.create_or_update(self.create_glossary_term_1) | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							|  |  |  |         self.assertEqual(self.create_glossary_term_1.name, res.name) | 
					
						
							|  |  |  |         self.assertEqual( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             f"{self.create_glossary.name.root}.{res.name.root}", | 
					
						
							|  |  |  |             res.fullyQualifiedName.root, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Create with parent | 
					
						
							|  |  |  |         if OMetaGlossaryTest.glossary_term_1 is None: | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_1 = res | 
					
						
							|  |  |  |         self.create_glossary_term_2.parent = self.glossary_term_1.fullyQualifiedName | 
					
						
							|  |  |  |         res = self.metadata.create_or_update(self.create_glossary_term_2) | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							|  |  |  |         self.assertEqual(self.create_glossary_term_2.name, res.name) | 
					
						
							|  |  |  |         self.assertEqual(model_str(self.create_glossary_term_1.name), res.parent.name) | 
					
						
							|  |  |  |         if OMetaGlossaryTest.glossary_term_2 is None: | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_2 = res | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_patch_glossary_term_parent(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Update parent via PATCH | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         if OMetaGlossaryTest.glossary_entity_id is None: | 
					
						
							|  |  |  |             glossary: Glossary = self.metadata.create_or_update(self.create_glossary) | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_entity_id = glossary.id | 
					
						
							|  |  |  |         if self.glossary_term_1 is None: | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_1 = self.metadata.create_or_update( | 
					
						
							|  |  |  |                 self.create_glossary_term_1 | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         if self.glossary_term_2 is None: | 
					
						
							|  |  |  |             self.create_glossary_term_2.parent = self.glossary_term_1.fullyQualifiedName | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_2 = self.metadata.create_or_update( | 
					
						
							|  |  |  |                 self.create_glossary_term_2 | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         if self.glossary_term_3 is None: | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_3 = self.metadata.create_or_update( | 
					
						
							|  |  |  |                 self.create_glossary_term_3 | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_3 = deepcopy(self.glossary_term_3) | 
					
						
							|  |  |  |         dest_glossary_term_3.parent = EntityReference( | 
					
						
							|  |  |  |             id=self.glossary_term_2.id, type="glossaryTerm" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         # Add parent | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         res: GlossaryTerm = self.metadata.patch( | 
					
						
							|  |  |  |             entity=GlossaryTerm, | 
					
						
							|  |  |  |             source=self.glossary_term_3, | 
					
						
							|  |  |  |             destination=dest_glossary_term_3, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							|  |  |  |         self.assertEqual(self.glossary_term_2.id, res.parent.id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Move parent | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_3.parent = EntityReference( | 
					
						
							|  |  |  |             id=self.glossary_term_1.id, type="glossaryTerm" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         res: GlossaryTerm = self.metadata.patch( | 
					
						
							|  |  |  |             entity=GlossaryTerm, | 
					
						
							|  |  |  |             source=self.glossary_term_3, | 
					
						
							|  |  |  |             destination=dest_glossary_term_3, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         self.assertIsNotNone(res) | 
					
						
							|  |  |  |         self.assertEqual(self.glossary_term_1.id, res.parent.id) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_3 = deepcopy(res) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         # Delete parent | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_3.parent = None | 
					
						
							|  |  |  |         res: GlossaryTerm = self.metadata.patch( | 
					
						
							|  |  |  |             entity=GlossaryTerm, | 
					
						
							|  |  |  |             source=res, | 
					
						
							|  |  |  |             destination=dest_glossary_term_3, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							|  |  |  |         self.assertIsNone(res.parent) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_patch_glossary_term_related_terms(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Update related terms via PATCH | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         if OMetaGlossaryTest.glossary_entity_id is None: | 
					
						
							|  |  |  |             glossary: Glossary = self.metadata.create_or_update(self.create_glossary) | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_entity_id = glossary.id | 
					
						
							|  |  |  |         if self.glossary_term_1 is None: | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_1 = self.metadata.create_or_update( | 
					
						
							|  |  |  |                 self.create_glossary_term_1 | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         if self.glossary_term_2 is None: | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_2 = self.metadata.create_or_update( | 
					
						
							|  |  |  |                 self.create_glossary_term_2 | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         elif self.glossary_term_2.parent is not None: | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |             dest_glossary_term_2 = deepcopy(self.glossary_term_2) | 
					
						
							|  |  |  |             dest_glossary_term_2.parent = EntityReference( | 
					
						
							|  |  |  |                 id=self.glossary_term_1.id, type="glossaryTerm" | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             self.metadata.patch( | 
					
						
							|  |  |  |                 entity=GlossaryTerm, | 
					
						
							|  |  |  |                 source=self.glossary_term_2, | 
					
						
							|  |  |  |                 destination=dest_glossary_term_2, | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         if self.glossary_term_3 is None: | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_3 = self.metadata.create_or_update( | 
					
						
							|  |  |  |                 self.create_glossary_term_3 | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         elif self.glossary_term_3.parent is not None: | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |             dest_glossary_term_3 = deepcopy(self.glossary_term_3) | 
					
						
							|  |  |  |             dest_glossary_term_3.parent = None | 
					
						
							|  |  |  |             self.metadata.patch( | 
					
						
							|  |  |  |                 entity=GlossaryTerm, | 
					
						
							|  |  |  |                 source=self.glossary_term_3, | 
					
						
							|  |  |  |                 destination=dest_glossary_term_3, | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Add related term | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1 = deepcopy(self.glossary_term_1) | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         dest_glossary_term_1.relatedTerms = None | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         if dest_glossary_term_1.relatedTerms is not None: | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |             dest_glossary_term_1.relatedTerms = None | 
					
						
							|  |  |  |         dest_glossary_term_1.relatedTerms = EntityReferenceList( | 
					
						
							|  |  |  |             root=[EntityReference(id=self.glossary_term_2.id, type="glossaryTerm")] | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         ) | 
					
						
							|  |  |  |         res: GlossaryTerm = self.metadata.patch( | 
					
						
							|  |  |  |             entity=GlossaryTerm, | 
					
						
							|  |  |  |             source=self.glossary_term_1, | 
					
						
							|  |  |  |             destination=dest_glossary_term_1, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         self.assertEqual(1, len(res.relatedTerms.root)) | 
					
						
							|  |  |  |         self.assertEqual(self.glossary_term_2.id, res.relatedTerms.root[0].id) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_patch_reviewer(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Update reviewers via PATCH | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         if OMetaGlossaryTest.glossary is None: | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             glossary: Glossary = self.metadata.create_or_update(self.create_glossary) | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_entity_id = glossary.id | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |             self.glossary = glossary | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         if self.glossary_term_1 is None: | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_1 = self.metadata.create_or_update( | 
					
						
							|  |  |  |                 self.create_glossary_term_1 | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         # Add Glossary Reviewer | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary = deepcopy(self.glossary) | 
					
						
							|  |  |  |         if dest_glossary.reviewers is None: | 
					
						
							|  |  |  |             dest_glossary.reviewers = [] | 
					
						
							|  |  |  |         dest_glossary.reviewers.append(EntityReference(id=self.user_1.id, type="user")) | 
					
						
							|  |  |  |         res_glossary: Glossary = self.metadata.patch( | 
					
						
							|  |  |  |             entity=Glossary, source=self.glossary, destination=dest_glossary | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         self.assertIsNotNone(res_glossary) | 
					
						
							|  |  |  |         self.assertEqual(1, len(res_glossary.reviewers)) | 
					
						
							|  |  |  |         self.assertEqual(self.user_1.id, res_glossary.reviewers[0].id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Remove only Glossary reviewer | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary = deepcopy(res_glossary) | 
					
						
							|  |  |  |         dest_glossary.reviewers.pop(0) | 
					
						
							|  |  |  |         res_glossary: Glossary = self.metadata.patch( | 
					
						
							|  |  |  |             entity=Glossary, source=res_glossary, destination=dest_glossary | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         self.assertIsNotNone(res_glossary) | 
					
						
							|  |  |  |         self.assertEqual(0, len(res_glossary.reviewers)) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary = deepcopy(res_glossary) | 
					
						
							|  |  |  |         dest_glossary.reviewers.append(EntityReference(id=self.user_1.id, type="user")) | 
					
						
							|  |  |  |         dest_glossary.reviewers.append(EntityReference(id=self.user_2.id, type="user")) | 
					
						
							|  |  |  |         dest_glossary.reviewers.append(EntityReference(id=self.user_3.id, type="user")) | 
					
						
							|  |  |  |         res_glossary: Glossary = self.metadata.patch( | 
					
						
							|  |  |  |             entity=Glossary, source=res_glossary, destination=dest_glossary | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-07-05 08:53:20 +02:00
										 |  |  |         # Remove one Glossary reviewer when there are many | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         # delete self.user_3 | 
					
						
							|  |  |  |         dest_glossary = deepcopy(res_glossary) | 
					
						
							|  |  |  |         dest_glossary.reviewers.pop(2) | 
					
						
							|  |  |  |         res_glossary: Glossary = self.metadata.patch( | 
					
						
							|  |  |  |             entity=Glossary, source=res_glossary, destination=dest_glossary | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         self.assertIsNotNone(res_glossary) | 
					
						
							|  |  |  |         self.assertEqual(2, len(res_glossary.reviewers)) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         self.assertEqual(self.user_1.id, res_glossary.reviewers[0].id) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         self.assertEqual(self.user_2.id, res_glossary.reviewers[1].id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Add GlossaryTerm Reviewer | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1 = deepcopy(self.glossary_term_1) | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         dest_glossary_term_1.reviewers.root.append( | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |             EntityReference(id=self.user_1.id, type="user") | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         res_glossary_term: GlossaryTerm = self.metadata.patch( | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             entity=GlossaryTerm, | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |             source=self.glossary_term_1, | 
					
						
							|  |  |  |             destination=dest_glossary_term_1, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         self.assertIsNotNone(res_glossary_term) | 
					
						
							| 
									
										
										
										
											2024-06-06 20:23:37 +05:30
										 |  |  |         self.assertEqual(2, len(res_glossary_term.reviewers.root)) | 
					
						
							| 
									
										
										
										
											2024-08-02 10:16:14 +05:30
										 |  |  |         self.assertTrue( | 
					
						
							|  |  |  |             any( | 
					
						
							|  |  |  |                 reviewer.id == self.user_1.id | 
					
						
							|  |  |  |                 for reviewer in res_glossary_term.reviewers.root | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1 = deepcopy(res_glossary_term) | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         dest_glossary_term_1.reviewers.root.pop(0) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         res_glossary_term = self.metadata.patch( | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |             entity=GlossaryTerm, | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |             source=res_glossary_term, | 
					
						
							|  |  |  |             destination=dest_glossary_term_1, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-07-05 08:53:20 +02:00
										 |  |  |         self.assertIsNotNone(res_glossary_term) | 
					
						
							| 
									
										
										
										
											2024-06-06 20:23:37 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |         # inherited reviewers from glossary | 
					
						
							|  |  |  |         self.assertEqual(2, len(res_glossary_term.reviewers.root)) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_patch_glossary_term_synonyms(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Update synonyms via PATCH | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         if OMetaGlossaryTest.glossary_entity_id is None: | 
					
						
							|  |  |  |             glossary: Glossary = self.metadata.create_or_update(self.create_glossary) | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_entity_id = glossary.id | 
					
						
							|  |  |  |         if self.glossary_term_1 is None: | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_1 = self.metadata.create_or_update( | 
					
						
							|  |  |  |                 self.create_glossary_term_1 | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1 = deepcopy(self.glossary_term_1) | 
					
						
							|  |  |  |         if dest_glossary_term_1.synonyms is None: | 
					
						
							|  |  |  |             dest_glossary_term_1.synonyms = list() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if dest_glossary_term_1.synonyms is None: | 
					
						
							|  |  |  |             dest_glossary_term_1.synonyms = [] | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         dest_glossary_term_1.synonyms.append(EntityName("GT1S1")) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Add GlossaryTerm synonym | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         res: GlossaryTerm = self.metadata.patch( | 
					
						
							|  |  |  |             entity=GlossaryTerm, | 
					
						
							|  |  |  |             source=self.glossary_term_1, | 
					
						
							|  |  |  |             destination=dest_glossary_term_1, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							|  |  |  |         self.assertEqual(1, len(res.synonyms)) | 
					
						
							|  |  |  |         self.assertEqual("GT1S1", model_str(res.synonyms[0])) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         self.glossary_term_1 = self.metadata.get_by_id( | 
					
						
							|  |  |  |             entity=GlossaryTerm, entity_id=self.glossary_term_1.id, fields=["*"] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         dest_glossary_term_1 = deepcopy(res) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         # Remove GlossaryTerm synonym | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1.synonyms.pop(0) | 
					
						
							|  |  |  |         res = self.metadata.patch( | 
					
						
							|  |  |  |             entity=GlossaryTerm, | 
					
						
							|  |  |  |             source=res, | 
					
						
							|  |  |  |             destination=dest_glossary_term_1, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							|  |  |  |         self.assertEqual(0, len(res.synonyms)) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1 = deepcopy(res) | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |         dest_glossary_term_1.synonyms.append(EntityName("GT1S1")) | 
					
						
							|  |  |  |         dest_glossary_term_1.synonyms.append(EntityName("GT1S2")) | 
					
						
							|  |  |  |         dest_glossary_term_1.synonyms.append(EntityName("GT1S3")) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         res: GlossaryTerm = self.metadata.patch( | 
					
						
							|  |  |  |             entity=GlossaryTerm, | 
					
						
							|  |  |  |             source=res, | 
					
						
							|  |  |  |             destination=dest_glossary_term_1, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         self.assertEqual(3, len(res.synonyms)) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         self.assertEqual("GT1S2", model_str(res.synonyms[1])) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_patch_glossary_term_references(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Update GlossaryTerm references via PATCH | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if OMetaGlossaryTest.glossary_entity_id is None: | 
					
						
							|  |  |  |             glossary: Glossary = self.metadata.create_or_update(self.create_glossary) | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_entity_id = glossary.id | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |             self.glossary = glossary | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         if self.glossary_term_1 is None: | 
					
						
							|  |  |  |             OMetaGlossaryTest.glossary_term_1 = self.metadata.create_or_update( | 
					
						
							|  |  |  |                 self.create_glossary_term_1 | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1 = deepcopy(self.glossary_term_1) | 
					
						
							|  |  |  |         if dest_glossary_term_1.references is None: | 
					
						
							|  |  |  |             dest_glossary_term_1.references = [] | 
					
						
							|  |  |  |         dest_glossary_term_1.references.append( | 
					
						
							|  |  |  |             TermReference(name="GT1S1", endpoint="https://www.getcollate.io") | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         # Add reference | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         res: GlossaryTerm = self.metadata.patch( | 
					
						
							|  |  |  |             entity=GlossaryTerm, | 
					
						
							|  |  |  |             source=self.glossary_term_1, | 
					
						
							|  |  |  |             destination=dest_glossary_term_1, | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							|  |  |  |         self.assertEqual(1, len(res.references)) | 
					
						
							|  |  |  |         self.assertEqual("GT1S1", res.references[0].name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Remove reference | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1_noref = deepcopy(res) | 
					
						
							|  |  |  |         dest_glossary_term_1_noref.references = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.metadata.patch( | 
					
						
							|  |  |  |             entity=GlossaryTerm, source=res, destination=dest_glossary_term_1_noref | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         res: GlossaryTerm = self.metadata.get_by_name( | 
					
						
							|  |  |  |             entity=GlossaryTerm, | 
					
						
							|  |  |  |             fqn=fqn._build( | 
					
						
							| 
									
										
										
										
											2024-06-05 21:18:37 +02:00
										 |  |  |                 self.create_glossary.name.root, | 
					
						
							|  |  |  |                 self.create_glossary_term_1.name.root, | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |             ), | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							|  |  |  |         self.assertEqual(0, len(res.references)) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Remove reference when there are many | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1 = deepcopy(res) | 
					
						
							|  |  |  |         dest_glossary_term_1.references.append( | 
					
						
							|  |  |  |             TermReference(name="GT1S1", endpoint="https://www.getcollate.io") | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1.references.append( | 
					
						
							|  |  |  |             TermReference(name="GT1S2", endpoint="https://open-metadata.org/") | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         dest_glossary_term_1.references.append( | 
					
						
							|  |  |  |             TermReference( | 
					
						
							|  |  |  |                 name="GT1S3", endpoint="https://github.com/open-metadata/OpenMetadata" | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         res: GlossaryTerm = self.metadata.patch( | 
					
						
							|  |  |  |             entity=GlossaryTerm, source=res, destination=dest_glossary_term_1 | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         self.assertIsNotNone(res) | 
					
						
							| 
									
										
										
										
											2023-11-16 18:14:27 -08:00
										 |  |  |         self.assertEqual(3, len(res.references)) | 
					
						
							| 
									
										
										
										
											2023-03-31 07:55:22 -07:00
										 |  |  |         self.assertEqual("GT1S2", res.references[1].name) |