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 (#339)

* 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

* 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

* update samples and system test to use REST

* 🦉 Updates from OwlBot post-processor

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

---------

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 dandhlee committed Jul 24, 2023
1 parent bc41a97 commit 313f9d8
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 16 deletions.
6 changes: 4 additions & 2 deletions bigquery-reservation/snippets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def project_id() -> str:


@pytest.fixture(scope="session")
def reservation_client() -> reservation_service.ReservationServiceClient:
return reservation_service.ReservationServiceClient()
def reservation_client(
transport: str = "grpc",
) -> reservation_service.ReservationServiceClient:
return reservation_service.ReservationServiceClient(transport=transport)


@pytest.fixture(scope="session")
Expand Down
6 changes: 4 additions & 2 deletions bigquery-reservation/snippets/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
from google.cloud import bigquery_reservation_v1


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:
# Constructs the client for interacting with the service.
client = bigquery_reservation_v1.ReservationServiceClient()
client = bigquery_reservation_v1.ReservationServiceClient(transport=transport)

report_capacity_commitments(client, project_id, location)
report_reservations(client, project_id, location)
Expand Down
7 changes: 5 additions & 2 deletions bigquery-reservation/snippets/quickstart_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
from . import quickstart


def test_quickstart(capsys: pytest.CaptureFixture, project_id: str) -> None:
quickstart.main(project_id)
@pytest.mark.parametrize("transport", ["grpc", "rest"])
def test_quickstart(
capsys: pytest.CaptureFixture, project_id: str, transport: str
) -> None:
quickstart.main(project_id=project_id, transport=transport)
out, _ = capsys.readouterr()
assert " reservations processed." in out
15 changes: 13 additions & 2 deletions bigquery-reservation/snippets/reservation_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@


def create_reservation(
project_id: str, location: str, reservation_id: str, slot_capacity: str
project_id: str,
location: str,
reservation_id: str,
slot_capacity: str,
transport: str,
) -> reservation_types.Reservation:
original_project_id = project_id
original_location = location
original_reservation_id = reservation_id
original_slot_capacity = slot_capacity
original_transport = transport

# [START bigqueryreservation_reservation_create]
# TODO(developer): Set project_id to the project ID containing the
Expand All @@ -40,19 +45,25 @@ def create_reservation(
# reservation.
slot_capacity = 100

# TODO(developer): Choose a transport to use. Either 'grpc' or 'rest'
transport = "grpc"

# [START_EXCLUDE]
project_id = original_project_id
location = original_location
reservation_id = original_reservation_id
slot_capacity = original_slot_capacity
transport = original_transport
# [END_EXCLUDE]

from google.cloud.bigquery_reservation_v1.services import reservation_service
from google.cloud.bigquery_reservation_v1.types import (
reservation as reservation_types,
)

reservation_client = reservation_service.ReservationServiceClient()
reservation_client = reservation_service.ReservationServiceClient(
transport=transport
)

parent = reservation_client.common_location_path(project_id, location)

Expand Down
13 changes: 11 additions & 2 deletions bigquery-reservation/snippets/reservation_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
# limitations under the License.


def delete_reservation(project_id: str, location: str, reservation_id: str) -> None:
def delete_reservation(
project_id: str, location: str, reservation_id: str, transport: str
) -> None:
original_project_id = project_id
original_location = location
original_reservation_id = reservation_id
original_transport = transport

# [START bigqueryreservation_reservation_delete]
# TODO(developer): Set project_id to the project ID containing the
Expand All @@ -31,15 +34,21 @@ def delete_reservation(project_id: str, location: str, reservation_id: str) -> N
# TODO(developer): Set reservation_id to a unique ID of the reservation.
reservation_id = "sample-reservation"

# TODO(developer): Choose a transport to use. Either 'grpc' or 'rest'
transport = "grpc"

# [START_EXCLUDE]
project_id = original_project_id
location = original_location
reservation_id = original_reservation_id
transport = original_transport
# [END_EXCLUDE]

from google.cloud.bigquery_reservation_v1.services import reservation_service

reservation_client = reservation_service.ReservationServiceClient()
reservation_client = reservation_service.ReservationServiceClient(
transport=transport
)
reservation_name = reservation_client.reservation_path(
project_id, location, reservation_id
)
Expand Down
15 changes: 11 additions & 4 deletions bigquery-reservation/snippets/reservation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ def reservation_id(
pass


@pytest.mark.parametrize("transport", ["grpc", "rest"])
def test_reservation_samples(
capsys: pytest.CaptureFixture, project_id: str, location: str, reservation_id: str
capsys: pytest.CaptureFixture,
project_id: str,
location: str,
reservation_id: str,
transport: str,
) -> None:
slot_capacity = 100
reservation = reservation_create.create_reservation(
project_id, location, reservation_id, slot_capacity
project_id, location, reservation_id, slot_capacity, transport
)
assert reservation.slot_capacity == 100
assert reservation_id in reservation.name
Expand All @@ -65,14 +70,16 @@ def test_reservation_samples(

slot_capacity = 50
reservation = reservation_update.update_reservation(
project_id, location, reservation_id, slot_capacity
project_id, location, reservation_id, slot_capacity, transport
)
assert reservation.slot_capacity == 50
assert reservation_id in reservation.name
out, _ = capsys.readouterr()
assert f"Updated reservation: {reservation.name}" in out

reservation_delete.delete_reservation(project_id, location, reservation_id)
reservation_delete.delete_reservation(
project_id, location, reservation_id, transport
)
out, _ = capsys.readouterr()
assert "Deleted reservation" in out
assert reservation_id in out
15 changes: 13 additions & 2 deletions bigquery-reservation/snippets/reservation_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@


def update_reservation(
project_id: str, location: str, reservation_id: str, slot_capacity: str
project_id: str,
location: str,
reservation_id: str,
slot_capacity: str,
transport: str,
) -> reservation_types.Reservation:
original_project_id = project_id
original_location = location
original_reservation_id = reservation_id
original_slot_capacity = slot_capacity
original_transport = transport

# [START bigqueryreservation_reservation_update]
# TODO(developer): Set project_id to the project ID containing the
Expand All @@ -40,11 +45,15 @@ def update_reservation(
# reservation.
slot_capacity = 50

# TODO(developer): Choose a transport to use. Either 'grpc' or 'rest'
transport = "grpc"

# [START_EXCLUDE]
project_id = original_project_id
location = original_location
reservation_id = original_reservation_id
slot_capacity = original_slot_capacity
transport = original_transport
# [END_EXCLUDE]

from google.cloud.bigquery_reservation_v1.services import reservation_service
Expand All @@ -53,7 +62,9 @@ def update_reservation(
)
from google.protobuf import field_mask_pb2

reservation_client = reservation_service.ReservationServiceClient()
reservation_client = reservation_service.ReservationServiceClient(
transport=transport
)

reservation_name = reservation_client.reservation_path(
project_id, location, reservation_id
Expand Down

0 comments on commit 313f9d8

Please sign in to comment.