Skip to content

Commit

Permalink
feat: enable "rest" transport in Python for services supporting numer…
Browse files Browse the repository at this point in the history
…ic enums (#294)

* feat: enable "rest" transport in Python for services supporting numeric enums

PiperOrigin-RevId: 508143576

Source-Link: googleapis/googleapis@7a702a9

Source-Link: googleapis/googleapis-gen@6ad1279
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNmFkMTI3OWMwZTdhYTc4N2FjNmI2NmM5ZmQ0YTIxMDY5MmVkZmZjZCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* use REST transport in samples/tests

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* revert changes to fixtures

* revert

* revert

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
3 people authored and leahecole committed Jun 16, 2023
1 parent 3842181 commit 63338ab
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions bigquery-connection/snippets/create_mysql_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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}
Expand Down
3 changes: 3 additions & 0 deletions bigquery-connection/snippets/create_mysql_connection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
{
Expand All @@ -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
6 changes: 4 additions & 2 deletions bigquery-connection/snippets/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions bigquery-connection/snippets/quickstart_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 63338ab

Please sign in to comment.