From edbd1046e38c14fcce8f4c20822eb124b026d925 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 10 Jun 2021 14:27:04 -0400 Subject: [PATCH] feat: Add Pub/Sub Lite Reservation APIs (#156) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add Pub/Sub Lite Reservation APIs PiperOrigin-RevId: 377060979 Source-Link: https://github.com/googleapis/googleapis/commit/51d99df0295d5cebed2b0ba41ce629c42ea8ca65 Source-Link: https://github.com/googleapis/googleapis-gen/commit/604a9d39f80229ab5e662f2eaa9e94418d02a23a * 🦉 Updates from OwlBot Co-authored-by: Owl Bot --- google/cloud/pubsublite_v1/__init__.py | 18 + .../cloud/pubsublite_v1/gapic_metadata.json | 60 + .../services/admin_service/async_client.py | 472 +++++ .../services/admin_service/client.py | 486 +++++ .../services/admin_service/pagers.py | 256 +++ .../services/admin_service/transports/base.py | 79 + .../services/admin_service/transports/grpc.py | 160 ++ .../admin_service/transports/grpc_asyncio.py | 163 ++ google/cloud/pubsublite_v1/types/__init__.py | 18 + google/cloud/pubsublite_v1/types/admin.py | 168 ++ google/cloud/pubsublite_v1/types/common.py | 42 + .../gapic/pubsublite_v1/test_admin_service.py | 1620 ++++++++++++++++- 12 files changed, 3519 insertions(+), 23 deletions(-) diff --git a/google/cloud/pubsublite_v1/__init__.py b/google/cloud/pubsublite_v1/__init__.py index fbd29ce0..fbcd53a0 100644 --- a/google/cloud/pubsublite_v1/__init__.py +++ b/google/cloud/pubsublite_v1/__init__.py @@ -27,13 +27,20 @@ from .services.topic_stats_service import TopicStatsServiceClient from .services.topic_stats_service import TopicStatsServiceAsyncClient +from .types.admin import CreateReservationRequest from .types.admin import CreateSubscriptionRequest from .types.admin import CreateTopicRequest +from .types.admin import DeleteReservationRequest from .types.admin import DeleteSubscriptionRequest from .types.admin import DeleteTopicRequest +from .types.admin import GetReservationRequest from .types.admin import GetSubscriptionRequest from .types.admin import GetTopicPartitionsRequest from .types.admin import GetTopicRequest +from .types.admin import ListReservationsRequest +from .types.admin import ListReservationsResponse +from .types.admin import ListReservationTopicsRequest +from .types.admin import ListReservationTopicsResponse from .types.admin import ListSubscriptionsRequest from .types.admin import ListSubscriptionsResponse from .types.admin import ListTopicsRequest @@ -41,11 +48,13 @@ from .types.admin import ListTopicSubscriptionsRequest from .types.admin import ListTopicSubscriptionsResponse from .types.admin import TopicPartitions +from .types.admin import UpdateReservationRequest from .types.admin import UpdateSubscriptionRequest from .types.admin import UpdateTopicRequest from .types.common import AttributeValues from .types.common import Cursor from .types.common import PubSubMessage +from .types.common import Reservation from .types.common import SequencedMessage from .types.common import Subscription from .types.common import TimeTarget @@ -103,13 +112,16 @@ "ComputeMessageStatsResponse", "ComputeTimeCursorRequest", "ComputeTimeCursorResponse", + "CreateReservationRequest", "CreateSubscriptionRequest", "CreateTopicRequest", "Cursor", "CursorServiceClient", + "DeleteReservationRequest", "DeleteSubscriptionRequest", "DeleteTopicRequest", "FlowControlRequest", + "GetReservationRequest", "GetSubscriptionRequest", "GetTopicPartitionsRequest", "GetTopicRequest", @@ -122,6 +134,10 @@ "InitialSubscribeResponse", "ListPartitionCursorsRequest", "ListPartitionCursorsResponse", + "ListReservationTopicsRequest", + "ListReservationTopicsResponse", + "ListReservationsRequest", + "ListReservationsResponse", "ListSubscriptionsRequest", "ListSubscriptionsResponse", "ListTopicSubscriptionsRequest", @@ -140,6 +156,7 @@ "PublishRequest", "PublishResponse", "PublisherServiceClient", + "Reservation", "SeekRequest", "SeekResponse", "SequencedCommitCursorRequest", @@ -155,6 +172,7 @@ "Topic", "TopicPartitions", "TopicStatsServiceClient", + "UpdateReservationRequest", "UpdateSubscriptionRequest", "UpdateTopicRequest", ) diff --git a/google/cloud/pubsublite_v1/gapic_metadata.json b/google/cloud/pubsublite_v1/gapic_metadata.json index 160098a5..6e66f383 100644 --- a/google/cloud/pubsublite_v1/gapic_metadata.json +++ b/google/cloud/pubsublite_v1/gapic_metadata.json @@ -10,6 +10,11 @@ "grpc": { "libraryClient": "AdminServiceClient", "rpcs": { + "CreateReservation": { + "methods": [ + "create_reservation" + ] + }, "CreateSubscription": { "methods": [ "create_subscription" @@ -20,6 +25,11 @@ "create_topic" ] }, + "DeleteReservation": { + "methods": [ + "delete_reservation" + ] + }, "DeleteSubscription": { "methods": [ "delete_subscription" @@ -30,6 +40,11 @@ "delete_topic" ] }, + "GetReservation": { + "methods": [ + "get_reservation" + ] + }, "GetSubscription": { "methods": [ "get_subscription" @@ -45,6 +60,16 @@ "get_topic_partitions" ] }, + "ListReservationTopics": { + "methods": [ + "list_reservation_topics" + ] + }, + "ListReservations": { + "methods": [ + "list_reservations" + ] + }, "ListSubscriptions": { "methods": [ "list_subscriptions" @@ -60,6 +85,11 @@ "list_topics" ] }, + "UpdateReservation": { + "methods": [ + "update_reservation" + ] + }, "UpdateSubscription": { "methods": [ "update_subscription" @@ -75,6 +105,11 @@ "grpc-async": { "libraryClient": "AdminServiceAsyncClient", "rpcs": { + "CreateReservation": { + "methods": [ + "create_reservation" + ] + }, "CreateSubscription": { "methods": [ "create_subscription" @@ -85,6 +120,11 @@ "create_topic" ] }, + "DeleteReservation": { + "methods": [ + "delete_reservation" + ] + }, "DeleteSubscription": { "methods": [ "delete_subscription" @@ -95,6 +135,11 @@ "delete_topic" ] }, + "GetReservation": { + "methods": [ + "get_reservation" + ] + }, "GetSubscription": { "methods": [ "get_subscription" @@ -110,6 +155,16 @@ "get_topic_partitions" ] }, + "ListReservationTopics": { + "methods": [ + "list_reservation_topics" + ] + }, + "ListReservations": { + "methods": [ + "list_reservations" + ] + }, "ListSubscriptions": { "methods": [ "list_subscriptions" @@ -125,6 +180,11 @@ "list_topics" ] }, + "UpdateReservation": { + "methods": [ + "update_reservation" + ] + }, "UpdateSubscription": { "methods": [ "update_subscription" diff --git a/google/cloud/pubsublite_v1/services/admin_service/async_client.py b/google/cloud/pubsublite_v1/services/admin_service/async_client.py index 0cdd5304..cf3e1afb 100644 --- a/google/cloud/pubsublite_v1/services/admin_service/async_client.py +++ b/google/cloud/pubsublite_v1/services/admin_service/async_client.py @@ -46,6 +46,8 @@ class AdminServiceAsyncClient: DEFAULT_ENDPOINT = AdminServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = AdminServiceClient.DEFAULT_MTLS_ENDPOINT + reservation_path = staticmethod(AdminServiceClient.reservation_path) + parse_reservation_path = staticmethod(AdminServiceClient.parse_reservation_path) subscription_path = staticmethod(AdminServiceClient.subscription_path) parse_subscription_path = staticmethod(AdminServiceClient.parse_subscription_path) topic_path = staticmethod(AdminServiceClient.topic_path) @@ -1082,6 +1084,476 @@ async def delete_subscription( request, retry=retry, timeout=timeout, metadata=metadata, ) + async def create_reservation( + self, + request: admin.CreateReservationRequest = None, + *, + parent: str = None, + reservation: common.Reservation = None, + reservation_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> common.Reservation: + r"""Creates a new reservation. + + Args: + request (:class:`google.cloud.pubsublite_v1.types.CreateReservationRequest`): + The request object. Request for CreateReservation. + parent (:class:`str`): + Required. The parent location in which to create the + reservation. Structured like + ``projects/{project_number}/locations/{location}``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reservation (:class:`google.cloud.pubsublite_v1.types.Reservation`): + Required. Configuration of the reservation to create. + Its ``name`` field is ignored. + + This corresponds to the ``reservation`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reservation_id (:class:`str`): + Required. The ID to use for the reservation, which will + become the final component of the reservation's name. + + This value is structured like: ``my-reservation-name``. + + This corresponds to the ``reservation_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.pubsublite_v1.types.Reservation: + Metadata about a reservation + resource. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, reservation, reservation_id]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = admin.CreateReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if reservation is not None: + request.reservation = reservation + if reservation_id is not None: + request.reservation_id = reservation_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_reservation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def get_reservation( + self, + request: admin.GetReservationRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> common.Reservation: + r"""Returns the reservation configuration. + + Args: + request (:class:`google.cloud.pubsublite_v1.types.GetReservationRequest`): + The request object. Request for GetReservation. + name (:class:`str`): + Required. The name of the reservation whose + configuration to return. Structured like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.pubsublite_v1.types.Reservation: + Metadata about a reservation + resource. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = admin.GetReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_reservation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def list_reservations( + self, + request: admin.ListReservationsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReservationsAsyncPager: + r"""Returns the list of reservations for the given + project. + + Args: + request (:class:`google.cloud.pubsublite_v1.types.ListReservationsRequest`): + The request object. Request for ListReservations. + parent (:class:`str`): + Required. The parent whose reservations are to be + listed. Structured like + ``projects/{project_number}/locations/{location}``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.pubsublite_v1.services.admin_service.pagers.ListReservationsAsyncPager: + Response for ListReservations. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = admin.ListReservationsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_reservations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListReservationsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_reservation( + self, + request: admin.UpdateReservationRequest = None, + *, + reservation: common.Reservation = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> common.Reservation: + r"""Updates properties of the specified reservation. + + Args: + request (:class:`google.cloud.pubsublite_v1.types.UpdateReservationRequest`): + The request object. Request for UpdateReservation. + reservation (:class:`google.cloud.pubsublite_v1.types.Reservation`): + Required. The reservation to update. Its ``name`` field + must be populated. + + This corresponds to the ``reservation`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. A mask specifying the + reservation fields to change. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.pubsublite_v1.types.Reservation: + Metadata about a reservation + resource. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([reservation, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = admin.UpdateReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if reservation is not None: + request.reservation = reservation + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_reservation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("reservation.name", request.reservation.name),) + ), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def delete_reservation( + self, + request: admin.DeleteReservationRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes the specified reservation. + + Args: + request (:class:`google.cloud.pubsublite_v1.types.DeleteReservationRequest`): + The request object. Request for DeleteReservation. + name (:class:`str`): + Required. The name of the reservation to delete. + Structured like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = admin.DeleteReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.delete_reservation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, retry=retry, timeout=timeout, metadata=metadata, + ) + + async def list_reservation_topics( + self, + request: admin.ListReservationTopicsRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReservationTopicsAsyncPager: + r"""Lists the topics attached to the specified + reservation. + + Args: + request (:class:`google.cloud.pubsublite_v1.types.ListReservationTopicsRequest`): + The request object. Request for ListReservationTopics. + name (:class:`str`): + Required. The name of the reservation whose topics to + list. Structured like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.pubsublite_v1.services.admin_service.pagers.ListReservationTopicsAsyncPager: + Response for ListReservationTopics. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = admin.ListReservationTopicsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_reservation_topics, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListReservationTopicsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/pubsublite_v1/services/admin_service/client.py b/google/cloud/pubsublite_v1/services/admin_service/client.py index 40e9d39a..a4926aa1 100644 --- a/google/cloud/pubsublite_v1/services/admin_service/client.py +++ b/google/cloud/pubsublite_v1/services/admin_service/client.py @@ -158,6 +158,22 @@ def transport(self) -> AdminServiceTransport: """ return self._transport + @staticmethod + def reservation_path(project: str, location: str, reservation: str,) -> str: + """Returns a fully-qualified reservation string.""" + return "projects/{project}/locations/{location}/reservations/{reservation}".format( + project=project, location=location, reservation=reservation, + ) + + @staticmethod + def parse_reservation_path(path: str) -> Dict[str, str]: + """Parses a reservation path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/reservations/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def subscription_path(project: str, location: str, subscription: str,) -> str: """Returns a fully-qualified subscription string.""" @@ -1283,6 +1299,476 @@ def delete_subscription( request, retry=retry, timeout=timeout, metadata=metadata, ) + def create_reservation( + self, + request: admin.CreateReservationRequest = None, + *, + parent: str = None, + reservation: common.Reservation = None, + reservation_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> common.Reservation: + r"""Creates a new reservation. + + Args: + request (google.cloud.pubsublite_v1.types.CreateReservationRequest): + The request object. Request for CreateReservation. + parent (str): + Required. The parent location in which to create the + reservation. Structured like + ``projects/{project_number}/locations/{location}``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reservation (google.cloud.pubsublite_v1.types.Reservation): + Required. Configuration of the reservation to create. + Its ``name`` field is ignored. + + This corresponds to the ``reservation`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reservation_id (str): + Required. The ID to use for the reservation, which will + become the final component of the reservation's name. + + This value is structured like: ``my-reservation-name``. + + This corresponds to the ``reservation_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.pubsublite_v1.types.Reservation: + Metadata about a reservation + resource. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, reservation, reservation_id]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a admin.CreateReservationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, admin.CreateReservationRequest): + request = admin.CreateReservationRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if reservation is not None: + request.reservation = reservation + if reservation_id is not None: + request.reservation_id = reservation_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_reservation] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def get_reservation( + self, + request: admin.GetReservationRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> common.Reservation: + r"""Returns the reservation configuration. + + Args: + request (google.cloud.pubsublite_v1.types.GetReservationRequest): + The request object. Request for GetReservation. + name (str): + Required. The name of the reservation whose + configuration to return. Structured like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.pubsublite_v1.types.Reservation: + Metadata about a reservation + resource. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a admin.GetReservationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, admin.GetReservationRequest): + request = admin.GetReservationRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_reservation] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def list_reservations( + self, + request: admin.ListReservationsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReservationsPager: + r"""Returns the list of reservations for the given + project. + + Args: + request (google.cloud.pubsublite_v1.types.ListReservationsRequest): + The request object. Request for ListReservations. + parent (str): + Required. The parent whose reservations are to be + listed. Structured like + ``projects/{project_number}/locations/{location}``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.pubsublite_v1.services.admin_service.pagers.ListReservationsPager: + Response for ListReservations. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a admin.ListReservationsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, admin.ListReservationsRequest): + request = admin.ListReservationsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_reservations] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListReservationsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def update_reservation( + self, + request: admin.UpdateReservationRequest = None, + *, + reservation: common.Reservation = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> common.Reservation: + r"""Updates properties of the specified reservation. + + Args: + request (google.cloud.pubsublite_v1.types.UpdateReservationRequest): + The request object. Request for UpdateReservation. + reservation (google.cloud.pubsublite_v1.types.Reservation): + Required. The reservation to update. Its ``name`` field + must be populated. + + This corresponds to the ``reservation`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. A mask specifying the + reservation fields to change. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.pubsublite_v1.types.Reservation: + Metadata about a reservation + resource. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([reservation, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a admin.UpdateReservationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, admin.UpdateReservationRequest): + request = admin.UpdateReservationRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if reservation is not None: + request.reservation = reservation + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_reservation] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("reservation.name", request.reservation.name),) + ), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def delete_reservation( + self, + request: admin.DeleteReservationRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes the specified reservation. + + Args: + request (google.cloud.pubsublite_v1.types.DeleteReservationRequest): + The request object. Request for DeleteReservation. + name (str): + Required. The name of the reservation to delete. + Structured like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a admin.DeleteReservationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, admin.DeleteReservationRequest): + request = admin.DeleteReservationRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_reservation] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, retry=retry, timeout=timeout, metadata=metadata, + ) + + def list_reservation_topics( + self, + request: admin.ListReservationTopicsRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReservationTopicsPager: + r"""Lists the topics attached to the specified + reservation. + + Args: + request (google.cloud.pubsublite_v1.types.ListReservationTopicsRequest): + The request object. Request for ListReservationTopics. + name (str): + Required. The name of the reservation whose topics to + list. Structured like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.pubsublite_v1.services.admin_service.pagers.ListReservationTopicsPager: + Response for ListReservationTopics. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a admin.ListReservationTopicsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, admin.ListReservationTopicsRequest): + request = admin.ListReservationTopicsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_reservation_topics] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListReservationTopicsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/pubsublite_v1/services/admin_service/pagers.py b/google/cloud/pubsublite_v1/services/admin_service/pagers.py index 02680128..893e9189 100644 --- a/google/cloud/pubsublite_v1/services/admin_service/pagers.py +++ b/google/cloud/pubsublite_v1/services/admin_service/pagers.py @@ -410,3 +410,259 @@ async def async_generator(): def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListReservationsPager: + """A pager for iterating through ``list_reservations`` requests. + + This class thinly wraps an initial + :class:`google.cloud.pubsublite_v1.types.ListReservationsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``reservations`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListReservations`` requests and continue to iterate + through the ``reservations`` field on the + corresponding responses. + + All the usual :class:`google.cloud.pubsublite_v1.types.ListReservationsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., admin.ListReservationsResponse], + request: admin.ListReservationsRequest, + response: admin.ListReservationsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.pubsublite_v1.types.ListReservationsRequest): + The initial request object. + response (google.cloud.pubsublite_v1.types.ListReservationsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = admin.ListReservationsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterable[admin.ListReservationsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterable[common.Reservation]: + for page in self.pages: + yield from page.reservations + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListReservationsAsyncPager: + """A pager for iterating through ``list_reservations`` requests. + + This class thinly wraps an initial + :class:`google.cloud.pubsublite_v1.types.ListReservationsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``reservations`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListReservations`` requests and continue to iterate + through the ``reservations`` field on the + corresponding responses. + + All the usual :class:`google.cloud.pubsublite_v1.types.ListReservationsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[admin.ListReservationsResponse]], + request: admin.ListReservationsRequest, + response: admin.ListReservationsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.pubsublite_v1.types.ListReservationsRequest): + The initial request object. + response (google.cloud.pubsublite_v1.types.ListReservationsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = admin.ListReservationsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterable[admin.ListReservationsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterable[common.Reservation]: + async def async_generator(): + async for page in self.pages: + for response in page.reservations: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListReservationTopicsPager: + """A pager for iterating through ``list_reservation_topics`` requests. + + This class thinly wraps an initial + :class:`google.cloud.pubsublite_v1.types.ListReservationTopicsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``topics`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListReservationTopics`` requests and continue to iterate + through the ``topics`` field on the + corresponding responses. + + All the usual :class:`google.cloud.pubsublite_v1.types.ListReservationTopicsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., admin.ListReservationTopicsResponse], + request: admin.ListReservationTopicsRequest, + response: admin.ListReservationTopicsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.pubsublite_v1.types.ListReservationTopicsRequest): + The initial request object. + response (google.cloud.pubsublite_v1.types.ListReservationTopicsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = admin.ListReservationTopicsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterable[admin.ListReservationTopicsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterable[str]: + for page in self.pages: + yield from page.topics + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListReservationTopicsAsyncPager: + """A pager for iterating through ``list_reservation_topics`` requests. + + This class thinly wraps an initial + :class:`google.cloud.pubsublite_v1.types.ListReservationTopicsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``topics`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListReservationTopics`` requests and continue to iterate + through the ``topics`` field on the + corresponding responses. + + All the usual :class:`google.cloud.pubsublite_v1.types.ListReservationTopicsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[admin.ListReservationTopicsResponse]], + request: admin.ListReservationTopicsRequest, + response: admin.ListReservationTopicsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.pubsublite_v1.types.ListReservationTopicsRequest): + The initial request object. + response (google.cloud.pubsublite_v1.types.ListReservationTopicsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = admin.ListReservationTopicsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterable[admin.ListReservationTopicsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterable[str]: + async def async_generator(): + async for page in self.pages: + for response in page.topics: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/pubsublite_v1/services/admin_service/transports/base.py b/google/cloud/pubsublite_v1/services/admin_service/transports/base.py index f7ea8b6b..74d8c6a4 100644 --- a/google/cloud/pubsublite_v1/services/admin_service/transports/base.py +++ b/google/cloud/pubsublite_v1/services/admin_service/transports/base.py @@ -208,6 +208,26 @@ def _prep_wrapped_messages(self, client_info): self.delete_subscription: gapic_v1.method.wrap_method( self.delete_subscription, default_timeout=None, client_info=client_info, ), + self.create_reservation: gapic_v1.method.wrap_method( + self.create_reservation, default_timeout=None, client_info=client_info, + ), + self.get_reservation: gapic_v1.method.wrap_method( + self.get_reservation, default_timeout=None, client_info=client_info, + ), + self.list_reservations: gapic_v1.method.wrap_method( + self.list_reservations, default_timeout=None, client_info=client_info, + ), + self.update_reservation: gapic_v1.method.wrap_method( + self.update_reservation, default_timeout=None, client_info=client_info, + ), + self.delete_reservation: gapic_v1.method.wrap_method( + self.delete_reservation, default_timeout=None, client_info=client_info, + ), + self.list_reservation_topics: gapic_v1.method.wrap_method( + self.list_reservation_topics, + default_timeout=None, + client_info=client_info, + ), } @property @@ -319,5 +339,64 @@ def delete_subscription( ]: raise NotImplementedError() + @property + def create_reservation( + self, + ) -> Callable[ + [admin.CreateReservationRequest], + Union[common.Reservation, Awaitable[common.Reservation]], + ]: + raise NotImplementedError() + + @property + def get_reservation( + self, + ) -> Callable[ + [admin.GetReservationRequest], + Union[common.Reservation, Awaitable[common.Reservation]], + ]: + raise NotImplementedError() + + @property + def list_reservations( + self, + ) -> Callable[ + [admin.ListReservationsRequest], + Union[ + admin.ListReservationsResponse, Awaitable[admin.ListReservationsResponse] + ], + ]: + raise NotImplementedError() + + @property + def update_reservation( + self, + ) -> Callable[ + [admin.UpdateReservationRequest], + Union[common.Reservation, Awaitable[common.Reservation]], + ]: + raise NotImplementedError() + + @property + def delete_reservation( + self, + ) -> Callable[ + [admin.DeleteReservationRequest], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], + ]: + raise NotImplementedError() + + @property + def list_reservation_topics( + self, + ) -> Callable[ + [admin.ListReservationTopicsRequest], + Union[ + admin.ListReservationTopicsResponse, + Awaitable[admin.ListReservationTopicsResponse], + ], + ]: + raise NotImplementedError() + __all__ = ("AdminServiceTransport",) diff --git a/google/cloud/pubsublite_v1/services/admin_service/transports/grpc.py b/google/cloud/pubsublite_v1/services/admin_service/transports/grpc.py index 1b0bba6d..1d98d5e9 100644 --- a/google/cloud/pubsublite_v1/services/admin_service/transports/grpc.py +++ b/google/cloud/pubsublite_v1/services/admin_service/transports/grpc.py @@ -534,5 +534,165 @@ def delete_subscription( ) return self._stubs["delete_subscription"] + @property + def create_reservation( + self, + ) -> Callable[[admin.CreateReservationRequest], common.Reservation]: + r"""Return a callable for the create reservation method over gRPC. + + Creates a new reservation. + + Returns: + Callable[[~.CreateReservationRequest], + ~.Reservation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_reservation" not in self._stubs: + self._stubs["create_reservation"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/CreateReservation", + request_serializer=admin.CreateReservationRequest.serialize, + response_deserializer=common.Reservation.deserialize, + ) + return self._stubs["create_reservation"] + + @property + def get_reservation( + self, + ) -> Callable[[admin.GetReservationRequest], common.Reservation]: + r"""Return a callable for the get reservation method over gRPC. + + Returns the reservation configuration. + + Returns: + Callable[[~.GetReservationRequest], + ~.Reservation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_reservation" not in self._stubs: + self._stubs["get_reservation"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/GetReservation", + request_serializer=admin.GetReservationRequest.serialize, + response_deserializer=common.Reservation.deserialize, + ) + return self._stubs["get_reservation"] + + @property + def list_reservations( + self, + ) -> Callable[[admin.ListReservationsRequest], admin.ListReservationsResponse]: + r"""Return a callable for the list reservations method over gRPC. + + Returns the list of reservations for the given + project. + + Returns: + Callable[[~.ListReservationsRequest], + ~.ListReservationsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_reservations" not in self._stubs: + self._stubs["list_reservations"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/ListReservations", + request_serializer=admin.ListReservationsRequest.serialize, + response_deserializer=admin.ListReservationsResponse.deserialize, + ) + return self._stubs["list_reservations"] + + @property + def update_reservation( + self, + ) -> Callable[[admin.UpdateReservationRequest], common.Reservation]: + r"""Return a callable for the update reservation method over gRPC. + + Updates properties of the specified reservation. + + Returns: + Callable[[~.UpdateReservationRequest], + ~.Reservation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_reservation" not in self._stubs: + self._stubs["update_reservation"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/UpdateReservation", + request_serializer=admin.UpdateReservationRequest.serialize, + response_deserializer=common.Reservation.deserialize, + ) + return self._stubs["update_reservation"] + + @property + def delete_reservation( + self, + ) -> Callable[[admin.DeleteReservationRequest], empty_pb2.Empty]: + r"""Return a callable for the delete reservation method over gRPC. + + Deletes the specified reservation. + + Returns: + Callable[[~.DeleteReservationRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_reservation" not in self._stubs: + self._stubs["delete_reservation"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/DeleteReservation", + request_serializer=admin.DeleteReservationRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_reservation"] + + @property + def list_reservation_topics( + self, + ) -> Callable[ + [admin.ListReservationTopicsRequest], admin.ListReservationTopicsResponse + ]: + r"""Return a callable for the list reservation topics method over gRPC. + + Lists the topics attached to the specified + reservation. + + Returns: + Callable[[~.ListReservationTopicsRequest], + ~.ListReservationTopicsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_reservation_topics" not in self._stubs: + self._stubs["list_reservation_topics"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/ListReservationTopics", + request_serializer=admin.ListReservationTopicsRequest.serialize, + response_deserializer=admin.ListReservationTopicsResponse.deserialize, + ) + return self._stubs["list_reservation_topics"] + __all__ = ("AdminServiceGrpcTransport",) diff --git a/google/cloud/pubsublite_v1/services/admin_service/transports/grpc_asyncio.py b/google/cloud/pubsublite_v1/services/admin_service/transports/grpc_asyncio.py index b4aa423b..ff9841ee 100644 --- a/google/cloud/pubsublite_v1/services/admin_service/transports/grpc_asyncio.py +++ b/google/cloud/pubsublite_v1/services/admin_service/transports/grpc_asyncio.py @@ -546,5 +546,168 @@ def delete_subscription( ) return self._stubs["delete_subscription"] + @property + def create_reservation( + self, + ) -> Callable[[admin.CreateReservationRequest], Awaitable[common.Reservation]]: + r"""Return a callable for the create reservation method over gRPC. + + Creates a new reservation. + + Returns: + Callable[[~.CreateReservationRequest], + Awaitable[~.Reservation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_reservation" not in self._stubs: + self._stubs["create_reservation"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/CreateReservation", + request_serializer=admin.CreateReservationRequest.serialize, + response_deserializer=common.Reservation.deserialize, + ) + return self._stubs["create_reservation"] + + @property + def get_reservation( + self, + ) -> Callable[[admin.GetReservationRequest], Awaitable[common.Reservation]]: + r"""Return a callable for the get reservation method over gRPC. + + Returns the reservation configuration. + + Returns: + Callable[[~.GetReservationRequest], + Awaitable[~.Reservation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_reservation" not in self._stubs: + self._stubs["get_reservation"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/GetReservation", + request_serializer=admin.GetReservationRequest.serialize, + response_deserializer=common.Reservation.deserialize, + ) + return self._stubs["get_reservation"] + + @property + def list_reservations( + self, + ) -> Callable[ + [admin.ListReservationsRequest], Awaitable[admin.ListReservationsResponse] + ]: + r"""Return a callable for the list reservations method over gRPC. + + Returns the list of reservations for the given + project. + + Returns: + Callable[[~.ListReservationsRequest], + Awaitable[~.ListReservationsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_reservations" not in self._stubs: + self._stubs["list_reservations"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/ListReservations", + request_serializer=admin.ListReservationsRequest.serialize, + response_deserializer=admin.ListReservationsResponse.deserialize, + ) + return self._stubs["list_reservations"] + + @property + def update_reservation( + self, + ) -> Callable[[admin.UpdateReservationRequest], Awaitable[common.Reservation]]: + r"""Return a callable for the update reservation method over gRPC. + + Updates properties of the specified reservation. + + Returns: + Callable[[~.UpdateReservationRequest], + Awaitable[~.Reservation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_reservation" not in self._stubs: + self._stubs["update_reservation"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/UpdateReservation", + request_serializer=admin.UpdateReservationRequest.serialize, + response_deserializer=common.Reservation.deserialize, + ) + return self._stubs["update_reservation"] + + @property + def delete_reservation( + self, + ) -> Callable[[admin.DeleteReservationRequest], Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete reservation method over gRPC. + + Deletes the specified reservation. + + Returns: + Callable[[~.DeleteReservationRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_reservation" not in self._stubs: + self._stubs["delete_reservation"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/DeleteReservation", + request_serializer=admin.DeleteReservationRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_reservation"] + + @property + def list_reservation_topics( + self, + ) -> Callable[ + [admin.ListReservationTopicsRequest], + Awaitable[admin.ListReservationTopicsResponse], + ]: + r"""Return a callable for the list reservation topics method over gRPC. + + Lists the topics attached to the specified + reservation. + + Returns: + Callable[[~.ListReservationTopicsRequest], + Awaitable[~.ListReservationTopicsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_reservation_topics" not in self._stubs: + self._stubs["list_reservation_topics"] = self.grpc_channel.unary_unary( + "/google.cloud.pubsublite.v1.AdminService/ListReservationTopics", + request_serializer=admin.ListReservationTopicsRequest.serialize, + response_deserializer=admin.ListReservationTopicsResponse.deserialize, + ) + return self._stubs["list_reservation_topics"] + __all__ = ("AdminServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/pubsublite_v1/types/__init__.py b/google/cloud/pubsublite_v1/types/__init__.py index 0cad49ad..56e6353e 100644 --- a/google/cloud/pubsublite_v1/types/__init__.py +++ b/google/cloud/pubsublite_v1/types/__init__.py @@ -14,13 +14,20 @@ # limitations under the License. # from .admin import ( + CreateReservationRequest, CreateSubscriptionRequest, CreateTopicRequest, + DeleteReservationRequest, DeleteSubscriptionRequest, DeleteTopicRequest, + GetReservationRequest, GetSubscriptionRequest, GetTopicPartitionsRequest, GetTopicRequest, + ListReservationsRequest, + ListReservationsResponse, + ListReservationTopicsRequest, + ListReservationTopicsResponse, ListSubscriptionsRequest, ListSubscriptionsResponse, ListTopicsRequest, @@ -28,6 +35,7 @@ ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, TopicPartitions, + UpdateReservationRequest, UpdateSubscriptionRequest, UpdateTopicRequest, ) @@ -35,6 +43,7 @@ AttributeValues, Cursor, PubSubMessage, + Reservation, SequencedMessage, Subscription, TimeTarget, @@ -85,13 +94,20 @@ ) __all__ = ( + "CreateReservationRequest", "CreateSubscriptionRequest", "CreateTopicRequest", + "DeleteReservationRequest", "DeleteSubscriptionRequest", "DeleteTopicRequest", + "GetReservationRequest", "GetSubscriptionRequest", "GetTopicPartitionsRequest", "GetTopicRequest", + "ListReservationsRequest", + "ListReservationsResponse", + "ListReservationTopicsRequest", + "ListReservationTopicsResponse", "ListSubscriptionsRequest", "ListSubscriptionsResponse", "ListTopicsRequest", @@ -99,11 +115,13 @@ "ListTopicSubscriptionsRequest", "ListTopicSubscriptionsResponse", "TopicPartitions", + "UpdateReservationRequest", "UpdateSubscriptionRequest", "UpdateTopicRequest", "AttributeValues", "Cursor", "PubSubMessage", + "Reservation", "SequencedMessage", "Subscription", "TimeTarget", diff --git a/google/cloud/pubsublite_v1/types/admin.py b/google/cloud/pubsublite_v1/types/admin.py index 8ad6445b..35edd29e 100644 --- a/google/cloud/pubsublite_v1/types/admin.py +++ b/google/cloud/pubsublite_v1/types/admin.py @@ -38,6 +38,14 @@ "ListSubscriptionsResponse", "UpdateSubscriptionRequest", "DeleteSubscriptionRequest", + "CreateReservationRequest", + "GetReservationRequest", + "ListReservationsRequest", + "ListReservationsResponse", + "UpdateReservationRequest", + "DeleteReservationRequest", + "ListReservationTopicsRequest", + "ListReservationTopicsResponse", }, ) @@ -333,4 +341,164 @@ class DeleteSubscriptionRequest(proto.Message): name = proto.Field(proto.STRING, number=1,) +class CreateReservationRequest(proto.Message): + r"""Request for CreateReservation. + Attributes: + parent (str): + Required. The parent location in which to create the + reservation. Structured like + ``projects/{project_number}/locations/{location}``. + reservation (google.cloud.pubsublite_v1.types.Reservation): + Required. Configuration of the reservation to create. Its + ``name`` field is ignored. + reservation_id (str): + Required. The ID to use for the reservation, which will + become the final component of the reservation's name. + + This value is structured like: ``my-reservation-name``. + """ + + parent = proto.Field(proto.STRING, number=1,) + reservation = proto.Field(proto.MESSAGE, number=2, message=common.Reservation,) + reservation_id = proto.Field(proto.STRING, number=3,) + + +class GetReservationRequest(proto.Message): + r"""Request for GetReservation. + Attributes: + name (str): + Required. The name of the reservation whose configuration to + return. Structured like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + """ + + name = proto.Field(proto.STRING, number=1,) + + +class ListReservationsRequest(proto.Message): + r"""Request for ListReservations. + Attributes: + parent (str): + Required. The parent whose reservations are to be listed. + Structured like + ``projects/{project_number}/locations/{location}``. + page_size (int): + The maximum number of reservations to return. + The service may return fewer than this value. If + unset or zero, all reservations for the parent + will be returned. + page_token (str): + A page token, received from a previous ``ListReservations`` + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + ``ListReservations`` must match the call that provided the + page token. + """ + + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + + +class ListReservationsResponse(proto.Message): + r"""Response for ListReservations. + Attributes: + reservations (Sequence[google.cloud.pubsublite_v1.types.Reservation]): + The list of reservation in the requested + parent. The order of the reservations is + unspecified. + next_page_token (str): + A token that can be sent as ``page_token`` to retrieve the + next page of results. If this field is omitted, there are no + more results. + """ + + @property + def raw_page(self): + return self + + reservations = proto.RepeatedField( + proto.MESSAGE, number=1, message=common.Reservation, + ) + next_page_token = proto.Field(proto.STRING, number=2,) + + +class UpdateReservationRequest(proto.Message): + r"""Request for UpdateReservation. + Attributes: + reservation (google.cloud.pubsublite_v1.types.Reservation): + Required. The reservation to update. Its ``name`` field must + be populated. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. A mask specifying the reservation + fields to change. + """ + + reservation = proto.Field(proto.MESSAGE, number=1, message=common.Reservation,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) + + +class DeleteReservationRequest(proto.Message): + r"""Request for DeleteReservation. + Attributes: + name (str): + Required. The name of the reservation to delete. Structured + like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + """ + + name = proto.Field(proto.STRING, number=1,) + + +class ListReservationTopicsRequest(proto.Message): + r"""Request for ListReservationTopics. + Attributes: + name (str): + Required. The name of the reservation whose topics to list. + Structured like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + page_size (int): + The maximum number of topics to return. The + service may return fewer than this value. + If unset or zero, all topics for the given + reservation will be returned. + page_token (str): + A page token, received from a previous + ``ListReservationTopics`` call. Provide this to retrieve the + subsequent page. + + When paginating, all other parameters provided to + ``ListReservationTopics`` must match the call that provided + the page token. + """ + + name = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + + +class ListReservationTopicsResponse(proto.Message): + r"""Response for ListReservationTopics. + Attributes: + topics (Sequence[str]): + The names of topics attached to the + reservation. The order of the topics is + unspecified. + next_page_token (str): + A token that can be sent as ``page_token`` to retrieve the + next page of results. If this field is omitted, there are no + more results. + """ + + @property + def raw_page(self): + return self + + topics = proto.RepeatedField(proto.STRING, number=1,) + next_page_token = proto.Field(proto.STRING, number=2,) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/pubsublite_v1/types/common.py b/google/cloud/pubsublite_v1/types/common.py index 2869cab8..6c52cd5a 100644 --- a/google/cloud/pubsublite_v1/types/common.py +++ b/google/cloud/pubsublite_v1/types/common.py @@ -26,6 +26,7 @@ "PubSubMessage", "Cursor", "SequencedMessage", + "Reservation", "Topic", "Subscription", "TimeTarget", @@ -110,6 +111,29 @@ class SequencedMessage(proto.Message): size_bytes = proto.Field(proto.INT64, number=4,) +class Reservation(proto.Message): + r"""Metadata about a reservation resource. + + Attributes: + name (str): + The name of the reservation. Structured like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + throughput_capacity (int): + The reserved throughput capacity. Every unit + of throughput capacity is equivalent to 1 MiB/s + of published messages or 2 MiB/s of subscribed + messages. + + Any topics which are declared as using capacity + from a Reservation will consume resources from + this reservation instead of being charged + individually. + """ + + name = proto.Field(proto.STRING, number=1,) + throughput_capacity = proto.Field(proto.INT64, number=2,) + + class Topic(proto.Message): r"""Metadata about a topic resource. @@ -122,6 +146,9 @@ class Topic(proto.Message): retention_config (google.cloud.pubsublite_v1.types.Topic.RetentionConfig): The settings for this topic's message retention. + reservation_config (google.cloud.pubsublite_v1.types.Topic.ReservationConfig): + The settings for this topic's Reservation + usage. """ class PartitionConfig(proto.Message): @@ -192,9 +219,24 @@ class RetentionConfig(proto.Message): per_partition_bytes = proto.Field(proto.INT64, number=1,) period = proto.Field(proto.MESSAGE, number=2, message=duration_pb2.Duration,) + class ReservationConfig(proto.Message): + r"""The settings for this topic's Reservation usage. + + Attributes: + throughput_reservation (str): + The Reservation to use for this topic's throughput capacity. + Structured like: + projects/{project_number}/locations/{location}/reservations/{reservation_id} + """ + + throughput_reservation = proto.Field(proto.STRING, number=1,) + name = proto.Field(proto.STRING, number=1,) partition_config = proto.Field(proto.MESSAGE, number=2, message=PartitionConfig,) retention_config = proto.Field(proto.MESSAGE, number=3, message=RetentionConfig,) + reservation_config = proto.Field( + proto.MESSAGE, number=4, message=ReservationConfig, + ) class Subscription(proto.Message): diff --git a/tests/unit/gapic/pubsublite_v1/test_admin_service.py b/tests/unit/gapic/pubsublite_v1/test_admin_service.py index 526fe784..30e7fd88 100644 --- a/tests/unit/gapic/pubsublite_v1/test_admin_service.py +++ b/tests/unit/gapic/pubsublite_v1/test_admin_service.py @@ -3309,6 +3309,1550 @@ async def test_delete_subscription_flattened_error_async(): ) +def test_create_reservation( + transport: str = "grpc", request_type=admin.CreateReservationRequest +): + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = common.Reservation( + name="name_value", throughput_capacity=2055, + ) + response = client.create_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == admin.CreateReservationRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, common.Reservation) + assert response.name == "name_value" + assert response.throughput_capacity == 2055 + + +def test_create_reservation_from_dict(): + test_create_reservation(request_type=dict) + + +def test_create_reservation_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reservation), "__call__" + ) as call: + client.create_reservation() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == admin.CreateReservationRequest() + + +@pytest.mark.asyncio +async def test_create_reservation_async( + transport: str = "grpc_asyncio", request_type=admin.CreateReservationRequest +): + client = AdminServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + common.Reservation(name="name_value", throughput_capacity=2055,) + ) + response = await client.create_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == admin.CreateReservationRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, common.Reservation) + assert response.name == "name_value" + assert response.throughput_capacity == 2055 + + +@pytest.mark.asyncio +async def test_create_reservation_async_from_dict(): + await test_create_reservation_async(request_type=dict) + + +def test_create_reservation_field_headers(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.CreateReservationRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reservation), "__call__" + ) as call: + call.return_value = common.Reservation() + client.create_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_reservation_field_headers_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.CreateReservationRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reservation), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.Reservation()) + await client.create_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +def test_create_reservation_flattened(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = common.Reservation() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_reservation( + parent="parent_value", + reservation=common.Reservation(name="name_value"), + reservation_id="reservation_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].parent == "parent_value" + assert args[0].reservation == common.Reservation(name="name_value") + assert args[0].reservation_id == "reservation_id_value" + + +def test_create_reservation_flattened_error(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_reservation( + admin.CreateReservationRequest(), + parent="parent_value", + reservation=common.Reservation(name="name_value"), + reservation_id="reservation_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_reservation_flattened_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = common.Reservation() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.Reservation()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_reservation( + parent="parent_value", + reservation=common.Reservation(name="name_value"), + reservation_id="reservation_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].parent == "parent_value" + assert args[0].reservation == common.Reservation(name="name_value") + assert args[0].reservation_id == "reservation_id_value" + + +@pytest.mark.asyncio +async def test_create_reservation_flattened_error_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_reservation( + admin.CreateReservationRequest(), + parent="parent_value", + reservation=common.Reservation(name="name_value"), + reservation_id="reservation_id_value", + ) + + +def test_get_reservation( + transport: str = "grpc", request_type=admin.GetReservationRequest +): + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_reservation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = common.Reservation( + name="name_value", throughput_capacity=2055, + ) + response = client.get_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == admin.GetReservationRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, common.Reservation) + assert response.name == "name_value" + assert response.throughput_capacity == 2055 + + +def test_get_reservation_from_dict(): + test_get_reservation(request_type=dict) + + +def test_get_reservation_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_reservation), "__call__") as call: + client.get_reservation() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == admin.GetReservationRequest() + + +@pytest.mark.asyncio +async def test_get_reservation_async( + transport: str = "grpc_asyncio", request_type=admin.GetReservationRequest +): + client = AdminServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_reservation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + common.Reservation(name="name_value", throughput_capacity=2055,) + ) + response = await client.get_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == admin.GetReservationRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, common.Reservation) + assert response.name == "name_value" + assert response.throughput_capacity == 2055 + + +@pytest.mark.asyncio +async def test_get_reservation_async_from_dict(): + await test_get_reservation_async(request_type=dict) + + +def test_get_reservation_field_headers(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.GetReservationRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_reservation), "__call__") as call: + call.return_value = common.Reservation() + client.get_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_reservation_field_headers_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.GetReservationRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_reservation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.Reservation()) + await client.get_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +def test_get_reservation_flattened(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_reservation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = common.Reservation() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_reservation(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" + + +def test_get_reservation_flattened_error(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_reservation( + admin.GetReservationRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_reservation_flattened_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_reservation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = common.Reservation() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.Reservation()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_reservation(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" + + +@pytest.mark.asyncio +async def test_get_reservation_flattened_error_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_reservation( + admin.GetReservationRequest(), name="name_value", + ) + + +def test_list_reservations( + transport: str = "grpc", request_type=admin.ListReservationsRequest +): + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = admin.ListReservationsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_reservations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == admin.ListReservationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReservationsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_reservations_from_dict(): + test_list_reservations(request_type=dict) + + +def test_list_reservations_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), "__call__" + ) as call: + client.list_reservations() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == admin.ListReservationsRequest() + + +@pytest.mark.asyncio +async def test_list_reservations_async( + transport: str = "grpc_asyncio", request_type=admin.ListReservationsRequest +): + client = AdminServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + admin.ListReservationsResponse(next_page_token="next_page_token_value",) + ) + response = await client.list_reservations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == admin.ListReservationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReservationsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_reservations_async_from_dict(): + await test_list_reservations_async(request_type=dict) + + +def test_list_reservations_field_headers(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.ListReservationsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), "__call__" + ) as call: + call.return_value = admin.ListReservationsResponse() + client.list_reservations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_reservations_field_headers_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.ListReservationsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + admin.ListReservationsResponse() + ) + await client.list_reservations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +def test_list_reservations_flattened(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = admin.ListReservationsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_reservations(parent="parent_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].parent == "parent_value" + + +def test_list_reservations_flattened_error(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_reservations( + admin.ListReservationsRequest(), parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_reservations_flattened_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = admin.ListReservationsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + admin.ListReservationsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_reservations(parent="parent_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].parent == "parent_value" + + +@pytest.mark.asyncio +async def test_list_reservations_flattened_error_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_reservations( + admin.ListReservationsRequest(), parent="parent_value", + ) + + +def test_list_reservations_pager(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + admin.ListReservationsResponse( + reservations=[ + common.Reservation(), + common.Reservation(), + common.Reservation(), + ], + next_page_token="abc", + ), + admin.ListReservationsResponse(reservations=[], next_page_token="def",), + admin.ListReservationsResponse( + reservations=[common.Reservation(),], next_page_token="ghi", + ), + admin.ListReservationsResponse( + reservations=[common.Reservation(), common.Reservation(),], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_reservations(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, common.Reservation) for i in results) + + +def test_list_reservations_pages(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + admin.ListReservationsResponse( + reservations=[ + common.Reservation(), + common.Reservation(), + common.Reservation(), + ], + next_page_token="abc", + ), + admin.ListReservationsResponse(reservations=[], next_page_token="def",), + admin.ListReservationsResponse( + reservations=[common.Reservation(),], next_page_token="ghi", + ), + admin.ListReservationsResponse( + reservations=[common.Reservation(), common.Reservation(),], + ), + RuntimeError, + ) + pages = list(client.list_reservations(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_reservations_async_pager(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + admin.ListReservationsResponse( + reservations=[ + common.Reservation(), + common.Reservation(), + common.Reservation(), + ], + next_page_token="abc", + ), + admin.ListReservationsResponse(reservations=[], next_page_token="def",), + admin.ListReservationsResponse( + reservations=[common.Reservation(),], next_page_token="ghi", + ), + admin.ListReservationsResponse( + reservations=[common.Reservation(), common.Reservation(),], + ), + RuntimeError, + ) + async_pager = await client.list_reservations(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, common.Reservation) for i in responses) + + +@pytest.mark.asyncio +async def test_list_reservations_async_pages(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservations), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + admin.ListReservationsResponse( + reservations=[ + common.Reservation(), + common.Reservation(), + common.Reservation(), + ], + next_page_token="abc", + ), + admin.ListReservationsResponse(reservations=[], next_page_token="def",), + admin.ListReservationsResponse( + reservations=[common.Reservation(),], next_page_token="ghi", + ), + admin.ListReservationsResponse( + reservations=[common.Reservation(), common.Reservation(),], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_reservations(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_update_reservation( + transport: str = "grpc", request_type=admin.UpdateReservationRequest +): + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = common.Reservation( + name="name_value", throughput_capacity=2055, + ) + response = client.update_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == admin.UpdateReservationRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, common.Reservation) + assert response.name == "name_value" + assert response.throughput_capacity == 2055 + + +def test_update_reservation_from_dict(): + test_update_reservation(request_type=dict) + + +def test_update_reservation_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_reservation), "__call__" + ) as call: + client.update_reservation() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == admin.UpdateReservationRequest() + + +@pytest.mark.asyncio +async def test_update_reservation_async( + transport: str = "grpc_asyncio", request_type=admin.UpdateReservationRequest +): + client = AdminServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + common.Reservation(name="name_value", throughput_capacity=2055,) + ) + response = await client.update_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == admin.UpdateReservationRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, common.Reservation) + assert response.name == "name_value" + assert response.throughput_capacity == 2055 + + +@pytest.mark.asyncio +async def test_update_reservation_async_from_dict(): + await test_update_reservation_async(request_type=dict) + + +def test_update_reservation_field_headers(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.UpdateReservationRequest() + + request.reservation.name = "reservation.name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_reservation), "__call__" + ) as call: + call.return_value = common.Reservation() + client.update_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "reservation.name=reservation.name/value",) in kw[ + "metadata" + ] + + +@pytest.mark.asyncio +async def test_update_reservation_field_headers_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.UpdateReservationRequest() + + request.reservation.name = "reservation.name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_reservation), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.Reservation()) + await client.update_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "reservation.name=reservation.name/value",) in kw[ + "metadata" + ] + + +def test_update_reservation_flattened(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = common.Reservation() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_reservation( + reservation=common.Reservation(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].reservation == common.Reservation(name="name_value") + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + + +def test_update_reservation_flattened_error(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_reservation( + admin.UpdateReservationRequest(), + reservation=common.Reservation(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_reservation_flattened_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = common.Reservation() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.Reservation()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_reservation( + reservation=common.Reservation(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].reservation == common.Reservation(name="name_value") + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + + +@pytest.mark.asyncio +async def test_update_reservation_flattened_error_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_reservation( + admin.UpdateReservationRequest(), + reservation=common.Reservation(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +def test_delete_reservation( + transport: str = "grpc", request_type=admin.DeleteReservationRequest +): + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == admin.DeleteReservationRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_reservation_from_dict(): + test_delete_reservation(request_type=dict) + + +def test_delete_reservation_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reservation), "__call__" + ) as call: + client.delete_reservation() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == admin.DeleteReservationRequest() + + +@pytest.mark.asyncio +async def test_delete_reservation_async( + transport: str = "grpc_asyncio", request_type=admin.DeleteReservationRequest +): + client = AdminServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == admin.DeleteReservationRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_reservation_async_from_dict(): + await test_delete_reservation_async(request_type=dict) + + +def test_delete_reservation_field_headers(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.DeleteReservationRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reservation), "__call__" + ) as call: + call.return_value = None + client.delete_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_reservation_field_headers_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.DeleteReservationRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reservation), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_reservation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +def test_delete_reservation_flattened(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_reservation(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" + + +def test_delete_reservation_flattened_error(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_reservation( + admin.DeleteReservationRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_reservation_flattened_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reservation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_reservation(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" + + +@pytest.mark.asyncio +async def test_delete_reservation_flattened_error_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_reservation( + admin.DeleteReservationRequest(), name="name_value", + ) + + +def test_list_reservation_topics( + transport: str = "grpc", request_type=admin.ListReservationTopicsRequest +): + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = admin.ListReservationTopicsResponse( + topics=["topics_value"], next_page_token="next_page_token_value", + ) + response = client.list_reservation_topics(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == admin.ListReservationTopicsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReservationTopicsPager) + assert response.topics == ["topics_value"] + assert response.next_page_token == "next_page_token_value" + + +def test_list_reservation_topics_from_dict(): + test_list_reservation_topics(request_type=dict) + + +def test_list_reservation_topics_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AdminServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), "__call__" + ) as call: + client.list_reservation_topics() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == admin.ListReservationTopicsRequest() + + +@pytest.mark.asyncio +async def test_list_reservation_topics_async( + transport: str = "grpc_asyncio", request_type=admin.ListReservationTopicsRequest +): + client = AdminServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + admin.ListReservationTopicsResponse( + topics=["topics_value"], next_page_token="next_page_token_value", + ) + ) + response = await client.list_reservation_topics(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == admin.ListReservationTopicsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReservationTopicsAsyncPager) + assert response.topics == ["topics_value"] + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_reservation_topics_async_from_dict(): + await test_list_reservation_topics_async(request_type=dict) + + +def test_list_reservation_topics_field_headers(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.ListReservationTopicsRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), "__call__" + ) as call: + call.return_value = admin.ListReservationTopicsResponse() + client.list_reservation_topics(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_reservation_topics_field_headers_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = admin.ListReservationTopicsRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + admin.ListReservationTopicsResponse() + ) + await client.list_reservation_topics(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +def test_list_reservation_topics_flattened(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = admin.ListReservationTopicsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_reservation_topics(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" + + +def test_list_reservation_topics_flattened_error(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_reservation_topics( + admin.ListReservationTopicsRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_list_reservation_topics_flattened_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = admin.ListReservationTopicsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + admin.ListReservationTopicsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_reservation_topics(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" + + +@pytest.mark.asyncio +async def test_list_reservation_topics_flattened_error_async(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_reservation_topics( + admin.ListReservationTopicsRequest(), name="name_value", + ) + + +def test_list_reservation_topics_pager(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + admin.ListReservationTopicsResponse( + topics=[str(), str(), str(),], next_page_token="abc", + ), + admin.ListReservationTopicsResponse(topics=[], next_page_token="def",), + admin.ListReservationTopicsResponse( + topics=[str(),], next_page_token="ghi", + ), + admin.ListReservationTopicsResponse(topics=[str(), str(),],), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", ""),)), + ) + pager = client.list_reservation_topics(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, str) for i in results) + + +def test_list_reservation_topics_pages(): + client = AdminServiceClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + admin.ListReservationTopicsResponse( + topics=[str(), str(), str(),], next_page_token="abc", + ), + admin.ListReservationTopicsResponse(topics=[], next_page_token="def",), + admin.ListReservationTopicsResponse( + topics=[str(),], next_page_token="ghi", + ), + admin.ListReservationTopicsResponse(topics=[str(), str(),],), + RuntimeError, + ) + pages = list(client.list_reservation_topics(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_reservation_topics_async_pager(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + admin.ListReservationTopicsResponse( + topics=[str(), str(), str(),], next_page_token="abc", + ), + admin.ListReservationTopicsResponse(topics=[], next_page_token="def",), + admin.ListReservationTopicsResponse( + topics=[str(),], next_page_token="ghi", + ), + admin.ListReservationTopicsResponse(topics=[str(), str(),],), + RuntimeError, + ) + async_pager = await client.list_reservation_topics(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, str) for i in responses) + + +@pytest.mark.asyncio +async def test_list_reservation_topics_async_pages(): + client = AdminServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reservation_topics), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + admin.ListReservationTopicsResponse( + topics=[str(), str(), str(),], next_page_token="abc", + ), + admin.ListReservationTopicsResponse(topics=[], next_page_token="def",), + admin.ListReservationTopicsResponse( + topics=[str(),], next_page_token="ghi", + ), + admin.ListReservationTopicsResponse(topics=[str(), str(),],), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_reservation_topics(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AdminServiceGrpcTransport( @@ -3418,6 +4962,12 @@ def test_admin_service_base_transport(): "list_subscriptions", "update_subscription", "delete_subscription", + "create_reservation", + "get_reservation", + "list_reservations", + "update_reservation", + "delete_reservation", + "list_reservation_topics", ) for method in methods: with pytest.raises(NotImplementedError): @@ -3829,10 +5379,34 @@ def test_admin_service_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel -def test_subscription_path(): +def test_reservation_path(): project = "squid" location = "clam" - subscription = "whelk" + reservation = "whelk" + expected = "projects/{project}/locations/{location}/reservations/{reservation}".format( + project=project, location=location, reservation=reservation, + ) + actual = AdminServiceClient.reservation_path(project, location, reservation) + assert expected == actual + + +def test_parse_reservation_path(): + expected = { + "project": "octopus", + "location": "oyster", + "reservation": "nudibranch", + } + path = AdminServiceClient.reservation_path(**expected) + + # Check that the path construction is reversible. + actual = AdminServiceClient.parse_reservation_path(path) + assert expected == actual + + +def test_subscription_path(): + project = "cuttlefish" + location = "mussel" + subscription = "winkle" expected = "projects/{project}/locations/{location}/subscriptions/{subscription}".format( project=project, location=location, subscription=subscription, ) @@ -3842,9 +5416,9 @@ def test_subscription_path(): def test_parse_subscription_path(): expected = { - "project": "octopus", - "location": "oyster", - "subscription": "nudibranch", + "project": "nautilus", + "location": "scallop", + "subscription": "abalone", } path = AdminServiceClient.subscription_path(**expected) @@ -3854,9 +5428,9 @@ def test_parse_subscription_path(): def test_topic_path(): - project = "cuttlefish" - location = "mussel" - topic = "winkle" + project = "squid" + location = "clam" + topic = "whelk" expected = "projects/{project}/locations/{location}/topics/{topic}".format( project=project, location=location, topic=topic, ) @@ -3866,9 +5440,9 @@ def test_topic_path(): def test_parse_topic_path(): expected = { - "project": "nautilus", - "location": "scallop", - "topic": "abalone", + "project": "octopus", + "location": "oyster", + "topic": "nudibranch", } path = AdminServiceClient.topic_path(**expected) @@ -3878,7 +5452,7 @@ def test_parse_topic_path(): def test_common_billing_account_path(): - billing_account = "squid" + billing_account = "cuttlefish" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -3888,7 +5462,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "clam", + "billing_account": "mussel", } path = AdminServiceClient.common_billing_account_path(**expected) @@ -3898,7 +5472,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "whelk" + folder = "winkle" expected = "folders/{folder}".format(folder=folder,) actual = AdminServiceClient.common_folder_path(folder) assert expected == actual @@ -3906,7 +5480,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "octopus", + "folder": "nautilus", } path = AdminServiceClient.common_folder_path(**expected) @@ -3916,7 +5490,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "oyster" + organization = "scallop" expected = "organizations/{organization}".format(organization=organization,) actual = AdminServiceClient.common_organization_path(organization) assert expected == actual @@ -3924,7 +5498,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nudibranch", + "organization": "abalone", } path = AdminServiceClient.common_organization_path(**expected) @@ -3934,7 +5508,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "cuttlefish" + project = "squid" expected = "projects/{project}".format(project=project,) actual = AdminServiceClient.common_project_path(project) assert expected == actual @@ -3942,7 +5516,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "mussel", + "project": "clam", } path = AdminServiceClient.common_project_path(**expected) @@ -3952,8 +5526,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "winkle" - location = "nautilus" + project = "whelk" + location = "octopus" expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -3963,8 +5537,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "scallop", - "location": "abalone", + "project": "oyster", + "location": "nudibranch", } path = AdminServiceClient.common_location_path(**expected)