| 
									
										
										
										
											2025-04-03 10:39:47 +05:30
										 |  |  | #  Copyright 2025 Collate | 
					
						
							|  |  |  | #  Licensed under the Collate Community License, Version 1.0 (the "License"); | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  | #  you may not use this file except in compliance with the License. | 
					
						
							|  |  |  | #  You may obtain a copy of the License at | 
					
						
							| 
									
										
										
										
											2025-04-03 10:39:47 +05:30
										 |  |  | #  https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  | #  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. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | Test import utilities | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | from unittest import TestCase | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from metadata.generated.schema.entity.services.serviceType import ServiceType | 
					
						
							|  |  |  | from metadata.utils.importer import ( | 
					
						
							| 
									
										
										
										
											2022-12-27 15:00:22 +01:00
										 |  |  |     get_class_name_root, | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  |     get_module_name, | 
					
						
							| 
									
										
										
										
											2022-12-27 15:00:22 +01:00
										 |  |  |     get_source_module_name, | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  |     import_bulk_sink_type, | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +01:00
										 |  |  |     import_from_module, | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  |     import_processor_class, | 
					
						
							|  |  |  |     import_sink_class, | 
					
						
							|  |  |  |     import_stage_class, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2024-10-24 07:47:50 +02:00
										 |  |  | from metadata.utils.service_spec.service_spec import import_source_class | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # pylint: disable=import-outside-toplevel | 
					
						
							|  |  |  | class ImporterTest(TestCase): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Validate that we properly convert | 
					
						
							|  |  |  |     module paths and load classes. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_get_module_name(self) -> None: | 
					
						
							| 
									
										
										
										
											2022-12-27 15:00:22 +01:00
										 |  |  |         self.assertEqual(get_source_module_name("mysql"), "metadata") | 
					
						
							|  |  |  |         self.assertEqual(get_source_module_name("redshift-usage"), "usage") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual(get_module_name("query-parser"), "query_parser") | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_get_class_name(self) -> None: | 
					
						
							| 
									
										
										
										
											2022-12-27 15:00:22 +01:00
										 |  |  |         self.assertEqual(get_class_name_root("mysql"), "Mysql") | 
					
						
							|  |  |  |         self.assertEqual(get_class_name_root("redshift-usage"), "RedshiftUsage") | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_import_class(self) -> None: | 
					
						
							| 
									
										
										
										
											2022-12-27 15:00:22 +01:00
										 |  |  |         from metadata.ingestion.source.database.mysql.metadata import MysqlSource | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual( | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +01:00
										 |  |  |             import_from_module( | 
					
						
							| 
									
										
										
										
											2022-12-27 15:00:22 +01:00
										 |  |  |                 "metadata.ingestion.source.database.mysql.metadata.MysqlSource" | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  |             MysqlSource, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_import_source_class(self) -> None: | 
					
						
							| 
									
										
										
										
											2022-12-27 15:00:22 +01:00
										 |  |  |         from metadata.ingestion.source.database.mysql.metadata import MysqlSource | 
					
						
							| 
									
										
										
										
											2022-12-23 12:17:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual( | 
					
						
							|  |  |  |             import_source_class(service_type=ServiceType.Database, source_type="mysql"), | 
					
						
							|  |  |  |             MysqlSource, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_import_processor_class(self) -> None: | 
					
						
							|  |  |  |         from metadata.ingestion.processor.query_parser import QueryParserProcessor | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual( | 
					
						
							|  |  |  |             import_processor_class(processor_type="query-parser"), | 
					
						
							|  |  |  |             QueryParserProcessor, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_import_stage_class(self) -> None: | 
					
						
							|  |  |  |         from metadata.ingestion.stage.table_usage import TableUsageStage | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual(import_stage_class(stage_type="table-usage"), TableUsageStage) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_import_sink_class(self) -> None: | 
					
						
							|  |  |  |         from metadata.ingestion.sink.metadata_rest import MetadataRestSink | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual(import_sink_class(sink_type="metadata-rest"), MetadataRestSink) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_import_bulk_sink_type(self) -> None: | 
					
						
							|  |  |  |         from metadata.ingestion.bulksink.metadata_usage import MetadataUsageBulkSink | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual( | 
					
						
							|  |  |  |             import_bulk_sink_type(bulk_sink_type="metadata-usage"), | 
					
						
							|  |  |  |             MetadataUsageBulkSink, | 
					
						
							|  |  |  |         ) |