diff --git a/bigquery-connection/snippets/create_mysql_connection.py b/bigquery-connection/snippets/create_mysql_connection.py index a71c9678db01..f4577afbb703 100644 --- a/bigquery-connection/snippets/create_mysql_connection.py +++ b/bigquery-connection/snippets/create_mysql_connection.py @@ -28,6 +28,7 @@ def main() -> None: username = "my-username" # set database username password = "my-password" # set database password cloud_sql_conn_name = "" # set the name of your connection + transport = "grpc" # Set the transport to either "grpc" or "rest" cloud_sql_credential = bq_connection.CloudSqlCredential( { @@ -43,16 +44,17 @@ def main() -> None: "credential": cloud_sql_credential, } ) - create_mysql_connection(project_id, location, cloud_sql_properties) + create_mysql_connection(project_id, location, cloud_sql_properties, transport) def create_mysql_connection( project_id: str, location: str, cloud_sql_properties: bq_connection.CloudSqlProperties, + transport: str, ) -> None: connection = bq_connection.types.Connection({"cloud_sql": cloud_sql_properties}) - client = bq_connection.ConnectionServiceClient() + client = bq_connection.ConnectionServiceClient(transport=transport) parent = client.common_location_path(project_id, location) request = bq_connection.CreateConnectionRequest( {"parent": parent, "connection": connection} diff --git a/bigquery-connection/snippets/create_mysql_connection_test.py b/bigquery-connection/snippets/create_mysql_connection_test.py index 9eda07da2d0d..501af447d8b6 100644 --- a/bigquery-connection/snippets/create_mysql_connection_test.py +++ b/bigquery-connection/snippets/create_mysql_connection_test.py @@ -58,6 +58,7 @@ def connection_id( pass +@pytest.mark.parametrize("transport", ["grpc", "rest"]) def test_create_mysql_connection( capsys: pytest.CaptureFixture, mysql_username: str, @@ -66,6 +67,7 @@ def test_create_mysql_connection( cloud_sql_conn_name: str, project_id: str, location: str, + transport: str, ) -> None: cloud_sql_credential = bq_connection.CloudSqlCredential( { @@ -85,6 +87,7 @@ def test_create_mysql_connection( project_id=project_id, location=location, cloud_sql_properties=cloud_sql_properties, + transport=transport, ) out, _ = capsys.readouterr() assert "Created connection successfully:" in out diff --git a/bigquery-connection/snippets/quickstart.py b/bigquery-connection/snippets/quickstart.py index 3c5107c1291c..463bd8a87ccc 100644 --- a/bigquery-connection/snippets/quickstart.py +++ b/bigquery-connection/snippets/quickstart.py @@ -17,9 +17,11 @@ from google.cloud import bigquery_connection_v1 as bq_connection -def main(project_id: str = "your-project-id", location: str = "US") -> None: +def main( + project_id: str = "your-project-id", location: str = "US", transport: str = "grpc" +) -> None: """Prints details and summary information about connections for a given admin project and location""" - client = bq_connection.ConnectionServiceClient() + client = bq_connection.ConnectionServiceClient(transport=transport) print(f"List of connections in project {project_id} in location {location}") req = bq_connection.ListConnectionsRequest( parent=client.common_location_path(project_id, location) diff --git a/bigquery-connection/snippets/quickstart_test.py b/bigquery-connection/snippets/quickstart_test.py index 615134b51241..2a8df8f59eaf 100644 --- a/bigquery-connection/snippets/quickstart_test.py +++ b/bigquery-connection/snippets/quickstart_test.py @@ -17,9 +17,10 @@ from . import quickstart +@pytest.mark.parametrize("transport", ["grpc", "rest"]) def test_quickstart( - capsys: pytest.CaptureFixture, project_id: str, location: str + capsys: pytest.CaptureFixture, project_id: str, location: str, transport: str ) -> None: - quickstart.main(project_id, location) + quickstart.main(project_id, location, transport) out, _ = capsys.readouterr() assert "List of connections in project" in out