Skip to content

Commit e91bdac

Browse files
gcf-owl-bot[bot]parthea
authored andcommitted
feat: enable "rest" transport in Python for services supporting numeric 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 <[email protected]>
1 parent 72060b4 commit e91bdac

File tree

7 files changed

+61
-16
lines changed

7 files changed

+61
-16
lines changed

bigquery-reservation/snippets/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ def project_id() -> str:
4242

4343

4444
@pytest.fixture(scope="session")
45-
def reservation_client() -> reservation_service.ReservationServiceClient:
46-
return reservation_service.ReservationServiceClient()
45+
def reservation_client(
46+
transport: str = "grpc",
47+
) -> reservation_service.ReservationServiceClient:
48+
return reservation_service.ReservationServiceClient(transport=transport)
4749

4850

4951
@pytest.fixture(scope="session")

bigquery-reservation/snippets/quickstart.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
from google.cloud import bigquery_reservation_v1
1919

2020

21-
def main(project_id: str = "your-project-id", location: str = "US") -> None:
21+
def main(
22+
project_id: str = "your-project-id", location: str = "US", transport: str = "grpc"
23+
) -> None:
2224
# Constructs the client for interacting with the service.
23-
client = bigquery_reservation_v1.ReservationServiceClient()
25+
client = bigquery_reservation_v1.ReservationServiceClient(transport=transport)
2426

2527
report_capacity_commitments(client, project_id, location)
2628
report_reservations(client, project_id, location)

bigquery-reservation/snippets/quickstart_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
from . import quickstart
1818

1919

20-
def test_quickstart(capsys: pytest.CaptureFixture, project_id: str) -> None:
21-
quickstart.main(project_id)
20+
@pytest.mark.parametrize("transport", ["grpc", "rest"])
21+
def test_quickstart(
22+
capsys: pytest.CaptureFixture, project_id: str, transport: str
23+
) -> None:
24+
quickstart.main(project_id=project_id, transport=transport)
2225
out, _ = capsys.readouterr()
2326
assert " reservations processed." in out

bigquery-reservation/snippets/reservation_create.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616

1717

1818
def create_reservation(
19-
project_id: str, location: str, reservation_id: str, slot_capacity: str
19+
project_id: str,
20+
location: str,
21+
reservation_id: str,
22+
slot_capacity: str,
23+
transport: str,
2024
) -> reservation_types.Reservation:
2125
original_project_id = project_id
2226
original_location = location
2327
original_reservation_id = reservation_id
2428
original_slot_capacity = slot_capacity
29+
original_transport = transport
2530

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

48+
# TODO(developer): Choose a transport to use. Either 'grpc' or 'rest'
49+
transport = "grpc"
50+
4351
# [START_EXCLUDE]
4452
project_id = original_project_id
4553
location = original_location
4654
reservation_id = original_reservation_id
4755
slot_capacity = original_slot_capacity
56+
transport = original_transport
4857
# [END_EXCLUDE]
4958

5059
from google.cloud.bigquery_reservation_v1.services import reservation_service
5160
from google.cloud.bigquery_reservation_v1.types import (
5261
reservation as reservation_types,
5362
)
5463

55-
reservation_client = reservation_service.ReservationServiceClient()
64+
reservation_client = reservation_service.ReservationServiceClient(
65+
transport=transport
66+
)
5667

5768
parent = reservation_client.common_location_path(project_id, location)
5869

bigquery-reservation/snippets/reservation_delete.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
# limitations under the License.
1414

1515

16-
def delete_reservation(project_id: str, location: str, reservation_id: str) -> None:
16+
def delete_reservation(
17+
project_id: str, location: str, reservation_id: str, transport: str
18+
) -> None:
1719
original_project_id = project_id
1820
original_location = location
1921
original_reservation_id = reservation_id
22+
original_transport = transport
2023

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

37+
# TODO(developer): Choose a transport to use. Either 'grpc' or 'rest'
38+
transport = "grpc"
39+
3440
# [START_EXCLUDE]
3541
project_id = original_project_id
3642
location = original_location
3743
reservation_id = original_reservation_id
44+
transport = original_transport
3845
# [END_EXCLUDE]
3946

4047
from google.cloud.bigquery_reservation_v1.services import reservation_service
4148

42-
reservation_client = reservation_service.ReservationServiceClient()
49+
reservation_client = reservation_service.ReservationServiceClient(
50+
transport=transport
51+
)
4352
reservation_name = reservation_client.reservation_path(
4453
project_id, location, reservation_id
4554
)

bigquery-reservation/snippets/reservation_test.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,17 @@ def reservation_id(
5151
pass
5252

5353

54+
@pytest.mark.parametrize("transport", ["grpc", "rest"])
5455
def test_reservation_samples(
55-
capsys: pytest.CaptureFixture, project_id: str, location: str, reservation_id: str
56+
capsys: pytest.CaptureFixture,
57+
project_id: str,
58+
location: str,
59+
reservation_id: str,
60+
transport: str,
5661
) -> None:
5762
slot_capacity = 100
5863
reservation = reservation_create.create_reservation(
59-
project_id, location, reservation_id, slot_capacity
64+
project_id, location, reservation_id, slot_capacity, transport
6065
)
6166
assert reservation.slot_capacity == 100
6267
assert reservation_id in reservation.name
@@ -65,14 +70,16 @@ def test_reservation_samples(
6570

6671
slot_capacity = 50
6772
reservation = reservation_update.update_reservation(
68-
project_id, location, reservation_id, slot_capacity
73+
project_id, location, reservation_id, slot_capacity, transport
6974
)
7075
assert reservation.slot_capacity == 50
7176
assert reservation_id in reservation.name
7277
out, _ = capsys.readouterr()
7378
assert f"Updated reservation: {reservation.name}" in out
7479

75-
reservation_delete.delete_reservation(project_id, location, reservation_id)
80+
reservation_delete.delete_reservation(
81+
project_id, location, reservation_id, transport
82+
)
7683
out, _ = capsys.readouterr()
7784
assert "Deleted reservation" in out
7885
assert reservation_id in out

bigquery-reservation/snippets/reservation_update.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616

1717

1818
def update_reservation(
19-
project_id: str, location: str, reservation_id: str, slot_capacity: str
19+
project_id: str,
20+
location: str,
21+
reservation_id: str,
22+
slot_capacity: str,
23+
transport: str,
2024
) -> reservation_types.Reservation:
2125
original_project_id = project_id
2226
original_location = location
2327
original_reservation_id = reservation_id
2428
original_slot_capacity = slot_capacity
29+
original_transport = transport
2530

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

48+
# TODO(developer): Choose a transport to use. Either 'grpc' or 'rest'
49+
transport = "grpc"
50+
4351
# [START_EXCLUDE]
4452
project_id = original_project_id
4553
location = original_location
4654
reservation_id = original_reservation_id
4755
slot_capacity = original_slot_capacity
56+
transport = original_transport
4857
# [END_EXCLUDE]
4958

5059
from google.cloud.bigquery_reservation_v1.services import reservation_service
@@ -53,7 +62,9 @@ def update_reservation(
5362
)
5463
from google.protobuf import field_mask_pb2
5564

56-
reservation_client = reservation_service.ReservationServiceClient()
65+
reservation_client = reservation_service.ReservationServiceClient(
66+
transport=transport
67+
)
5768

5869
reservation_name = reservation_client.reservation_path(
5970
project_id, location, reservation_id

0 commit comments

Comments
 (0)