| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  | #  Copyright 2022 Collate | 
					
						
							| 
									
										
										
										
											2025-04-03 10:39:47 +05:30
										 |  |  | #  Licensed under the Collate Community License, Version 1.0 (the "License"); | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  | #  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 | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  | #  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 Redshift connector with CLI | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | from pathlib import Path | 
					
						
							|  |  |  | from typing import List | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 14:59:49 +05:30
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  | from sqlalchemy.engine import Engine | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-30 15:49:42 +02:00
										 |  |  | from metadata.ingestion.api.status import Status | 
					
						
							|  |  |  | from metadata.workflow.metadata import MetadataWorkflow | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-14 15:58:31 +02:00
										 |  |  | from .base.test_cli import PATH_TO_RESOURCES | 
					
						
							|  |  |  | from .base.test_cli_dbt import CliDBTBase | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DbtCliTest(CliDBTBase.TestSuite): | 
					
						
							|  |  |  |     engine: Engine | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def setUpClass(cls) -> None: | 
					
						
							|  |  |  |         connector = cls.get_connector_name() | 
					
						
							| 
									
										
										
										
											2023-08-30 15:49:42 +02:00
										 |  |  |         workflow: MetadataWorkflow = cls.get_workflow( | 
					
						
							| 
									
										
										
										
											2023-04-14 15:58:31 +02:00
										 |  |  |             test_type=cls.get_test_type(), connector=connector | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  |         cls.engine = workflow.source.engine | 
					
						
							|  |  |  |         cls.openmetadata = workflow.source.metadata | 
					
						
							|  |  |  |         cls.config_file_path = str( | 
					
						
							|  |  |  |             Path(PATH_TO_RESOURCES + f"/dbt/{connector}/{connector}.yaml") | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         cls.dbt_file_path = str(Path(PATH_TO_RESOURCES + f"/dbt/{connector}/dbt.yaml")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def tearDown(self) -> None: | 
					
						
							|  |  |  |         self.engine.dispose() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @staticmethod | 
					
						
							|  |  |  |     def get_connector_name() -> str: | 
					
						
							|  |  |  |         return "redshift" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @staticmethod | 
					
						
							|  |  |  |     def expected_tables() -> int: | 
					
						
							|  |  |  |         return 9 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @staticmethod | 
					
						
							|  |  |  |     def expected_records() -> int: | 
					
						
							|  |  |  |         return 72 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @staticmethod | 
					
						
							|  |  |  |     def fqn_dbt_tables() -> List[str]: | 
					
						
							|  |  |  |         return [ | 
					
						
							| 
									
										
										
										
											2023-07-04 15:46:09 +05:30
										 |  |  |             "local_redshift.dev.dbt_cli_e2e.customers", | 
					
						
							|  |  |  |             "local_redshift.dev.dbt_cli_e2e.orders", | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 14:59:49 +05:30
										 |  |  |     @pytest.mark.order(11) | 
					
						
							|  |  |  |     def test_lineage(self) -> None: | 
					
						
							|  |  |  |         pytest.skip("Lineage not configured. Skipping Test") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  |     def assert_for_vanilla_ingestion( | 
					
						
							| 
									
										
										
										
											2023-08-30 15:49:42 +02:00
										 |  |  |         self, source_status: Status, sink_status: Status | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  |     ) -> None: | 
					
						
							|  |  |  |         self.assertTrue(len(source_status.failures) == 0) | 
					
						
							|  |  |  |         self.assertTrue(len(source_status.warnings) == 0) | 
					
						
							| 
									
										
										
										
											2023-12-12 22:32:13 +05:30
										 |  |  |         self.assertTrue(len(source_status.filtered) >= 10) | 
					
						
							| 
									
										
										
										
											2024-01-16 17:53:05 +05:30
										 |  |  |         self.assertTrue( | 
					
						
							|  |  |  |             (len(source_status.records) + len(source_status.updated_records)) | 
					
						
							|  |  |  |             >= self.expected_tables() | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  |         self.assertTrue(len(sink_status.failures) == 0) | 
					
						
							|  |  |  |         self.assertTrue(len(sink_status.warnings) == 0) | 
					
						
							| 
									
										
										
										
											2024-01-16 17:53:05 +05:30
										 |  |  |         self.assertTrue( | 
					
						
							|  |  |  |             (len(sink_status.records) + len(sink_status.updated_records)) | 
					
						
							|  |  |  |             > self.expected_tables() | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     def assert_for_dbt_ingestion( | 
					
						
							| 
									
										
										
										
											2023-08-30 15:49:42 +02:00
										 |  |  |         self, source_status: Status, sink_status: Status | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  |     ) -> None: | 
					
						
							|  |  |  |         self.assertTrue(len(source_status.failures) == 0) | 
					
						
							|  |  |  |         self.assertTrue(len(source_status.warnings) == 0) | 
					
						
							|  |  |  |         self.assertTrue(len(source_status.filtered) == 0) | 
					
						
							| 
									
										
										
										
											2024-01-16 17:53:05 +05:30
										 |  |  |         self.assertTrue( | 
					
						
							|  |  |  |             (len(source_status.records) + len(source_status.updated_records)) >= 0 | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-01-18 18:59:16 +05:30
										 |  |  |         self.assertTrue(len(sink_status.failures) == 0) | 
					
						
							|  |  |  |         self.assertTrue(len(sink_status.warnings) == 0) | 
					
						
							| 
									
										
										
										
											2024-01-16 17:53:05 +05:30
										 |  |  |         self.assertTrue( | 
					
						
							|  |  |  |             (len(sink_status.records) + len(sink_status.updated_records)) | 
					
						
							|  |  |  |             >= self.expected_records() | 
					
						
							|  |  |  |         ) |