1313See the License for the specific language governing permissions and
1414limitations under the License.
1515"""
16- import logging
1716import os
1817import uuid
1918
2019import pymysql
2120import pytest
2221import sqlalchemy
23- from google .cloud .sql .connector import connector , IPTypes
22+ from google .cloud .sql .connector import Connector , IPTypes
2423
2524table_name = f"books_{ uuid .uuid4 ().hex } "
2625
2726
28- def init_connection_engine (ip_type : IPTypes ) -> sqlalchemy .engine .Engine :
27+ def init_connection_engine (
28+ connector : Connector , ip_type : IPTypes
29+ ) -> sqlalchemy .engine .Engine :
2930 def getconn () -> pymysql .connections .Connection :
3031 conn : pymysql .connections .Connection = connector .connect (
3132 os .environ ["MYSQL_CONNECTION_NAME" ],
@@ -45,19 +46,15 @@ def getconn() -> pymysql.connections.Connection:
4546
4647
4748def test_public_ip () -> None :
48- try :
49- pool = init_connection_engine (IPTypes .PUBLIC )
50- except Exception as e :
51- logging .exception ("Failed to initialize pool with public IP" , e )
52- with pool .connect () as conn :
53- conn .execute ("SELECT 1" )
49+ with Connector () as connector :
50+ pool = init_connection_engine (connector , IPTypes .PUBLIC )
51+ with pool .connect () as conn :
52+ conn .execute ("SELECT 1" )
5453
5554
5655@pytest .mark .private_ip
5756def test_private_ip () -> None :
58- try :
59- pool = init_connection_engine (IPTypes .PRIVATE )
60- except Exception as e :
61- logging .exception ("Failed to initialize pool with private IP" , e )
62- with pool .connect () as conn :
63- conn .execute ("SELECT 1" )
57+ with Connector () as connector :
58+ pool = init_connection_engine (connector , IPTypes .PRIVATE )
59+ with pool .connect () as conn :
60+ conn .execute ("SELECT 1" )
0 commit comments