diff --git a/bigquery-reservation/snippets/conftest.py b/bigquery-reservation/snippets/conftest.py index 320cc074124a..1801372fe056 100644 --- a/bigquery-reservation/snippets/conftest.py +++ b/bigquery-reservation/snippets/conftest.py @@ -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") diff --git a/bigquery-reservation/snippets/quickstart.py b/bigquery-reservation/snippets/quickstart.py index eb1227ca2dbb..2452da9d47f2 100644 --- a/bigquery-reservation/snippets/quickstart.py +++ b/bigquery-reservation/snippets/quickstart.py @@ -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) diff --git a/bigquery-reservation/snippets/quickstart_test.py b/bigquery-reservation/snippets/quickstart_test.py index 3ade3e40f0ed..85a0a8727d62 100644 --- a/bigquery-reservation/snippets/quickstart_test.py +++ b/bigquery-reservation/snippets/quickstart_test.py @@ -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 diff --git a/bigquery-reservation/snippets/reservation_create.py b/bigquery-reservation/snippets/reservation_create.py index bae295e880c6..efaaefe30986 100644 --- a/bigquery-reservation/snippets/reservation_create.py +++ b/bigquery-reservation/snippets/reservation_create.py @@ -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 @@ -40,11 +45,15 @@ 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 @@ -52,7 +61,9 @@ def create_reservation( 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) diff --git a/bigquery-reservation/snippets/reservation_delete.py b/bigquery-reservation/snippets/reservation_delete.py index b0537b5e16c5..a0f25ce1cf2f 100644 --- a/bigquery-reservation/snippets/reservation_delete.py +++ b/bigquery-reservation/snippets/reservation_delete.py @@ -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 @@ -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 ) diff --git a/bigquery-reservation/snippets/reservation_test.py b/bigquery-reservation/snippets/reservation_test.py index e92fe9e9afc3..1270ba23251b 100644 --- a/bigquery-reservation/snippets/reservation_test.py +++ b/bigquery-reservation/snippets/reservation_test.py @@ -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 @@ -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 diff --git a/bigquery-reservation/snippets/reservation_update.py b/bigquery-reservation/snippets/reservation_update.py index d43a96dc7b32..8afbd9d7d0f3 100644 --- a/bigquery-reservation/snippets/reservation_update.py +++ b/bigquery-reservation/snippets/reservation_update.py @@ -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 @@ -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 @@ -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