Skip to content

Commit b6a0d0b

Browse files
chore: update region tags in test samples (#396)
1 parent e172186 commit b6a0d0b

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

tests/system/test_connector_object.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def getconn() -> pymysql.connections.Connection:
3636
)
3737
return conn
3838

39-
engine = sqlalchemy.create_engine(
39+
pool = sqlalchemy.create_engine(
4040
"mysql+pymysql://",
4141
creator=getconn,
4242
)
43-
return engine
43+
return pool
4444

4545

4646
def test_connector_with_credentials() -> None:

tests/system/test_ip_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def getconn() -> pymysql.connections.Connection:
3838
)
3939
return conn
4040

41-
engine = sqlalchemy.create_engine(
41+
pool = sqlalchemy.create_engine(
4242
"mysql+pymysql://",
4343
creator=getconn,
4444
)
45-
return engine
45+
return pool
4646

4747

4848
def test_public_ip() -> None:

tests/system/test_pg8000_connection.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
import uuid
1818
from typing import Generator
1919

20-
import pg8000
2120
import pytest
21+
22+
# [START cloud_sql_connector_postgres_pg8000]
23+
import pg8000
2224
import sqlalchemy
2325
from google.cloud.sql.connector import Connector
2426

27+
# [END cloud_sql_connector_postgres_pg8000]
28+
2529
table_name = f"books_{uuid.uuid4().hex}"
2630

2731

@@ -30,6 +34,7 @@
3034
# 'creator' argument to 'create_engine'
3135
def init_connection_engine() -> sqlalchemy.engine.Engine:
3236
def getconn() -> pg8000.dbapi.Connection:
37+
# initialize Connector object for connections to Cloud SQL
3338
with Connector() as connector:
3439
conn: pg8000.dbapi.Connection = connector.connect(
3540
os.environ["POSTGRES_CONNECTION_NAME"],
@@ -40,12 +45,13 @@ def getconn() -> pg8000.dbapi.Connection:
4045
)
4146
return conn
4247

43-
engine = sqlalchemy.create_engine(
48+
# create SQLAlchemy connection pool
49+
pool = sqlalchemy.create_engine(
4450
"postgresql+pg8000://",
4551
creator=getconn,
4652
)
47-
engine.dialect.description_encoding = None
48-
return engine
53+
pool.dialect.description_encoding = None
54+
return pool
4955

5056

5157
# [END cloud_sql_connector_postgres_pg8000]

tests/system/test_pg8000_iam_auth.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@
1717
import uuid
1818
from typing import Generator
1919

20-
import pg8000
20+
# [START cloud_sql_connector_postgres_pg8000_iam_auth]
2121
import pytest
22+
import pg8000
2223
import sqlalchemy
2324
from google.cloud.sql.connector import Connector
2425

26+
# [END cloud_sql_connector_postgres_pg8000_iam_auth]
27+
2528
table_name = f"books_{uuid.uuid4().hex}"
2629

2730

2831
# [START cloud_sql_connector_postgres_pg8000_iam_auth]
2932
# The Cloud SQL Python Connector can be used along with SQLAlchemy using the
3033
# 'creator' argument to 'create_engine'
3134
def init_connection_engine() -> sqlalchemy.engine.Engine:
35+
# initialize Connector object for connections to Cloud SQL
3236
def getconn() -> pg8000.dbapi.Connection:
3337
with Connector() as connector:
3438
conn: pg8000.dbapi.Connection = connector.connect(
@@ -40,12 +44,13 @@ def getconn() -> pg8000.dbapi.Connection:
4044
)
4145
return conn
4246

43-
engine = sqlalchemy.create_engine(
47+
# create SQLAlchemy connection pool
48+
pool = sqlalchemy.create_engine(
4449
"postgresql+pg8000://",
4550
creator=getconn,
4651
)
47-
engine.dialect.description_encoding = None
48-
return engine
52+
pool.dialect.description_encoding = None
53+
return pool
4954

5055

5156
# [END cloud_sql_connector_postgres_pg8000_iam_auth]

tests/system/test_pymysql_connection.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
import uuid
1818
from typing import Generator
1919

20-
import pymysql
2120
import pytest
21+
22+
# [START cloud_sql_connector_mysql_pymysql]
23+
import pymysql
2224
import sqlalchemy
2325
from google.cloud.sql.connector import Connector
2426

27+
# [END cloud_sql_connector_mysql_pymysql]
28+
2529
table_name = f"books_{uuid.uuid4().hex}"
2630

2731

@@ -30,6 +34,7 @@
3034
# 'creator' argument to 'create_engine'
3135
def init_connection_engine() -> sqlalchemy.engine.Engine:
3236
def getconn() -> pymysql.connections.Connection:
37+
# initialize Connector object for connections to Cloud SQL
3338
with Connector() as connector:
3439
conn: pymysql.connections.Connection = connector.connect(
3540
os.environ["MYSQL_CONNECTION_NAME"],
@@ -40,11 +45,12 @@ def getconn() -> pymysql.connections.Connection:
4045
)
4146
return conn
4247

43-
engine = sqlalchemy.create_engine(
48+
# create SQLAlchemy connection pool
49+
pool = sqlalchemy.create_engine(
4450
"mysql+pymysql://",
4551
creator=getconn,
4652
)
47-
return engine
53+
return pool
4854

4955

5056
# [END cloud_sql_connector_mysql_pymysql]

tests/system/test_pytds_connection.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
import uuid
1818
from typing import Generator
1919

20-
import pytds
2120
import pytest
21+
22+
# [START cloud_sql_connector_mysql_pytds]
23+
import pytds
2224
import sqlalchemy
2325
from google.cloud.sql.connector import Connector
2426

27+
# [END cloud_sql_connector_mysql_pytds]
28+
2529
table_name = f"books_{uuid.uuid4().hex}"
2630

2731

@@ -31,6 +35,7 @@
3135
# 'sqlalchemy-pytds` in your dependencies
3236
def init_connection_engine() -> sqlalchemy.engine.Engine:
3337
def getconn() -> pytds.Connection:
38+
# initialize Connector object for connections to Cloud SQL
3439
with Connector() as connector:
3540
conn = connector.connect(
3641
os.environ["SQLSERVER_CONNECTION_NAME"],
@@ -41,12 +46,13 @@ def getconn() -> pytds.Connection:
4146
)
4247
return conn
4348

44-
engine = sqlalchemy.create_engine(
49+
# create SQLAlchemy connection pool
50+
pool = sqlalchemy.create_engine(
4551
"mssql+pytds://localhost",
4652
creator=getconn,
4753
)
48-
engine.dialect.description_encoding = None
49-
return engine
54+
pool.dialect.description_encoding = None
55+
return pool
5056

5157

5258
# [END cloud_sql_connector_mysql_pytds]

0 commit comments

Comments
 (0)