| 
									
										
										
										
											2025-04-03 10:39:47 +05:30
										 |  |  | #  Copyright 2025 Collate | 
					
						
							|  |  |  | #  Licensed under the Collate Community License, Version 1.0 (the "License"); | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +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 | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +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. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | MySQL connection test | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2024-09-17 11:57:32 +02:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-17 11:57:32 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +01:00
										 |  |  | from sqlalchemy.engine import Engine | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-16 13:18:12 +05:30
										 |  |  | from metadata.generated.schema.entity.services.connections.database.common.basicAuth import ( | 
					
						
							|  |  |  |     BasicAuth, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +01:00
										 |  |  | from metadata.generated.schema.entity.services.connections.database.mysqlConnection import ( | 
					
						
							|  |  |  |     MysqlConnection, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | from metadata.ingestion.source.connections import get_connection, get_test_connection_fn | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-17 11:57:32 +02:00
										 |  |  | if sys.version_info < (3, 9): | 
					
						
							|  |  |  |     pytest.skip("requires python 3.9+", allow_module_level=True) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-17 11:57:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | def test_test_connection(metadata, mysql_container): | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +01:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-09-17 11:57:32 +02:00
										 |  |  |     Test connection function requires: | 
					
						
							|  |  |  |     - ometa | 
					
						
							|  |  |  |     - connection object, i.e., the engine | 
					
						
							|  |  |  |     - the service connection | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +01:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2023-12-22 15:43:50 +01:00
										 |  |  |     service_connection = MysqlConnection( | 
					
						
							| 
									
										
										
										
											2024-09-17 11:57:32 +02:00
										 |  |  |         username=mysql_container.username, | 
					
						
							|  |  |  |         authType=BasicAuth(password=mysql_container.password), | 
					
						
							|  |  |  |         hostPort=f"localhost:{mysql_container.get_exposed_port(3306)}", | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-17 11:57:32 +02:00
										 |  |  |     engine = get_connection(service_connection) | 
					
						
							|  |  |  |     assert isinstance(engine, Engine) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:52:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-17 11:57:32 +02:00
										 |  |  |     _test_connection_fn = get_test_connection_fn(service_connection) | 
					
						
							| 
									
										
										
										
											2025-06-13 14:52:29 +02:00
										 |  |  |     _test_connection_fn(metadata) |