From e727cc0e98e37d55882215182f86c2a7d23154ef Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sun, 22 Sep 2024 20:52:35 -0400 Subject: [PATCH] feat: [google-cloud-gdchardwaremanagement] add an order type field to distinguish a fulfillment request from a sales inquiry (#13090) BEGIN_COMMIT_OVERRIDE feat: add an order type field to distinguish a fulfillment request from a sales inquiry feat: add support to mark comments as read or unread feat: rename zone state signal READY_FOR_SITE_TURNUP to FACTORY_TURNUP_CHECKS_PASSED docs: clarify how access_times are used END_COMMIT_OVERRIDE - [ ] Regenerate this pull request now. feat: add support to mark comments as read or unread feat: rename zone state signal READY_FOR_SITE_TURNUP to FACTORY_TURNUP_CHECKS_PASSED docs: clarify how access_times are used PiperOrigin-RevId: 675275984 Source-Link: https://github.com/googleapis/googleapis/commit/fde103ca32090688564bc86d8a430450d59dded7 Source-Link: https://github.com/googleapis/googleapis-gen/commit/a58cb7449fccaa7e9c76bd5a137e79aefa45ede7 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWdkY2hhcmR3YXJlbWFuYWdlbWVudC8uT3dsQm90LnlhbWwiLCJoIjoiYTU4Y2I3NDQ5ZmNjYWE3ZTljNzZiZDVhMTM3ZTc5YWVmYTQ1ZWRlNyJ9 --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: ohmayr <omairnaveed@ymail.com> --- .../cloud/gdchardwaremanagement/__init__.py | 6 + .../gdchardwaremanagement_v1alpha/__init__.py | 6 + .../gapic_metadata.json | 15 + .../gdc_hardware_management/async_client.py | 120 + .../gdc_hardware_management/client.py | 117 + .../transports/base.py | 14 + .../transports/grpc.py | 31 + .../transports/grpc_asyncio.py | 36 + .../transports/rest.py | 134 + .../types/__init__.py | 6 + .../types/resources.py | 145 +- .../types/service.py | 85 + ...nagement_record_action_on_comment_async.py | 53 + ...anagement_record_action_on_comment_sync.py | 53 + ...e.cloud.gdchardwaremanagement.v1alpha.json | 169 + ..._gdchardwaremanagement_v1alpha_keywords.py | 3 +- .../test_gdc_hardware_management.py | 8956 +++++++++-------- 17 files changed, 5851 insertions(+), 4098 deletions(-) create mode 100644 packages/google-cloud-gdchardwaremanagement/samples/generated_samples/gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_async.py create mode 100644 packages/google-cloud-gdchardwaremanagement/samples/generated_samples/gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_sync.py diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement/__init__.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement/__init__.py index 8f1261e786ed..6804d0c2e133 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement/__init__.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement/__init__.py @@ -29,6 +29,7 @@ Comment, Contact, Dimensions, + Entity, Hardware, HardwareConfig, HardwareGroup, @@ -44,6 +45,7 @@ SkuConfig, SkuInstance, Subnet, + SubscriptionConfig, TimePeriod, Zone, ZoneNetworkConfig, @@ -84,6 +86,7 @@ ListZonesRequest, ListZonesResponse, OperationMetadata, + RecordActionOnCommentRequest, SignalZoneStateRequest, SubmitOrderRequest, UpdateHardwareGroupRequest, @@ -114,9 +117,11 @@ "SkuConfig", "SkuInstance", "Subnet", + "SubscriptionConfig", "TimePeriod", "Zone", "ZoneNetworkConfig", + "Entity", "PowerSupply", "CreateCommentRequest", "CreateHardwareGroupRequest", @@ -153,6 +158,7 @@ "ListZonesRequest", "ListZonesResponse", "OperationMetadata", + "RecordActionOnCommentRequest", "SignalZoneStateRequest", "SubmitOrderRequest", "UpdateHardwareGroupRequest", diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/__init__.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/__init__.py index adfdd5d5be4b..4be645a5703c 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/__init__.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/__init__.py @@ -27,6 +27,7 @@ Comment, Contact, Dimensions, + Entity, Hardware, HardwareConfig, HardwareGroup, @@ -42,6 +43,7 @@ SkuConfig, SkuInstance, Subnet, + SubscriptionConfig, TimePeriod, Zone, ZoneNetworkConfig, @@ -82,6 +84,7 @@ ListZonesRequest, ListZonesResponse, OperationMetadata, + RecordActionOnCommentRequest, SignalZoneStateRequest, SubmitOrderRequest, UpdateHardwareGroupRequest, @@ -107,6 +110,7 @@ "DeleteOrderRequest", "DeleteZoneRequest", "Dimensions", + "Entity", "GDCHardwareManagementClient", "GetChangeLogEntryRequest", "GetCommentRequest", @@ -143,6 +147,7 @@ "OrganizationContact", "PowerSupply", "RackSpace", + "RecordActionOnCommentRequest", "SignalZoneStateRequest", "Site", "Sku", @@ -150,6 +155,7 @@ "SkuInstance", "SubmitOrderRequest", "Subnet", + "SubscriptionConfig", "TimePeriod", "UpdateHardwareGroupRequest", "UpdateHardwareRequest", diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/gapic_metadata.json b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/gapic_metadata.json index b5713b6e1b21..3d9830bcaec9 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/gapic_metadata.json +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/gapic_metadata.json @@ -140,6 +140,11 @@ "list_zones" ] }, + "RecordActionOnComment": { + "methods": [ + "record_action_on_comment" + ] + }, "SignalZoneState": { "methods": [ "signal_zone_state" @@ -310,6 +315,11 @@ "list_zones" ] }, + "RecordActionOnComment": { + "methods": [ + "record_action_on_comment" + ] + }, "SignalZoneState": { "methods": [ "signal_zone_state" @@ -480,6 +490,11 @@ "list_zones" ] }, + "RecordActionOnComment": { + "methods": [ + "record_action_on_comment" + ] + }, "SignalZoneState": { "methods": [ "signal_zone_state" diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/async_client.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/async_client.py index b0755c816a88..7c2f13b80903 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/async_client.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/async_client.py @@ -3237,6 +3237,126 @@ async def sample_create_comment(): # Done; return the response. return response + async def record_action_on_comment( + self, + request: Optional[Union[service.RecordActionOnCommentRequest, dict]] = None, + *, + name: Optional[str] = None, + action_type: Optional[service.RecordActionOnCommentRequest.ActionType] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> resources.Comment: + r"""Record Action on a Comment. If the Action specified + in the request is READ, the viewed time in the comment + is set to the time the request was received. If the + comment is already marked as read, subsequent calls will + be ignored. If the Action is UNREAD, the viewed time is + cleared from the comment. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import gdchardwaremanagement_v1alpha + + async def sample_record_action_on_comment(): + # Create a client + client = gdchardwaremanagement_v1alpha.GDCHardwareManagementAsyncClient() + + # Initialize request argument(s) + request = gdchardwaremanagement_v1alpha.RecordActionOnCommentRequest( + name="name_value", + action_type="UNREAD", + ) + + # Make the request + response = await client.record_action_on_comment(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.gdchardwaremanagement_v1alpha.types.RecordActionOnCommentRequest, dict]]): + The request object. A request to record an action on a + comment. + name (:class:`str`): + Required. The name of the comment. Format: + ``projects/{project}/locations/{location}/orders/{order}/comments/{comment}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + action_type (:class:`google.cloud.gdchardwaremanagement_v1alpha.types.RecordActionOnCommentRequest.ActionType`): + Required. The action type of the + recorded action. + + This corresponds to the ``action_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): 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.gdchardwaremanagement_v1alpha.types.Comment: + A comment on an order. + """ + # Create or coerce a protobuf request object. + # - Quick 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, action_type]) + 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." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, service.RecordActionOnCommentRequest): + request = service.RecordActionOnCommentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if action_type is not None: + request.action_type = action_type + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.record_action_on_comment + ] + + # 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),)), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + async def list_change_log_entries( self, request: Optional[Union[service.ListChangeLogEntriesRequest, dict]] = None, diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/client.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/client.py index 44e392dffb0f..fe8281c62c7d 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/client.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/client.py @@ -3734,6 +3734,123 @@ def sample_create_comment(): # Done; return the response. return response + def record_action_on_comment( + self, + request: Optional[Union[service.RecordActionOnCommentRequest, dict]] = None, + *, + name: Optional[str] = None, + action_type: Optional[service.RecordActionOnCommentRequest.ActionType] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> resources.Comment: + r"""Record Action on a Comment. If the Action specified + in the request is READ, the viewed time in the comment + is set to the time the request was received. If the + comment is already marked as read, subsequent calls will + be ignored. If the Action is UNREAD, the viewed time is + cleared from the comment. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import gdchardwaremanagement_v1alpha + + def sample_record_action_on_comment(): + # Create a client + client = gdchardwaremanagement_v1alpha.GDCHardwareManagementClient() + + # Initialize request argument(s) + request = gdchardwaremanagement_v1alpha.RecordActionOnCommentRequest( + name="name_value", + action_type="UNREAD", + ) + + # Make the request + response = client.record_action_on_comment(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.gdchardwaremanagement_v1alpha.types.RecordActionOnCommentRequest, dict]): + The request object. A request to record an action on a + comment. + name (str): + Required. The name of the comment. Format: + ``projects/{project}/locations/{location}/orders/{order}/comments/{comment}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + action_type (google.cloud.gdchardwaremanagement_v1alpha.types.RecordActionOnCommentRequest.ActionType): + Required. The action type of the + recorded action. + + This corresponds to the ``action_type`` 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.gdchardwaremanagement_v1alpha.types.Comment: + A comment on an order. + """ + # Create or coerce a protobuf request object. + # - Quick 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, action_type]) + 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." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, service.RecordActionOnCommentRequest): + request = service.RecordActionOnCommentRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if action_type is not None: + request.action_type = action_type + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.record_action_on_comment] + + # 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),)), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + def list_change_log_entries( self, request: Optional[Union[service.ListChangeLogEntriesRequest, dict]] = None, diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/base.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/base.py index 2aacf3ed6d5a..1af0337b882d 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/base.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/base.py @@ -407,6 +407,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.record_action_on_comment: gapic_v1.method.wrap_method( + self.record_action_on_comment, + default_timeout=None, + client_info=client_info, + ), self.list_change_log_entries: gapic_v1.method.wrap_method( self.list_change_log_entries, default_retry=retries.Retry( @@ -753,6 +758,15 @@ def create_comment( ]: raise NotImplementedError() + @property + def record_action_on_comment( + self, + ) -> Callable[ + [service.RecordActionOnCommentRequest], + Union[resources.Comment, Awaitable[resources.Comment]], + ]: + raise NotImplementedError() + @property def list_change_log_entries( self, diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc.py index 50edb419994a..a9126a268ef9 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc.py @@ -845,6 +845,37 @@ def create_comment( ) return self._stubs["create_comment"] + @property + def record_action_on_comment( + self, + ) -> Callable[[service.RecordActionOnCommentRequest], resources.Comment]: + r"""Return a callable for the record action on comment method over gRPC. + + Record Action on a Comment. If the Action specified + in the request is READ, the viewed time in the comment + is set to the time the request was received. If the + comment is already marked as read, subsequent calls will + be ignored. If the Action is UNREAD, the viewed time is + cleared from the comment. + + Returns: + Callable[[~.RecordActionOnCommentRequest], + ~.Comment]: + 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 "record_action_on_comment" not in self._stubs: + self._stubs["record_action_on_comment"] = self.grpc_channel.unary_unary( + "/google.cloud.gdchardwaremanagement.v1alpha.GDCHardwareManagement/RecordActionOnComment", + request_serializer=service.RecordActionOnCommentRequest.serialize, + response_deserializer=resources.Comment.deserialize, + ) + return self._stubs["record_action_on_comment"] + @property def list_change_log_entries( self, diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc_asyncio.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc_asyncio.py index 1dfcb6395532..12579c465cb7 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc_asyncio.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc_asyncio.py @@ -868,6 +868,37 @@ def create_comment( ) return self._stubs["create_comment"] + @property + def record_action_on_comment( + self, + ) -> Callable[[service.RecordActionOnCommentRequest], Awaitable[resources.Comment]]: + r"""Return a callable for the record action on comment method over gRPC. + + Record Action on a Comment. If the Action specified + in the request is READ, the viewed time in the comment + is set to the time the request was received. If the + comment is already marked as read, subsequent calls will + be ignored. If the Action is UNREAD, the viewed time is + cleared from the comment. + + Returns: + Callable[[~.RecordActionOnCommentRequest], + Awaitable[~.Comment]]: + 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 "record_action_on_comment" not in self._stubs: + self._stubs["record_action_on_comment"] = self.grpc_channel.unary_unary( + "/google.cloud.gdchardwaremanagement.v1alpha.GDCHardwareManagement/RecordActionOnComment", + request_serializer=service.RecordActionOnCommentRequest.serialize, + response_deserializer=resources.Comment.deserialize, + ) + return self._stubs["record_action_on_comment"] + @property def list_change_log_entries( self, @@ -1411,6 +1442,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.record_action_on_comment: gapic_v1.method_async.wrap_method( + self.record_action_on_comment, + default_timeout=None, + client_info=client_info, + ), self.list_change_log_entries: gapic_v1.method_async.wrap_method( self.list_change_log_entries, default_retry=retries.AsyncRetry( diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/rest.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/rest.py index b95064ee417e..25c96778ddb7 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/rest.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/rest.py @@ -280,6 +280,14 @@ def post_list_zones(self, response): logging.log(f"Received response: {response}") return response + def pre_record_action_on_comment(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_record_action_on_comment(self, response): + logging.log(f"Received response: {response}") + return response + def pre_signal_zone_state(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -892,6 +900,29 @@ def post_list_zones( """ return response + def pre_record_action_on_comment( + self, + request: service.RecordActionOnCommentRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[service.RecordActionOnCommentRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for record_action_on_comment + + Override in a subclass to manipulate the request or metadata + before they are sent to the GDCHardwareManagement server. + """ + return request, metadata + + def post_record_action_on_comment( + self, response: resources.Comment + ) -> resources.Comment: + """Post-rpc interceptor for record_action_on_comment + + Override in a subclass to manipulate the response + after it is returned by the GDCHardwareManagement server but before + it is returned to user code. + """ + return response + def pre_signal_zone_state( self, request: service.SignalZoneStateRequest, @@ -3615,6 +3646,101 @@ def __call__( resp = self._interceptor.post_list_zones(resp) return resp + class _RecordActionOnComment(GDCHardwareManagementRestStub): + def __hash__(self): + return hash("RecordActionOnComment") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: service.RecordActionOnCommentRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> resources.Comment: + r"""Call the record action on comment method over HTTP. + + Args: + request (~.service.RecordActionOnCommentRequest): + The request object. A request to record an action on a + comment. + 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: + ~.resources.Comment: + A comment on an order. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1alpha/{name=projects/*/locations/*/orders/*/comments/*}:recordAction", + "body": "*", + }, + ] + request, metadata = self._interceptor.pre_record_action_on_comment( + request, metadata + ) + pb_request = service.RecordActionOnCommentRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = resources.Comment() + pb_resp = resources.Comment.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_record_action_on_comment(resp) + return resp + class _SignalZoneState(GDCHardwareManagementRestStub): def __hash__(self): return hash("SignalZoneState") @@ -4483,6 +4609,14 @@ def list_zones( # In C++ this would require a dynamic_cast return self._ListZones(self._session, self._host, self._interceptor) # type: ignore + @property + def record_action_on_comment( + self, + ) -> Callable[[service.RecordActionOnCommentRequest], resources.Comment]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._RecordActionOnComment(self._session, self._host, self._interceptor) # type: ignore + @property def signal_zone_state( self, diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/__init__.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/__init__.py index 920359d3bd38..b800bd4e5181 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/__init__.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/__init__.py @@ -18,6 +18,7 @@ Comment, Contact, Dimensions, + Entity, Hardware, HardwareConfig, HardwareGroup, @@ -33,6 +34,7 @@ SkuConfig, SkuInstance, Subnet, + SubscriptionConfig, TimePeriod, Zone, ZoneNetworkConfig, @@ -73,6 +75,7 @@ ListZonesRequest, ListZonesResponse, OperationMetadata, + RecordActionOnCommentRequest, SignalZoneStateRequest, SubmitOrderRequest, UpdateHardwareGroupRequest, @@ -101,9 +104,11 @@ "SkuConfig", "SkuInstance", "Subnet", + "SubscriptionConfig", "TimePeriod", "Zone", "ZoneNetworkConfig", + "Entity", "PowerSupply", "CreateCommentRequest", "CreateHardwareGroupRequest", @@ -140,6 +145,7 @@ "ListZonesRequest", "ListZonesResponse", "OperationMetadata", + "RecordActionOnCommentRequest", "SignalZoneStateRequest", "SubmitOrderRequest", "UpdateHardwareGroupRequest", diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/resources.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/resources.py index 54d902b9ae68..9cf90c8096c5 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/resources.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/resources.py @@ -29,6 +29,7 @@ package="google.cloud.gdchardwaremanagement.v1alpha", manifest={ "PowerSupply", + "Entity", "Order", "Site", "HardwareGroup", @@ -50,6 +51,7 @@ "Dimensions", "RackSpace", "HardwareLocation", + "SubscriptionConfig", }, ) @@ -70,6 +72,25 @@ class PowerSupply(proto.Enum): POWER_SUPPLY_DC = 2 +class Entity(proto.Enum): + r"""Entity is used to denote an organization or party. + + Values: + ENTITY_UNSPECIFIED (0): + Entity is unspecified. + GOOGLE (1): + Google. + CUSTOMER (2): + Customer. + VENDOR (3): + Vendor. + """ + ENTITY_UNSPECIFIED = 0 + GOOGLE = 1 + CUSTOMER = 2 + VENDOR = 3 + + class Order(proto.Message): r"""An order for GDC hardware. @@ -140,6 +161,9 @@ class State(proto.Enum): has not been submitted yet. SUBMITTED (2): Order has been submitted to Google. + INFO_COMPLETE (12): + All information required from the customer + for fulfillment of the order is complete. ACCEPTED (3): Order has been accepted by Google. ADDITIONAL_INFO_NEEDED (4): @@ -167,6 +191,7 @@ class State(proto.Enum): STATE_UNSPECIFIED = 0 DRAFT = 1 SUBMITTED = 2 + INFO_COMPLETE = 12 ACCEPTED = 3 ADDITIONAL_INFO_NEEDED = 4 BUILDING = 5 @@ -297,17 +322,30 @@ class Site(proto.Message): Optional. The time periods when the site is accessible. If this field is empty, the site is accessible at all times. + + This field is used by Google to schedule the + initial installation as well as any later + hardware maintenance. You may update this at any + time. For example, if the initial installation + is requested during off-hours but maintenance + should be performed during regular business + hours, you should update the access times after + initial installation is complete. notes (str): Optional. Any additional notes for this Site. Please include information about: - - - security or access restrictions - - any regulations affecting the technicians - visiting the site - - any special process or approval required to - move the equipment - - whether a representative will be available - during site visits + - security or access restrictions + - any regulations affecting the technicians + visiting the site + - any special process or approval required to + move the equipment + - whether a representative will be available + during site visits + + customer_site_id (str): + Optional. Customer defined identifier for + this Site. This can be used to identify the site + in the customer's own systems. """ name: str = proto.Field( @@ -355,6 +393,10 @@ class Site(proto.Message): proto.STRING, number=27, ) + customer_site_id: str = proto.Field( + proto.STRING, + number=28, + ) class HardwareGroup(proto.Message): @@ -679,6 +721,14 @@ class Comment(proto.Message): text (str): Required. Text of this comment. The length of text must be <= 1000 characters. + customer_viewed_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp of the first time this + comment was viewed by the customer. If the + comment wasn't viewed then this timestamp will + be unset. + author_entity (google.cloud.gdchardwaremanagement_v1alpha.types.Entity): + Output only. The entity the author belongs + to. """ name: str = proto.Field( @@ -703,6 +753,16 @@ class Comment(proto.Message): proto.STRING, number=5, ) + customer_viewed_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + author_entity: "Entity" = proto.Field( + proto.ENUM, + number=7, + enum="Entity", + ) class ChangeLogEntry(proto.Message): @@ -881,6 +941,9 @@ class Zone(proto.Message): globally_unique_id (str): Output only. Globally unique identifier generated for this Edge Zone. + subscription_configs (MutableSequence[google.cloud.gdchardwaremanagement_v1alpha.types.SubscriptionConfig]): + Output only. Subscription configurations for + this zone. """ class State(proto.Enum): @@ -960,6 +1023,11 @@ class State(proto.Enum): proto.STRING, number=12, ) + subscription_configs: MutableSequence["SubscriptionConfig"] = proto.RepeatedField( + proto.MESSAGE, + number=13, + message="SubscriptionConfig", + ) class OrganizationContact(proto.Message): @@ -1502,4 +1570,65 @@ class HardwareLocation(proto.Message): ) +class SubscriptionConfig(proto.Message): + r"""A message to store a subscription configuration. + + Attributes: + subscription_id (str): + Output only. The unique identifier of the + subscription. + billing_id (str): + Output only. The Google Cloud Billing ID that + the subscription is created under. + state (google.cloud.gdchardwaremanagement_v1alpha.types.SubscriptionConfig.SubscriptionState): + Output only. The current state of the + subscription. + """ + + class SubscriptionState(proto.Enum): + r"""Enum to represent the state of the subscription. + + Values: + SUBSCRIPTION_STATE_UNSPECIFIED (0): + State is unspecified. + ACTIVE (1): + Active state means that the subscription has + been created successfully and billing is + happening. + INACTIVE (2): + Inactive means that the subscription has been + created successfully, but billing has not + started yet. + ERROR (3): + The subscription is in an erroneous state. + FAILED_TO_RETRIEVE (4): + The subscription state failed to be + retrieved. This may be a transient issue. The + user should retry the request. + COMPLETED (5): + The subscription has been completed, because + it has reached the end date. + """ + SUBSCRIPTION_STATE_UNSPECIFIED = 0 + ACTIVE = 1 + INACTIVE = 2 + ERROR = 3 + FAILED_TO_RETRIEVE = 4 + COMPLETED = 5 + + subscription_id: str = proto.Field( + proto.STRING, + number=1, + ) + billing_id: str = proto.Field( + proto.STRING, + number=2, + ) + state: SubscriptionState = proto.Field( + proto.ENUM, + number=3, + enum=SubscriptionState, + ) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/service.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/service.py index 9821128023c7..88c0224f1a48 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/service.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/types/service.py @@ -54,6 +54,7 @@ "ListCommentsResponse", "GetCommentRequest", "CreateCommentRequest", + "RecordActionOnCommentRequest", "ListChangeLogEntriesRequest", "ListChangeLogEntriesResponse", "GetChangeLogEntryRequest", @@ -280,8 +281,44 @@ class SubmitOrderRequest(proto.Message): request_id (str): Optional. An optional unique identifier for this request. See `AIP-155 <https://google.aip.dev/155>`__. + type_ (google.cloud.gdchardwaremanagement_v1alpha.types.SubmitOrderRequest.Type): + Optional. Type of this request. If unset, the request type + is assumed to be ``INFO_PENDING``. """ + class Type(proto.Enum): + r"""Valid types of submit order request. + + Values: + TYPE_UNSPECIFIED (0): + Request type is unspecified. This should not + be used. + INFO_PENDING (1): + Use this request type to submit your order + and initiate conversation with Google. After + this submission, you will not be able to modify + the number or SKU of your ordered hardware. + Please note that this order will not be ready + for fulfillment yet until you provide more + information, such as zone network configuration, + hardware physical and installation information, + etc. + If you are submitting an order for a SKU type of + RACK, please use this request type, as + additional information will be required outside + of the API. + INFO_COMPLETE (2): + Use this request type if and when you are ready to submit + your order for fulfillment. In addition to the information + required for ``INFO_PENDING``, the order must contain all + required information, such as zone network configuration, + hardware physical and installation information, etc. Further + changes to any order information will no longer be allowed. + """ + TYPE_UNSPECIFIED = 0 + INFO_PENDING = 1 + INFO_COMPLETE = 2 + name: str = proto.Field( proto.STRING, number=1, @@ -290,6 +327,11 @@ class SubmitOrderRequest(proto.Message): proto.STRING, number=2, ) + type_: Type = proto.Field( + proto.ENUM, + number=3, + enum=Type, + ) class ListSitesRequest(proto.Message): @@ -963,6 +1005,44 @@ class CreateCommentRequest(proto.Message): ) +class RecordActionOnCommentRequest(proto.Message): + r"""A request to record an action on a comment. + + Attributes: + name (str): + Required. The name of the comment. Format: + ``projects/{project}/locations/{location}/orders/{order}/comments/{comment}`` + action_type (google.cloud.gdchardwaremanagement_v1alpha.types.RecordActionOnCommentRequest.ActionType): + Required. The action type of the recorded + action. + """ + + class ActionType(proto.Enum): + r"""Valid action types of Comment. + + Values: + ACTION_TYPE_UNSPECIFIED (0): + Action is unspecified. + READ (1): + Mark comment as read. + UNREAD (2): + Mark comment as unread. + """ + ACTION_TYPE_UNSPECIFIED = 0 + READ = 1 + UNREAD = 2 + + name: str = proto.Field( + proto.STRING, + number=1, + ) + action_type: ActionType = proto.Field( + proto.ENUM, + number=2, + enum=ActionType, + ) + + class ListChangeLogEntriesRequest(proto.Message): r"""A request to list change log entries. @@ -1354,12 +1434,17 @@ class StateSignal(proto.Enum): Values: STATE_SIGNAL_UNSPECIFIED (0): State signal of the zone is unspecified. + FACTORY_TURNUP_CHECKS_PASSED (1): + The Zone is ready for site turnup. READY_FOR_SITE_TURNUP (1): The Zone is ready for site turnup. + Deprecated, but not deleted. FACTORY_TURNUP_CHECKS_FAILED (2): The Zone failed in factory turnup checks. """ + _pb_options = {"allow_alias": True} STATE_SIGNAL_UNSPECIFIED = 0 + FACTORY_TURNUP_CHECKS_PASSED = 1 READY_FOR_SITE_TURNUP = 1 FACTORY_TURNUP_CHECKS_FAILED = 2 diff --git a/packages/google-cloud-gdchardwaremanagement/samples/generated_samples/gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_async.py b/packages/google-cloud-gdchardwaremanagement/samples/generated_samples/gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_async.py new file mode 100644 index 000000000000..64fa35ff6d8a --- /dev/null +++ b/packages/google-cloud-gdchardwaremanagement/samples/generated_samples/gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RecordActionOnComment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-gdchardwaremanagement + + +# [START gdchardwaremanagement_v1alpha_generated_GDCHardwareManagement_RecordActionOnComment_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import gdchardwaremanagement_v1alpha + + +async def sample_record_action_on_comment(): + # Create a client + client = gdchardwaremanagement_v1alpha.GDCHardwareManagementAsyncClient() + + # Initialize request argument(s) + request = gdchardwaremanagement_v1alpha.RecordActionOnCommentRequest( + name="name_value", + action_type="UNREAD", + ) + + # Make the request + response = await client.record_action_on_comment(request=request) + + # Handle the response + print(response) + +# [END gdchardwaremanagement_v1alpha_generated_GDCHardwareManagement_RecordActionOnComment_async] diff --git a/packages/google-cloud-gdchardwaremanagement/samples/generated_samples/gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_sync.py b/packages/google-cloud-gdchardwaremanagement/samples/generated_samples/gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_sync.py new file mode 100644 index 000000000000..6658459e3cda --- /dev/null +++ b/packages/google-cloud-gdchardwaremanagement/samples/generated_samples/gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RecordActionOnComment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-gdchardwaremanagement + + +# [START gdchardwaremanagement_v1alpha_generated_GDCHardwareManagement_RecordActionOnComment_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import gdchardwaremanagement_v1alpha + + +def sample_record_action_on_comment(): + # Create a client + client = gdchardwaremanagement_v1alpha.GDCHardwareManagementClient() + + # Initialize request argument(s) + request = gdchardwaremanagement_v1alpha.RecordActionOnCommentRequest( + name="name_value", + action_type="UNREAD", + ) + + # Make the request + response = client.record_action_on_comment(request=request) + + # Handle the response + print(response) + +# [END gdchardwaremanagement_v1alpha_generated_GDCHardwareManagement_RecordActionOnComment_sync] diff --git a/packages/google-cloud-gdchardwaremanagement/samples/generated_samples/snippet_metadata_google.cloud.gdchardwaremanagement.v1alpha.json b/packages/google-cloud-gdchardwaremanagement/samples/generated_samples/snippet_metadata_google.cloud.gdchardwaremanagement.v1alpha.json index 9716952b0d31..588b33c7fb6e 100644 --- a/packages/google-cloud-gdchardwaremanagement/samples/generated_samples/snippet_metadata_google.cloud.gdchardwaremanagement.v1alpha.json +++ b/packages/google-cloud-gdchardwaremanagement/samples/generated_samples/snippet_metadata_google.cloud.gdchardwaremanagement.v1alpha.json @@ -4293,6 +4293,175 @@ ], "title": "gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_list_zones_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.gdchardwaremanagement_v1alpha.GDCHardwareManagementAsyncClient", + "shortName": "GDCHardwareManagementAsyncClient" + }, + "fullName": "google.cloud.gdchardwaremanagement_v1alpha.GDCHardwareManagementAsyncClient.record_action_on_comment", + "method": { + "fullName": "google.cloud.gdchardwaremanagement.v1alpha.GDCHardwareManagement.RecordActionOnComment", + "service": { + "fullName": "google.cloud.gdchardwaremanagement.v1alpha.GDCHardwareManagement", + "shortName": "GDCHardwareManagement" + }, + "shortName": "RecordActionOnComment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.gdchardwaremanagement_v1alpha.types.RecordActionOnCommentRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "action_type", + "type": "google.cloud.gdchardwaremanagement_v1alpha.types.RecordActionOnCommentRequest.ActionType" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.gdchardwaremanagement_v1alpha.types.Comment", + "shortName": "record_action_on_comment" + }, + "description": "Sample for RecordActionOnComment", + "file": "gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "gdchardwaremanagement_v1alpha_generated_GDCHardwareManagement_RecordActionOnComment_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.gdchardwaremanagement_v1alpha.GDCHardwareManagementClient", + "shortName": "GDCHardwareManagementClient" + }, + "fullName": "google.cloud.gdchardwaremanagement_v1alpha.GDCHardwareManagementClient.record_action_on_comment", + "method": { + "fullName": "google.cloud.gdchardwaremanagement.v1alpha.GDCHardwareManagement.RecordActionOnComment", + "service": { + "fullName": "google.cloud.gdchardwaremanagement.v1alpha.GDCHardwareManagement", + "shortName": "GDCHardwareManagement" + }, + "shortName": "RecordActionOnComment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.gdchardwaremanagement_v1alpha.types.RecordActionOnCommentRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "action_type", + "type": "google.cloud.gdchardwaremanagement_v1alpha.types.RecordActionOnCommentRequest.ActionType" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.gdchardwaremanagement_v1alpha.types.Comment", + "shortName": "record_action_on_comment" + }, + "description": "Sample for RecordActionOnComment", + "file": "gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "gdchardwaremanagement_v1alpha_generated_GDCHardwareManagement_RecordActionOnComment_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "gdchardwaremanagement_v1alpha_generated_gdc_hardware_management_record_action_on_comment_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/packages/google-cloud-gdchardwaremanagement/scripts/fixup_gdchardwaremanagement_v1alpha_keywords.py b/packages/google-cloud-gdchardwaremanagement/scripts/fixup_gdchardwaremanagement_v1alpha_keywords.py index 0a8496e2ccc3..c10e8cef3d54 100644 --- a/packages/google-cloud-gdchardwaremanagement/scripts/fixup_gdchardwaremanagement_v1alpha_keywords.py +++ b/packages/google-cloud-gdchardwaremanagement/scripts/fixup_gdchardwaremanagement_v1alpha_keywords.py @@ -65,8 +65,9 @@ class gdchardwaremanagementCallTransformer(cst.CSTTransformer): 'list_sites': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), 'list_skus': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), 'list_zones': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'record_action_on_comment': ('name', 'action_type', ), 'signal_zone_state': ('name', 'state_signal', 'request_id', ), - 'submit_order': ('name', 'request_id', ), + 'submit_order': ('name', 'request_id', 'type_', ), 'update_hardware': ('update_mask', 'hardware', 'request_id', ), 'update_hardware_group': ('update_mask', 'hardware_group', 'request_id', ), 'update_order': ('update_mask', 'order', 'request_id', ), diff --git a/packages/google-cloud-gdchardwaremanagement/tests/unit/gapic/gdchardwaremanagement_v1alpha/test_gdc_hardware_management.py b/packages/google-cloud-gdchardwaremanagement/tests/unit/gapic/gdchardwaremanagement_v1alpha/test_gdc_hardware_management.py index 72d9a360aa19..dc7856c427c9 100644 --- a/packages/google-cloud-gdchardwaremanagement/tests/unit/gapic/gdchardwaremanagement_v1alpha/test_gdc_hardware_management.py +++ b/packages/google-cloud-gdchardwaremanagement/tests/unit/gapic/gdchardwaremanagement_v1alpha/test_gdc_hardware_management.py @@ -4275,6 +4275,7 @@ def test_get_site(request_type, transport: str = "grpc"): description="description_value", google_maps_pin_uri="google_maps_pin_uri_value", notes="notes_value", + customer_site_id="customer_site_id_value", ) response = client.get_site(request) @@ -4291,6 +4292,7 @@ def test_get_site(request_type, transport: str = "grpc"): assert response.description == "description_value" assert response.google_maps_pin_uri == "google_maps_pin_uri_value" assert response.notes == "notes_value" + assert response.customer_site_id == "customer_site_id_value" def test_get_site_empty_call(): @@ -4394,6 +4396,7 @@ async def test_get_site_empty_call_async(): description="description_value", google_maps_pin_uri="google_maps_pin_uri_value", notes="notes_value", + customer_site_id="customer_site_id_value", ) ) response = await client.get_site() @@ -4465,6 +4468,7 @@ async def test_get_site_async( description="description_value", google_maps_pin_uri="google_maps_pin_uri_value", notes="notes_value", + customer_site_id="customer_site_id_value", ) ) response = await client.get_site(request) @@ -4482,6 +4486,7 @@ async def test_get_site_async( assert response.description == "description_value" assert response.google_maps_pin_uri == "google_maps_pin_uri_value" assert response.notes == "notes_value" + assert response.customer_site_id == "customer_site_id_value" @pytest.mark.asyncio @@ -10302,6 +10307,7 @@ def test_get_comment(request_type, transport: str = "grpc"): name="name_value", author="author_value", text="text_value", + author_entity=resources.Entity.GOOGLE, ) response = client.get_comment(request) @@ -10316,6 +10322,7 @@ def test_get_comment(request_type, transport: str = "grpc"): assert response.name == "name_value" assert response.author == "author_value" assert response.text == "text_value" + assert response.author_entity == resources.Entity.GOOGLE def test_get_comment_empty_call(): @@ -10417,6 +10424,7 @@ async def test_get_comment_empty_call_async(): name="name_value", author="author_value", text="text_value", + author_entity=resources.Entity.GOOGLE, ) ) response = await client.get_comment() @@ -10488,6 +10496,7 @@ async def test_get_comment_async( name="name_value", author="author_value", text="text_value", + author_entity=resources.Entity.GOOGLE, ) ) response = await client.get_comment(request) @@ -10503,6 +10512,7 @@ async def test_get_comment_async( assert response.name == "name_value" assert response.author == "author_value" assert response.text == "text_value" + assert response.author_entity == resources.Entity.GOOGLE @pytest.mark.asyncio @@ -11043,11 +11053,11 @@ async def test_create_comment_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - service.ListChangeLogEntriesRequest, + service.RecordActionOnCommentRequest, dict, ], ) -def test_list_change_log_entries(request_type, transport: str = "grpc"): +def test_record_action_on_comment(request_type, transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -11059,28 +11069,32 @@ def test_list_change_log_entries(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_change_log_entries), "__call__" + type(client.transport.record_action_on_comment), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = service.ListChangeLogEntriesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + call.return_value = resources.Comment( + name="name_value", + author="author_value", + text="text_value", + author_entity=resources.Entity.GOOGLE, ) - response = client.list_change_log_entries(request) + response = client.record_action_on_comment(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = service.ListChangeLogEntriesRequest() + request = service.RecordActionOnCommentRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListChangeLogEntriesPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, resources.Comment) + assert response.name == "name_value" + assert response.author == "author_value" + assert response.text == "text_value" + assert response.author_entity == resources.Entity.GOOGLE -def test_list_change_log_entries_empty_call(): +def test_record_action_on_comment_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 = GDCHardwareManagementClient( @@ -11090,18 +11104,18 @@ def test_list_change_log_entries_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_change_log_entries), "__call__" + type(client.transport.record_action_on_comment), "__call__" ) as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.list_change_log_entries() + client.record_action_on_comment() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListChangeLogEntriesRequest() + assert args[0] == service.RecordActionOnCommentRequest() -def test_list_change_log_entries_non_empty_request_with_auto_populated_field(): +def test_record_action_on_comment_non_empty_request_with_auto_populated_field(): # This test is a coverage failsafe to make sure that UUID4 fields are # automatically populated, according to AIP-4235, with non-empty requests. client = GDCHardwareManagementClient( @@ -11112,32 +11126,26 @@ def test_list_change_log_entries_non_empty_request_with_auto_populated_field(): # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. - request = service.ListChangeLogEntriesRequest( - parent="parent_value", - page_token="page_token_value", - filter="filter_value", - order_by="order_by_value", + request = service.RecordActionOnCommentRequest( + name="name_value", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_change_log_entries), "__call__" + type(client.transport.record_action_on_comment), "__call__" ) as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.list_change_log_entries(request=request) + client.record_action_on_comment(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListChangeLogEntriesRequest( - parent="parent_value", - page_token="page_token_value", - filter="filter_value", - order_by="order_by_value", + assert args[0] == service.RecordActionOnCommentRequest( + name="name_value", ) -def test_list_change_log_entries_use_cached_wrapped_rpc(): +def test_record_action_on_comment_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -11152,7 +11160,7 @@ def test_list_change_log_entries_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.list_change_log_entries + client._transport.record_action_on_comment in client._transport._wrapped_methods ) @@ -11162,15 +11170,15 @@ def test_list_change_log_entries_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.list_change_log_entries + client._transport.record_action_on_comment ] = mock_rpc request = {} - client.list_change_log_entries(request) + client.record_action_on_comment(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_change_log_entries(request) + client.record_action_on_comment(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -11178,7 +11186,7 @@ def test_list_change_log_entries_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_list_change_log_entries_empty_call_async(): +async def test_record_action_on_comment_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GDCHardwareManagementAsyncClient( @@ -11188,23 +11196,25 @@ async def test_list_change_log_entries_empty_call_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_change_log_entries), "__call__" + type(client.transport.record_action_on_comment), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListChangeLogEntriesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + resources.Comment( + name="name_value", + author="author_value", + text="text_value", + author_entity=resources.Entity.GOOGLE, ) ) - response = await client.list_change_log_entries() + response = await client.record_action_on_comment() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListChangeLogEntriesRequest() + assert args[0] == service.RecordActionOnCommentRequest() @pytest.mark.asyncio -async def test_list_change_log_entries_async_use_cached_wrapped_rpc( +async def test_record_action_on_comment_async_use_cached_wrapped_rpc( transport: str = "grpc_asyncio", ): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, @@ -11221,7 +11231,7 @@ async def test_list_change_log_entries_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.list_change_log_entries + client._client._transport.record_action_on_comment in client._client._transport._wrapped_methods ) @@ -11229,16 +11239,16 @@ async def test_list_change_log_entries_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.list_change_log_entries + client._client._transport.record_action_on_comment ] = mock_rpc request = {} - await client.list_change_log_entries(request) + await client.record_action_on_comment(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.list_change_log_entries(request) + await client.record_action_on_comment(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -11246,8 +11256,8 @@ async def test_list_change_log_entries_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_list_change_log_entries_async( - transport: str = "grpc_asyncio", request_type=service.ListChangeLogEntriesRequest +async def test_record_action_on_comment_async( + transport: str = "grpc_asyncio", request_type=service.RecordActionOnCommentRequest ): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11260,51 +11270,55 @@ async def test_list_change_log_entries_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_change_log_entries), "__call__" + type(client.transport.record_action_on_comment), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListChangeLogEntriesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + resources.Comment( + name="name_value", + author="author_value", + text="text_value", + author_entity=resources.Entity.GOOGLE, ) ) - response = await client.list_change_log_entries(request) + response = await client.record_action_on_comment(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = service.ListChangeLogEntriesRequest() + request = service.RecordActionOnCommentRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListChangeLogEntriesAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, resources.Comment) + assert response.name == "name_value" + assert response.author == "author_value" + assert response.text == "text_value" + assert response.author_entity == resources.Entity.GOOGLE @pytest.mark.asyncio -async def test_list_change_log_entries_async_from_dict(): - await test_list_change_log_entries_async(request_type=dict) +async def test_record_action_on_comment_async_from_dict(): + await test_record_action_on_comment_async(request_type=dict) -def test_list_change_log_entries_field_headers(): +def test_record_action_on_comment_field_headers(): client = GDCHardwareManagementClient( 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 = service.ListChangeLogEntriesRequest() + request = service.RecordActionOnCommentRequest() - request.parent = "parent_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_change_log_entries), "__call__" + type(client.transport.record_action_on_comment), "__call__" ) as call: - call.return_value = service.ListChangeLogEntriesResponse() - client.list_change_log_entries(request) + call.return_value = resources.Comment() + client.record_action_on_comment(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -11315,30 +11329,28 @@ def test_list_change_log_entries_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_change_log_entries_field_headers_async(): +async def test_record_action_on_comment_field_headers_async(): client = GDCHardwareManagementAsyncClient( 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 = service.ListChangeLogEntriesRequest() + request = service.RecordActionOnCommentRequest() - request.parent = "parent_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_change_log_entries), "__call__" + type(client.transport.record_action_on_comment), "__call__" ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListChangeLogEntriesResponse() - ) - await client.list_change_log_entries(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Comment()) + await client.record_action_on_comment(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -11349,37 +11361,41 @@ async def test_list_change_log_entries_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] -def test_list_change_log_entries_flattened(): +def test_record_action_on_comment_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_change_log_entries), "__call__" + type(client.transport.record_action_on_comment), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = service.ListChangeLogEntriesResponse() + call.return_value = resources.Comment() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_change_log_entries( - parent="parent_value", + client.record_action_on_comment( + name="name_value", + action_type=service.RecordActionOnCommentRequest.ActionType.READ, ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].action_type + mock_val = service.RecordActionOnCommentRequest.ActionType.READ assert arg == mock_val -def test_list_change_log_entries_flattened_error(): +def test_record_action_on_comment_flattened_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -11387,45 +11403,48 @@ def test_list_change_log_entries_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_change_log_entries( - service.ListChangeLogEntriesRequest(), - parent="parent_value", + client.record_action_on_comment( + service.RecordActionOnCommentRequest(), + name="name_value", + action_type=service.RecordActionOnCommentRequest.ActionType.READ, ) @pytest.mark.asyncio -async def test_list_change_log_entries_flattened_async(): +async def test_record_action_on_comment_flattened_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_change_log_entries), "__call__" + type(client.transport.record_action_on_comment), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = service.ListChangeLogEntriesResponse() + call.return_value = resources.Comment() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListChangeLogEntriesResponse() - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Comment()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_change_log_entries( - parent="parent_value", + response = await client.record_action_on_comment( + name="name_value", + action_type=service.RecordActionOnCommentRequest.ActionType.READ, ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].action_type + mock_val = service.RecordActionOnCommentRequest.ActionType.READ assert arg == mock_val @pytest.mark.asyncio -async def test_list_change_log_entries_flattened_error_async(): +async def test_record_action_on_comment_flattened_error_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -11433,276 +11452,75 @@ async def test_list_change_log_entries_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_change_log_entries( - service.ListChangeLogEntriesRequest(), - parent="parent_value", + await client.record_action_on_comment( + service.RecordActionOnCommentRequest(), + name="name_value", + action_type=service.RecordActionOnCommentRequest.ActionType.READ, ) -def test_list_change_log_entries_pager(transport_name: str = "grpc"): +@pytest.mark.parametrize( + "request_type", + [ + service.ListChangeLogEntriesRequest, + dict, + ], +) +def test_list_change_log_entries(request_type, transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport_name, + 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_change_log_entries), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - ], - next_page_token="abc", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[], - next_page_token="def", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - ], - next_page_token="ghi", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - ], - ), - RuntimeError, - ) - - expected_metadata = () - retry = retries.Retry() - timeout = 5 - expected_metadata = tuple(expected_metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Designate an appropriate return value for the call. + call.return_value = service.ListChangeLogEntriesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], ) - pager = client.list_change_log_entries(request={}, retry=retry, timeout=timeout) + response = client.list_change_log_entries(request) - assert pager._metadata == expected_metadata - assert pager._retry == retry - assert pager._timeout == timeout + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = service.ListChangeLogEntriesRequest() + assert args[0] == request - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, resources.ChangeLogEntry) for i in results) + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListChangeLogEntriesPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] -def test_list_change_log_entries_pages(transport_name: str = "grpc"): +def test_list_change_log_entries_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 = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport_name, + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.list_change_log_entries), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - ], - next_page_token="abc", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[], - next_page_token="def", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - ], - next_page_token="ghi", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - ], - ), - RuntimeError, + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. ) - pages = list(client.list_change_log_entries(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + client.list_change_log_entries() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.ListChangeLogEntriesRequest() -@pytest.mark.asyncio -async def test_list_change_log_entries_async_pager(): - client = GDCHardwareManagementAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_change_log_entries), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - ], - next_page_token="abc", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[], - next_page_token="def", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - ], - next_page_token="ghi", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_change_log_entries( - request={}, - ) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, resources.ChangeLogEntry) for i in responses) - - -@pytest.mark.asyncio -async def test_list_change_log_entries_async_pages(): - client = GDCHardwareManagementAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_change_log_entries), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - ], - next_page_token="abc", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[], - next_page_token="def", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - ], - next_page_token="ghi", - ), - service.ListChangeLogEntriesResponse( - change_log_entries=[ - resources.ChangeLogEntry(), - resources.ChangeLogEntry(), - ], - ), - RuntimeError, - ) - pages = [] - # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` - # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 - async for page_ in ( # pragma: no branch - await client.list_change_log_entries(request={}) - ).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize( - "request_type", - [ - service.GetChangeLogEntryRequest, - dict, - ], -) -def test_get_change_log_entry(request_type, transport: str = "grpc"): - client = GDCHardwareManagementClient( - 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_change_log_entry), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = resources.ChangeLogEntry( - name="name_value", - log="log_value", - ) - response = client.get_change_log_entry(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = service.GetChangeLogEntryRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, resources.ChangeLogEntry) - assert response.name == "name_value" - assert response.log == "log_value" - - -def test_get_change_log_entry_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 = GDCHardwareManagementClient( - 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_change_log_entry), "__call__" - ) as call: - call.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. - ) - client.get_change_log_entry() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == service.GetChangeLogEntryRequest() - - -def test_get_change_log_entry_non_empty_request_with_auto_populated_field(): +def test_list_change_log_entries_non_empty_request_with_auto_populated_field(): # This test is a coverage failsafe to make sure that UUID4 fields are # automatically populated, according to AIP-4235, with non-empty requests. client = GDCHardwareManagementClient( @@ -11713,26 +11531,32 @@ def test_get_change_log_entry_non_empty_request_with_auto_populated_field(): # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. - request = service.GetChangeLogEntryRequest( - name="name_value", + request = service.ListChangeLogEntriesRequest( + parent="parent_value", + page_token="page_token_value", + filter="filter_value", + order_by="order_by_value", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_change_log_entry), "__call__" + type(client.transport.list_change_log_entries), "__call__" ) as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.get_change_log_entry(request=request) + client.list_change_log_entries(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetChangeLogEntryRequest( - name="name_value", + assert args[0] == service.ListChangeLogEntriesRequest( + parent="parent_value", + page_token="page_token_value", + filter="filter_value", + order_by="order_by_value", ) -def test_get_change_log_entry_use_cached_wrapped_rpc(): +def test_list_change_log_entries_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -11747,7 +11571,8 @@ def test_get_change_log_entry_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.get_change_log_entry in client._transport._wrapped_methods + client._transport.list_change_log_entries + in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -11756,15 +11581,15 @@ def test_get_change_log_entry_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.get_change_log_entry + client._transport.list_change_log_entries ] = mock_rpc request = {} - client.get_change_log_entry(request) + client.list_change_log_entries(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_change_log_entry(request) + client.list_change_log_entries(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -11772,7 +11597,7 @@ def test_get_change_log_entry_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_get_change_log_entry_empty_call_async(): +async def test_list_change_log_entries_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GDCHardwareManagementAsyncClient( @@ -11782,23 +11607,23 @@ async def test_get_change_log_entry_empty_call_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_change_log_entry), "__call__" + type(client.transport.list_change_log_entries), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - resources.ChangeLogEntry( - name="name_value", - log="log_value", + service.ListChangeLogEntriesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], ) ) - response = await client.get_change_log_entry() + response = await client.list_change_log_entries() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetChangeLogEntryRequest() + assert args[0] == service.ListChangeLogEntriesRequest() @pytest.mark.asyncio -async def test_get_change_log_entry_async_use_cached_wrapped_rpc( +async def test_list_change_log_entries_async_use_cached_wrapped_rpc( transport: str = "grpc_asyncio", ): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, @@ -11815,7 +11640,7 @@ async def test_get_change_log_entry_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.get_change_log_entry + client._client._transport.list_change_log_entries in client._client._transport._wrapped_methods ) @@ -11823,16 +11648,16 @@ async def test_get_change_log_entry_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.get_change_log_entry + client._client._transport.list_change_log_entries ] = mock_rpc request = {} - await client.get_change_log_entry(request) + await client.list_change_log_entries(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.get_change_log_entry(request) + await client.list_change_log_entries(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -11840,8 +11665,8 @@ async def test_get_change_log_entry_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_get_change_log_entry_async( - transport: str = "grpc_asyncio", request_type=service.GetChangeLogEntryRequest +async def test_list_change_log_entries_async( + transport: str = "grpc_asyncio", request_type=service.ListChangeLogEntriesRequest ): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11854,51 +11679,51 @@ async def test_get_change_log_entry_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_change_log_entry), "__call__" + type(client.transport.list_change_log_entries), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - resources.ChangeLogEntry( - name="name_value", - log="log_value", + service.ListChangeLogEntriesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], ) ) - response = await client.get_change_log_entry(request) + response = await client.list_change_log_entries(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = service.GetChangeLogEntryRequest() + request = service.ListChangeLogEntriesRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, resources.ChangeLogEntry) - assert response.name == "name_value" - assert response.log == "log_value" + assert isinstance(response, pagers.ListChangeLogEntriesAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] @pytest.mark.asyncio -async def test_get_change_log_entry_async_from_dict(): - await test_get_change_log_entry_async(request_type=dict) +async def test_list_change_log_entries_async_from_dict(): + await test_list_change_log_entries_async(request_type=dict) -def test_get_change_log_entry_field_headers(): +def test_list_change_log_entries_field_headers(): client = GDCHardwareManagementClient( 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 = service.GetChangeLogEntryRequest() + request = service.ListChangeLogEntriesRequest() - request.name = "name_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_change_log_entry), "__call__" + type(client.transport.list_change_log_entries), "__call__" ) as call: - call.return_value = resources.ChangeLogEntry() - client.get_change_log_entry(request) + call.return_value = service.ListChangeLogEntriesResponse() + client.list_change_log_entries(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -11909,30 +11734,30 @@ def test_get_change_log_entry_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "parent=parent_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_change_log_entry_field_headers_async(): +async def test_list_change_log_entries_field_headers_async(): client = GDCHardwareManagementAsyncClient( 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 = service.GetChangeLogEntryRequest() + request = service.ListChangeLogEntriesRequest() - request.name = "name_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_change_log_entry), "__call__" + type(client.transport.list_change_log_entries), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - resources.ChangeLogEntry() + service.ListChangeLogEntriesResponse() ) - await client.get_change_log_entry(request) + await client.list_change_log_entries(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -11943,37 +11768,37 @@ async def test_get_change_log_entry_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "parent=parent_value", ) in kw["metadata"] -def test_get_change_log_entry_flattened(): +def test_list_change_log_entries_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_change_log_entry), "__call__" + type(client.transport.list_change_log_entries), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = resources.ChangeLogEntry() + call.return_value = service.ListChangeLogEntriesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_change_log_entry( - name="name_value", + client.list_change_log_entries( + 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] - arg = args[0].name - mock_val = "name_value" + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val -def test_get_change_log_entry_flattened_error(): +def test_list_change_log_entries_flattened_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -11981,45 +11806,45 @@ def test_get_change_log_entry_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_change_log_entry( - service.GetChangeLogEntryRequest(), - name="name_value", + client.list_change_log_entries( + service.ListChangeLogEntriesRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_get_change_log_entry_flattened_async(): +async def test_list_change_log_entries_flattened_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_change_log_entry), "__call__" + type(client.transport.list_change_log_entries), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = resources.ChangeLogEntry() + call.return_value = service.ListChangeLogEntriesResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - resources.ChangeLogEntry() + service.ListChangeLogEntriesResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_change_log_entry( - name="name_value", + response = await client.list_change_log_entries( + 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] - arg = args[0].name - mock_val = "name_value" + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val @pytest.mark.asyncio -async def test_get_change_log_entry_flattened_error_async(): +async def test_list_change_log_entries_flattened_error_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -12027,132 +11852,338 @@ async def test_get_change_log_entry_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_change_log_entry( - service.GetChangeLogEntryRequest(), - name="name_value", + await client.list_change_log_entries( + service.ListChangeLogEntriesRequest(), + parent="parent_value", ) -@pytest.mark.parametrize( - "request_type", - [ - service.ListSkusRequest, - dict, - ], -) -def test_list_skus(request_type, transport: str = "grpc"): +def test_list_change_log_entries_pager(transport_name: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + transport=transport_name, ) - # 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_skus), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = service.ListSkusResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + with mock.patch.object( + type(client.transport.list_change_log_entries), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + ], + next_page_token="abc", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[], + next_page_token="def", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + ], + next_page_token="ghi", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + ], + ), + RuntimeError, ) - response = client.list_skus(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = service.ListSkusRequest() - assert args[0] == request + expected_metadata = () + retry = retries.Retry() + timeout = 5 + expected_metadata = tuple(expected_metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_change_log_entries(request={}, retry=retry, timeout=timeout) - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSkusPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert pager._metadata == expected_metadata + assert pager._retry == retry + assert pager._timeout == timeout + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, resources.ChangeLogEntry) for i in results) -def test_list_skus_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. +def test_list_change_log_entries_pages(transport_name: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_skus), "__call__") as call: - call.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. + with mock.patch.object( + type(client.transport.list_change_log_entries), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + ], + next_page_token="abc", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[], + next_page_token="def", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + ], + next_page_token="ghi", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + ], + ), + RuntimeError, ) - client.list_skus() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == service.ListSkusRequest() + pages = list(client.list_change_log_entries(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_list_skus_non_empty_request_with_auto_populated_field(): - # This test is a coverage failsafe to make sure that UUID4 fields are - # automatically populated, according to AIP-4235, with non-empty requests. - client = GDCHardwareManagementClient( +@pytest.mark.asyncio +async def test_list_change_log_entries_async_pager(): + client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Populate all string fields in the request which are not UUID4 - # since we want to check that UUID4 are populated automatically - # if they meet the requirements of AIP 4235. - request = service.ListSkusRequest( - parent="parent_value", - page_token="page_token_value", - filter="filter_value", - order_by="order_by_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_skus), "__call__") as call: - call.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. + with mock.patch.object( + type(client.transport.list_change_log_entries), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + ], + next_page_token="abc", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[], + next_page_token="def", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + ], + next_page_token="ghi", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + ], + ), + RuntimeError, ) - client.list_skus(request=request) - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == service.ListSkusRequest( - parent="parent_value", - page_token="page_token_value", - filter="filter_value", - order_by="order_by_value", + async_pager = await client.list_change_log_entries( + request={}, ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + assert len(responses) == 6 + assert all(isinstance(i, resources.ChangeLogEntry) for i in responses) -def test_list_skus_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + +@pytest.mark.asyncio +async def test_list_change_log_entries_async_pages(): + client = GDCHardwareManagementAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_change_log_entries), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + ], + next_page_token="abc", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[], + next_page_token="def", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + ], + next_page_token="ghi", + ), + service.ListChangeLogEntriesResponse( + change_log_entries=[ + resources.ChangeLogEntry(), + resources.ChangeLogEntry(), + ], + ), + RuntimeError, + ) + pages = [] + # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` + # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 + async for page_ in ( # pragma: no branch + await client.list_change_log_entries(request={}) + ).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + service.GetChangeLogEntryRequest, + dict, + ], +) +def test_get_change_log_entry(request_type, transport: str = "grpc"): + client = GDCHardwareManagementClient( + 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_change_log_entry), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = resources.ChangeLogEntry( + name="name_value", + log="log_value", + ) + response = client.get_change_log_entry(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = service.GetChangeLogEntryRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, resources.ChangeLogEntry) + assert response.name == "name_value" + assert response.log == "log_value" + + +def test_get_change_log_entry_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 = GDCHardwareManagementClient( + 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_change_log_entry), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.get_change_log_entry() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.GetChangeLogEntryRequest() + + +def test_get_change_log_entry_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = service.GetChangeLogEntryRequest( + name="name_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_change_log_entry), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.get_change_log_entry(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.GetChangeLogEntryRequest( + name="name_value", + ) + + +def test_get_change_log_entry_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) # Should wrap all calls on client creation assert wrapper_fn.call_count > 0 wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_skus in client._transport._wrapped_methods + assert ( + client._transport.get_change_log_entry in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_skus] = mock_rpc + client._transport._wrapped_methods[ + client._transport.get_change_log_entry + ] = mock_rpc request = {} - client.list_skus(request) + client.get_change_log_entry(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_skus(request) + client.get_change_log_entry(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -12160,7 +12191,7 @@ def test_list_skus_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_list_skus_empty_call_async(): +async def test_get_change_log_entry_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GDCHardwareManagementAsyncClient( @@ -12169,22 +12200,26 @@ async def test_list_skus_empty_call_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_skus), "__call__") as call: + with mock.patch.object( + type(client.transport.get_change_log_entry), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListSkusResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + resources.ChangeLogEntry( + name="name_value", + log="log_value", ) ) - response = await client.list_skus() + response = await client.get_change_log_entry() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListSkusRequest() + assert args[0] == service.GetChangeLogEntryRequest() @pytest.mark.asyncio -async def test_list_skus_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): +async def test_get_change_log_entry_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: @@ -12199,7 +12234,7 @@ async def test_list_skus_async_use_cached_wrapped_rpc(transport: str = "grpc_asy # Ensure method has been cached assert ( - client._client._transport.list_skus + client._client._transport.get_change_log_entry in client._client._transport._wrapped_methods ) @@ -12207,16 +12242,16 @@ async def test_list_skus_async_use_cached_wrapped_rpc(transport: str = "grpc_asy mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.list_skus + client._client._transport.get_change_log_entry ] = mock_rpc request = {} - await client.list_skus(request) + await client.get_change_log_entry(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.list_skus(request) + await client.get_change_log_entry(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -12224,8 +12259,8 @@ async def test_list_skus_async_use_cached_wrapped_rpc(transport: str = "grpc_asy @pytest.mark.asyncio -async def test_list_skus_async( - transport: str = "grpc_asyncio", request_type=service.ListSkusRequest +async def test_get_change_log_entry_async( + transport: str = "grpc_asyncio", request_type=service.GetChangeLogEntryRequest ): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12237,48 +12272,52 @@ async def test_list_skus_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_skus), "__call__") as call: + with mock.patch.object( + type(client.transport.get_change_log_entry), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListSkusResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + resources.ChangeLogEntry( + name="name_value", + log="log_value", ) ) - response = await client.list_skus(request) + response = await client.get_change_log_entry(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = service.ListSkusRequest() + request = service.GetChangeLogEntryRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSkusAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, resources.ChangeLogEntry) + assert response.name == "name_value" + assert response.log == "log_value" @pytest.mark.asyncio -async def test_list_skus_async_from_dict(): - await test_list_skus_async(request_type=dict) +async def test_get_change_log_entry_async_from_dict(): + await test_get_change_log_entry_async(request_type=dict) -def test_list_skus_field_headers(): +def test_get_change_log_entry_field_headers(): client = GDCHardwareManagementClient( 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 = service.ListSkusRequest() + request = service.GetChangeLogEntryRequest() - request.parent = "parent_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_skus), "__call__") as call: - call.return_value = service.ListSkusResponse() - client.list_skus(request) + with mock.patch.object( + type(client.transport.get_change_log_entry), "__call__" + ) as call: + call.return_value = resources.ChangeLogEntry() + client.get_change_log_entry(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -12289,28 +12328,30 @@ def test_list_skus_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_skus_field_headers_async(): +async def test_get_change_log_entry_field_headers_async(): client = GDCHardwareManagementAsyncClient( 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 = service.ListSkusRequest() + request = service.GetChangeLogEntryRequest() - request.parent = "parent_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_skus), "__call__") as call: + with mock.patch.object( + type(client.transport.get_change_log_entry), "__call__" + ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListSkusResponse() + resources.ChangeLogEntry() ) - await client.list_skus(request) + await client.get_change_log_entry(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -12321,35 +12362,37 @@ async def test_list_skus_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] -def test_list_skus_flattened(): +def test_get_change_log_entry_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_skus), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = service.ListSkusResponse() + with mock.patch.object( + type(client.transport.get_change_log_entry), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = resources.ChangeLogEntry() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_skus( - parent="parent_value", + client.get_change_log_entry( + 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] - arg = args[0].parent - mock_val = "parent_value" + arg = args[0].name + mock_val = "name_value" assert arg == mock_val -def test_list_skus_flattened_error(): +def test_get_change_log_entry_flattened_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -12357,43 +12400,45 @@ def test_list_skus_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_skus( - service.ListSkusRequest(), - parent="parent_value", + client.get_change_log_entry( + service.GetChangeLogEntryRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_list_skus_flattened_async(): +async def test_get_change_log_entry_flattened_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_skus), "__call__") as call: + with mock.patch.object( + type(client.transport.get_change_log_entry), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = service.ListSkusResponse() + call.return_value = resources.ChangeLogEntry() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListSkusResponse() + resources.ChangeLogEntry() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_skus( - parent="parent_value", + response = await client.get_change_log_entry( + 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] - arg = args[0].parent - mock_val = "parent_value" + arg = args[0].name + mock_val = "name_value" assert arg == mock_val @pytest.mark.asyncio -async def test_list_skus_flattened_error_async(): +async def test_get_change_log_entry_flattened_error_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -12401,330 +12446,132 @@ async def test_list_skus_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_skus( - service.ListSkusRequest(), - parent="parent_value", + await client.get_change_log_entry( + service.GetChangeLogEntryRequest(), + name="name_value", ) -def test_list_skus_pager(transport_name: str = "grpc"): +@pytest.mark.parametrize( + "request_type", + [ + service.ListSkusRequest, + dict, + ], +) +def test_list_skus(request_type, transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport_name, + 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_skus), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListSkusResponse( - skus=[ - resources.Sku(), - resources.Sku(), - resources.Sku(), - ], - next_page_token="abc", - ), - service.ListSkusResponse( - skus=[], - next_page_token="def", - ), - service.ListSkusResponse( - skus=[ - resources.Sku(), - ], - next_page_token="ghi", - ), - service.ListSkusResponse( - skus=[ - resources.Sku(), - resources.Sku(), - ], - ), - RuntimeError, - ) - - expected_metadata = () - retry = retries.Retry() - timeout = 5 - expected_metadata = tuple(expected_metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Designate an appropriate return value for the call. + call.return_value = service.ListSkusResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], ) - pager = client.list_skus(request={}, retry=retry, timeout=timeout) + response = client.list_skus(request) - assert pager._metadata == expected_metadata - assert pager._retry == retry - assert pager._timeout == timeout + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = service.ListSkusRequest() + assert args[0] == request - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, resources.Sku) for i in results) + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSkusPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] -def test_list_skus_pages(transport_name: str = "grpc"): +def test_list_skus_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 = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport_name, + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_skus), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListSkusResponse( - skus=[ - resources.Sku(), - resources.Sku(), - resources.Sku(), - ], - next_page_token="abc", - ), - service.ListSkusResponse( - skus=[], - next_page_token="def", - ), - service.ListSkusResponse( - skus=[ - resources.Sku(), - ], - next_page_token="ghi", - ), - service.ListSkusResponse( - skus=[ - resources.Sku(), - resources.Sku(), - ], - ), - RuntimeError, + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. ) - pages = list(client.list_skus(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + client.list_skus() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.ListSkusRequest() -@pytest.mark.asyncio -async def test_list_skus_async_pager(): - client = GDCHardwareManagementAsyncClient( +def test_list_skus_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = service.ListSkusRequest( + parent="parent_value", + page_token="page_token_value", + filter="filter_value", + order_by="order_by_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_skus), "__call__", new_callable=mock.AsyncMock - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListSkusResponse( - skus=[ - resources.Sku(), - resources.Sku(), - resources.Sku(), - ], - next_page_token="abc", - ), - service.ListSkusResponse( - skus=[], - next_page_token="def", - ), - service.ListSkusResponse( - skus=[ - resources.Sku(), - ], - next_page_token="ghi", - ), - service.ListSkusResponse( - skus=[ - resources.Sku(), - resources.Sku(), - ], - ), - RuntimeError, + with mock.patch.object(type(client.transport.list_skus), "__call__") as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. ) - async_pager = await client.list_skus( - request={}, + client.list_skus(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.ListSkusRequest( + parent="parent_value", + page_token="page_token_value", + filter="filter_value", + order_by="order_by_value", ) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - assert len(responses) == 6 - assert all(isinstance(i, resources.Sku) for i in responses) +def test_list_skus_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) -@pytest.mark.asyncio -async def test_list_skus_async_pages(): - client = GDCHardwareManagementAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_skus), "__call__", new_callable=mock.AsyncMock - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListSkusResponse( - skus=[ - resources.Sku(), - resources.Sku(), - resources.Sku(), - ], - next_page_token="abc", - ), - service.ListSkusResponse( - skus=[], - next_page_token="def", - ), - service.ListSkusResponse( - skus=[ - resources.Sku(), - ], - next_page_token="ghi", - ), - service.ListSkusResponse( - skus=[ - resources.Sku(), - resources.Sku(), - ], - ), - RuntimeError, - ) - pages = [] - # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` - # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 - async for page_ in ( # pragma: no branch - await client.list_skus(request={}) - ).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize( - "request_type", - [ - service.GetSkuRequest, - dict, - ], -) -def test_get_sku(request_type, transport: str = "grpc"): - client = GDCHardwareManagementClient( - 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_sku), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = resources.Sku( - name="name_value", - display_name="display_name_value", - description="description_value", - revision_id="revision_id_value", - is_active=True, - type_=resources.Sku.Type.RACK, - vcpu_count=1094, - ) - response = client.get_sku(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = service.GetSkuRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, resources.Sku) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.revision_id == "revision_id_value" - assert response.is_active is True - assert response.type_ == resources.Sku.Type.RACK - assert response.vcpu_count == 1094 - - -def test_get_sku_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 = GDCHardwareManagementClient( - 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_sku), "__call__") as call: - call.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. - ) - client.get_sku() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == service.GetSkuRequest() - - -def test_get_sku_non_empty_request_with_auto_populated_field(): - # This test is a coverage failsafe to make sure that UUID4 fields are - # automatically populated, according to AIP-4235, with non-empty requests. - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Populate all string fields in the request which are not UUID4 - # since we want to check that UUID4 are populated automatically - # if they meet the requirements of AIP 4235. - request = service.GetSkuRequest( - name="name_value", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_sku), "__call__") as call: - call.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. - ) - client.get_sku(request=request) - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == service.GetSkuRequest( - name="name_value", - ) - - -def test_get_sku_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_sku in client._transport._wrapped_methods + assert client._transport.list_skus in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_sku] = mock_rpc + client._transport._wrapped_methods[client._transport.list_skus] = mock_rpc request = {} - client.get_sku(request) + client.list_skus(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_sku(request) + client.list_skus(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -12732,7 +12579,7 @@ def test_get_sku_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_get_sku_empty_call_async(): +async def test_list_skus_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GDCHardwareManagementAsyncClient( @@ -12741,27 +12588,22 @@ async def test_get_sku_empty_call_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_sku), "__call__") as call: + with mock.patch.object(type(client.transport.list_skus), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - resources.Sku( - name="name_value", - display_name="display_name_value", - description="description_value", - revision_id="revision_id_value", - is_active=True, - type_=resources.Sku.Type.RACK, - vcpu_count=1094, + service.ListSkusResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], ) ) - response = await client.get_sku() + response = await client.list_skus() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetSkuRequest() + assert args[0] == service.ListSkusRequest() @pytest.mark.asyncio -async def test_get_sku_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): +async def test_list_skus_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: @@ -12776,7 +12618,7 @@ async def test_get_sku_async_use_cached_wrapped_rpc(transport: str = "grpc_async # Ensure method has been cached assert ( - client._client._transport.get_sku + client._client._transport.list_skus in client._client._transport._wrapped_methods ) @@ -12784,16 +12626,16 @@ async def test_get_sku_async_use_cached_wrapped_rpc(transport: str = "grpc_async mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.get_sku + client._client._transport.list_skus ] = mock_rpc request = {} - await client.get_sku(request) + await client.list_skus(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.get_sku(request) + await client.list_skus(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -12801,8 +12643,8 @@ async def test_get_sku_async_use_cached_wrapped_rpc(transport: str = "grpc_async @pytest.mark.asyncio -async def test_get_sku_async( - transport: str = "grpc_asyncio", request_type=service.GetSkuRequest +async def test_list_skus_async( + transport: str = "grpc_asyncio", request_type=service.ListSkusRequest ): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12814,58 +12656,48 @@ async def test_get_sku_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_sku), "__call__") as call: + with mock.patch.object(type(client.transport.list_skus), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - resources.Sku( - name="name_value", - display_name="display_name_value", - description="description_value", - revision_id="revision_id_value", - is_active=True, - type_=resources.Sku.Type.RACK, - vcpu_count=1094, + service.ListSkusResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], ) ) - response = await client.get_sku(request) + response = await client.list_skus(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = service.GetSkuRequest() + request = service.ListSkusRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, resources.Sku) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.revision_id == "revision_id_value" - assert response.is_active is True - assert response.type_ == resources.Sku.Type.RACK - assert response.vcpu_count == 1094 + assert isinstance(response, pagers.ListSkusAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] @pytest.mark.asyncio -async def test_get_sku_async_from_dict(): - await test_get_sku_async(request_type=dict) +async def test_list_skus_async_from_dict(): + await test_list_skus_async(request_type=dict) -def test_get_sku_field_headers(): +def test_list_skus_field_headers(): client = GDCHardwareManagementClient( 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 = service.GetSkuRequest() + request = service.ListSkusRequest() - request.name = "name_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_sku), "__call__") as call: - call.return_value = resources.Sku() - client.get_sku(request) + with mock.patch.object(type(client.transport.list_skus), "__call__") as call: + call.return_value = service.ListSkusResponse() + client.list_skus(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -12876,26 +12708,28 @@ def test_get_sku_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "parent=parent_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_sku_field_headers_async(): +async def test_list_skus_field_headers_async(): client = GDCHardwareManagementAsyncClient( 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 = service.GetSkuRequest() + request = service.ListSkusRequest() - request.name = "name_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_sku), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Sku()) - await client.get_sku(request) + with mock.patch.object(type(client.transport.list_skus), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + service.ListSkusResponse() + ) + await client.list_skus(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -12906,35 +12740,35 @@ async def test_get_sku_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "parent=parent_value", ) in kw["metadata"] -def test_get_sku_flattened(): +def test_list_skus_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_sku), "__call__") as call: + with mock.patch.object(type(client.transport.list_skus), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = resources.Sku() + call.return_value = service.ListSkusResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_sku( - name="name_value", + client.list_skus( + 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] - arg = args[0].name - mock_val = "name_value" + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val -def test_get_sku_flattened_error(): +def test_list_skus_flattened_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -12942,41 +12776,43 @@ def test_get_sku_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_sku( - service.GetSkuRequest(), - name="name_value", + client.list_skus( + service.ListSkusRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_get_sku_flattened_async(): +async def test_list_skus_flattened_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_sku), "__call__") as call: + with mock.patch.object(type(client.transport.list_skus), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = resources.Sku() + call.return_value = service.ListSkusResponse() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Sku()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + service.ListSkusResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_sku( - name="name_value", + response = await client.list_skus( + 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] - arg = args[0].name - mock_val = "name_value" + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val @pytest.mark.asyncio -async def test_get_sku_flattened_error_async(): +async def test_list_skus_flattened_error_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -12984,164 +12820,367 @@ async def test_get_sku_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_sku( - service.GetSkuRequest(), - name="name_value", + await client.list_skus( + service.ListSkusRequest(), + parent="parent_value", ) -@pytest.mark.parametrize( - "request_type", - [ - service.ListZonesRequest, - dict, - ], -) -def test_list_zones(request_type, transport: str = "grpc"): +def test_list_skus_pager(transport_name: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + transport=transport_name, ) - # 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_zones), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = service.ListZonesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + with mock.patch.object(type(client.transport.list_skus), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListSkusResponse( + skus=[ + resources.Sku(), + resources.Sku(), + resources.Sku(), + ], + next_page_token="abc", + ), + service.ListSkusResponse( + skus=[], + next_page_token="def", + ), + service.ListSkusResponse( + skus=[ + resources.Sku(), + ], + next_page_token="ghi", + ), + service.ListSkusResponse( + skus=[ + resources.Sku(), + resources.Sku(), + ], + ), + RuntimeError, ) - response = client.list_zones(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = service.ListZonesRequest() - assert args[0] == request + expected_metadata = () + retry = retries.Retry() + timeout = 5 + expected_metadata = tuple(expected_metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_skus(request={}, retry=retry, timeout=timeout) - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListZonesPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert pager._metadata == expected_metadata + assert pager._retry == retry + assert pager._timeout == timeout + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, resources.Sku) for i in results) -def test_list_zones_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. + +def test_list_skus_pages(transport_name: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_zones), "__call__") as call: - call.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. + with mock.patch.object(type(client.transport.list_skus), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListSkusResponse( + skus=[ + resources.Sku(), + resources.Sku(), + resources.Sku(), + ], + next_page_token="abc", + ), + service.ListSkusResponse( + skus=[], + next_page_token="def", + ), + service.ListSkusResponse( + skus=[ + resources.Sku(), + ], + next_page_token="ghi", + ), + service.ListSkusResponse( + skus=[ + resources.Sku(), + resources.Sku(), + ], + ), + RuntimeError, ) - client.list_zones() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == service.ListZonesRequest() + pages = list(client.list_skus(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_list_zones_non_empty_request_with_auto_populated_field(): - # This test is a coverage failsafe to make sure that UUID4 fields are - # automatically populated, according to AIP-4235, with non-empty requests. - client = GDCHardwareManagementClient( +@pytest.mark.asyncio +async def test_list_skus_async_pager(): + client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Populate all string fields in the request which are not UUID4 - # since we want to check that UUID4 are populated automatically - # if they meet the requirements of AIP 4235. - request = service.ListZonesRequest( - parent="parent_value", - page_token="page_token_value", - filter="filter_value", - order_by="order_by_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_zones), "__call__") as call: - call.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. - ) - client.list_zones(request=request) - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == service.ListZonesRequest( - parent="parent_value", - page_token="page_token_value", - filter="filter_value", - order_by="order_by_value", - ) - - -def test_list_zones_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + with mock.patch.object( + type(client.transport.list_skus), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListSkusResponse( + skus=[ + resources.Sku(), + resources.Sku(), + resources.Sku(), + ], + next_page_token="abc", + ), + service.ListSkusResponse( + skus=[], + next_page_token="def", + ), + service.ListSkusResponse( + skus=[ + resources.Sku(), + ], + next_page_token="ghi", + ), + service.ListSkusResponse( + skus=[ + resources.Sku(), + resources.Sku(), + ], + ), + RuntimeError, ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.list_zones in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. + async_pager = await client.list_skus( + request={}, ) - client._transport._wrapped_methods[client._transport.list_zones] = mock_rpc - request = {} - client.list_zones(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.list_zones(request) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 + assert len(responses) == 6 + assert all(isinstance(i, resources.Sku) for i in responses) @pytest.mark.asyncio -async def test_list_zones_empty_call_async(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. +async def test_list_skus_async_pages(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_zones), "__call__") as call: - # Designate an appropriate return value for the call. + with mock.patch.object( + type(client.transport.list_skus), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListSkusResponse( + skus=[ + resources.Sku(), + resources.Sku(), + resources.Sku(), + ], + next_page_token="abc", + ), + service.ListSkusResponse( + skus=[], + next_page_token="def", + ), + service.ListSkusResponse( + skus=[ + resources.Sku(), + ], + next_page_token="ghi", + ), + service.ListSkusResponse( + skus=[ + resources.Sku(), + resources.Sku(), + ], + ), + RuntimeError, + ) + pages = [] + # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` + # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 + async for page_ in ( # pragma: no branch + await client.list_skus(request={}) + ).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + service.GetSkuRequest, + dict, + ], +) +def test_get_sku(request_type, transport: str = "grpc"): + client = GDCHardwareManagementClient( + 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_sku), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = resources.Sku( + name="name_value", + display_name="display_name_value", + description="description_value", + revision_id="revision_id_value", + is_active=True, + type_=resources.Sku.Type.RACK, + vcpu_count=1094, + ) + response = client.get_sku(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = service.GetSkuRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, resources.Sku) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.revision_id == "revision_id_value" + assert response.is_active is True + assert response.type_ == resources.Sku.Type.RACK + assert response.vcpu_count == 1094 + + +def test_get_sku_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 = GDCHardwareManagementClient( + 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_sku), "__call__") as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.get_sku() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.GetSkuRequest() + + +def test_get_sku_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = service.GetSkuRequest( + name="name_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_sku), "__call__") as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.get_sku(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.GetSkuRequest( + name="name_value", + ) + + +def test_get_sku_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_sku in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_sku] = mock_rpc + request = {} + client.get_sku(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_sku(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_get_sku_empty_call_async(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GDCHardwareManagementAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_sku), "__call__") as call: + # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListZonesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + resources.Sku( + name="name_value", + display_name="display_name_value", + description="description_value", + revision_id="revision_id_value", + is_active=True, + type_=resources.Sku.Type.RACK, + vcpu_count=1094, ) ) - response = await client.list_zones() + response = await client.get_sku() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListZonesRequest() + assert args[0] == service.GetSkuRequest() @pytest.mark.asyncio -async def test_list_zones_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): +async def test_get_sku_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: @@ -13156,7 +13195,7 @@ async def test_list_zones_async_use_cached_wrapped_rpc(transport: str = "grpc_as # Ensure method has been cached assert ( - client._client._transport.list_zones + client._client._transport.get_sku in client._client._transport._wrapped_methods ) @@ -13164,16 +13203,16 @@ async def test_list_zones_async_use_cached_wrapped_rpc(transport: str = "grpc_as mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.list_zones + client._client._transport.get_sku ] = mock_rpc request = {} - await client.list_zones(request) + await client.get_sku(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.list_zones(request) + await client.get_sku(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -13181,8 +13220,8 @@ async def test_list_zones_async_use_cached_wrapped_rpc(transport: str = "grpc_as @pytest.mark.asyncio -async def test_list_zones_async( - transport: str = "grpc_asyncio", request_type=service.ListZonesRequest +async def test_get_sku_async( + transport: str = "grpc_asyncio", request_type=service.GetSkuRequest ): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13194,50 +13233,60 @@ async def test_list_zones_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_zones), "__call__") as call: + with mock.patch.object(type(client.transport.get_sku), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListZonesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + resources.Sku( + name="name_value", + display_name="display_name_value", + description="description_value", + revision_id="revision_id_value", + is_active=True, + type_=resources.Sku.Type.RACK, + vcpu_count=1094, ) ) - response = await client.list_zones(request) + response = await client.get_sku(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = service.ListZonesRequest() + request = service.GetSkuRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListZonesAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, resources.Sku) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.revision_id == "revision_id_value" + assert response.is_active is True + assert response.type_ == resources.Sku.Type.RACK + assert response.vcpu_count == 1094 @pytest.mark.asyncio -async def test_list_zones_async_from_dict(): - await test_list_zones_async(request_type=dict) +async def test_get_sku_async_from_dict(): + await test_get_sku_async(request_type=dict) -def test_list_zones_field_headers(): +def test_get_sku_field_headers(): client = GDCHardwareManagementClient( 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 = service.ListZonesRequest() + request = service.GetSkuRequest() - request.parent = "parent_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_zones), "__call__") as call: - call.return_value = service.ListZonesResponse() - client.list_zones(request) - - # Establish that the underlying gRPC stub method was called. + with mock.patch.object(type(client.transport.get_sku), "__call__") as call: + call.return_value = resources.Sku() + client.get_sku(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 @@ -13246,28 +13295,26 @@ def test_list_zones_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_zones_field_headers_async(): +async def test_get_sku_field_headers_async(): client = GDCHardwareManagementAsyncClient( 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 = service.ListZonesRequest() + request = service.GetSkuRequest() - request.parent = "parent_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_zones), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListZonesResponse() - ) - await client.list_zones(request) + with mock.patch.object(type(client.transport.get_sku), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Sku()) + await client.get_sku(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -13278,35 +13325,35 @@ async def test_list_zones_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] -def test_list_zones_flattened(): +def test_get_sku_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_zones), "__call__") as call: + with mock.patch.object(type(client.transport.get_sku), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = service.ListZonesResponse() + call.return_value = resources.Sku() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_zones( - parent="parent_value", + client.get_sku( + 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] - arg = args[0].parent - mock_val = "parent_value" + arg = args[0].name + mock_val = "name_value" assert arg == mock_val -def test_list_zones_flattened_error(): +def test_get_sku_flattened_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -13314,43 +13361,41 @@ def test_list_zones_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_zones( - service.ListZonesRequest(), - parent="parent_value", + client.get_sku( + service.GetSkuRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_list_zones_flattened_async(): +async def test_get_sku_flattened_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_zones), "__call__") as call: + with mock.patch.object(type(client.transport.get_sku), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = service.ListZonesResponse() + call.return_value = resources.Sku() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListZonesResponse() - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Sku()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_zones( - parent="parent_value", + response = await client.get_sku( + 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] - arg = args[0].parent - mock_val = "parent_value" + arg = args[0].name + mock_val = "name_value" assert arg == mock_val @pytest.mark.asyncio -async def test_list_zones_flattened_error_async(): +async def test_get_sku_flattened_error_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -13358,298 +13403,104 @@ async def test_list_zones_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_zones( - service.ListZonesRequest(), - parent="parent_value", + await client.get_sku( + service.GetSkuRequest(), + name="name_value", ) -def test_list_zones_pager(transport_name: str = "grpc"): +@pytest.mark.parametrize( + "request_type", + [ + service.ListZonesRequest, + dict, + ], +) +def test_list_zones(request_type, transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport_name, + 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_zones), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListZonesResponse( - zones=[ - resources.Zone(), - resources.Zone(), - resources.Zone(), - ], - next_page_token="abc", - ), - service.ListZonesResponse( - zones=[], - next_page_token="def", - ), - service.ListZonesResponse( - zones=[ - resources.Zone(), - ], - next_page_token="ghi", - ), - service.ListZonesResponse( - zones=[ - resources.Zone(), - resources.Zone(), - ], - ), - RuntimeError, - ) - - expected_metadata = () - retry = retries.Retry() - timeout = 5 - expected_metadata = tuple(expected_metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Designate an appropriate return value for the call. + call.return_value = service.ListZonesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], ) - pager = client.list_zones(request={}, retry=retry, timeout=timeout) + response = client.list_zones(request) - assert pager._metadata == expected_metadata - assert pager._retry == retry - assert pager._timeout == timeout + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = service.ListZonesRequest() + assert args[0] == request - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, resources.Zone) for i in results) + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListZonesPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] -def test_list_zones_pages(transport_name: str = "grpc"): +def test_list_zones_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 = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport_name, + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_zones), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListZonesResponse( - zones=[ - resources.Zone(), - resources.Zone(), - resources.Zone(), - ], - next_page_token="abc", - ), - service.ListZonesResponse( - zones=[], - next_page_token="def", - ), - service.ListZonesResponse( - zones=[ - resources.Zone(), - ], - next_page_token="ghi", - ), - service.ListZonesResponse( - zones=[ - resources.Zone(), - resources.Zone(), - ], - ), - RuntimeError, + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. ) - pages = list(client.list_zones(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + client.list_zones() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.ListZonesRequest() -@pytest.mark.asyncio -async def test_list_zones_async_pager(): - client = GDCHardwareManagementAsyncClient( +def test_list_zones_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = service.ListZonesRequest( + parent="parent_value", + page_token="page_token_value", + filter="filter_value", + order_by="order_by_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_zones), "__call__", new_callable=mock.AsyncMock - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListZonesResponse( - zones=[ - resources.Zone(), - resources.Zone(), - resources.Zone(), - ], - next_page_token="abc", - ), - service.ListZonesResponse( - zones=[], - next_page_token="def", - ), - service.ListZonesResponse( - zones=[ - resources.Zone(), - ], - next_page_token="ghi", - ), - service.ListZonesResponse( - zones=[ - resources.Zone(), - resources.Zone(), - ], - ), - RuntimeError, + with mock.patch.object(type(client.transport.list_zones), "__call__") as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. ) - async_pager = await client.list_zones( - request={}, + client.list_zones(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.ListZonesRequest( + parent="parent_value", + page_token="page_token_value", + filter="filter_value", + order_by="order_by_value", ) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - assert len(responses) == 6 - assert all(isinstance(i, resources.Zone) for i in responses) - -@pytest.mark.asyncio -async def test_list_zones_async_pages(): - client = GDCHardwareManagementAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_zones), "__call__", new_callable=mock.AsyncMock - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - service.ListZonesResponse( - zones=[ - resources.Zone(), - resources.Zone(), - resources.Zone(), - ], - next_page_token="abc", - ), - service.ListZonesResponse( - zones=[], - next_page_token="def", - ), - service.ListZonesResponse( - zones=[ - resources.Zone(), - ], - next_page_token="ghi", - ), - service.ListZonesResponse( - zones=[ - resources.Zone(), - resources.Zone(), - ], - ), - RuntimeError, - ) - pages = [] - # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` - # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 - async for page_ in ( # pragma: no branch - await client.list_zones(request={}) - ).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize( - "request_type", - [ - service.GetZoneRequest, - dict, - ], -) -def test_get_zone(request_type, transport: str = "grpc"): - client = GDCHardwareManagementClient( - 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_zone), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = resources.Zone( - name="name_value", - display_name="display_name_value", - state=resources.Zone.State.ADDITIONAL_INFO_NEEDED, - ciq_uri="ciq_uri_value", - globally_unique_id="globally_unique_id_value", - ) - response = client.get_zone(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = service.GetZoneRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, resources.Zone) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.state == resources.Zone.State.ADDITIONAL_INFO_NEEDED - assert response.ciq_uri == "ciq_uri_value" - assert response.globally_unique_id == "globally_unique_id_value" - - -def test_get_zone_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 = GDCHardwareManagementClient( - 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_zone), "__call__") as call: - call.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. - ) - client.get_zone() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == service.GetZoneRequest() - - -def test_get_zone_non_empty_request_with_auto_populated_field(): - # This test is a coverage failsafe to make sure that UUID4 fields are - # automatically populated, according to AIP-4235, with non-empty requests. - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Populate all string fields in the request which are not UUID4 - # since we want to check that UUID4 are populated automatically - # if they meet the requirements of AIP 4235. - request = service.GetZoneRequest( - name="name_value", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_zone), "__call__") as call: - call.return_value.name = ( - "foo" # operation_request.operation in compute client(s) expect a string. - ) - client.get_zone(request=request) - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == service.GetZoneRequest( - name="name_value", - ) - - -def test_get_zone_use_cached_wrapped_rpc(): +def test_list_zones_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -13663,21 +13514,21 @@ def test_get_zone_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_zone in client._transport._wrapped_methods + assert client._transport.list_zones in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_zone] = mock_rpc + client._transport._wrapped_methods[client._transport.list_zones] = mock_rpc request = {} - client.get_zone(request) + client.list_zones(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_zone(request) + client.list_zones(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -13685,7 +13536,7 @@ def test_get_zone_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_get_zone_empty_call_async(): +async def test_list_zones_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GDCHardwareManagementAsyncClient( @@ -13694,25 +13545,22 @@ async def test_get_zone_empty_call_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_zone), "__call__") as call: + with mock.patch.object(type(client.transport.list_zones), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - resources.Zone( - name="name_value", - display_name="display_name_value", - state=resources.Zone.State.ADDITIONAL_INFO_NEEDED, - ciq_uri="ciq_uri_value", - globally_unique_id="globally_unique_id_value", + service.ListZonesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], ) ) - response = await client.get_zone() + response = await client.list_zones() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetZoneRequest() + assert args[0] == service.ListZonesRequest() @pytest.mark.asyncio -async def test_get_zone_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): +async def test_list_zones_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: @@ -13727,7 +13575,7 @@ async def test_get_zone_async_use_cached_wrapped_rpc(transport: str = "grpc_asyn # Ensure method has been cached assert ( - client._client._transport.get_zone + client._client._transport.list_zones in client._client._transport._wrapped_methods ) @@ -13735,16 +13583,16 @@ async def test_get_zone_async_use_cached_wrapped_rpc(transport: str = "grpc_asyn mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.get_zone + client._client._transport.list_zones ] = mock_rpc request = {} - await client.get_zone(request) + await client.list_zones(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.get_zone(request) + await client.list_zones(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -13752,8 +13600,8 @@ async def test_get_zone_async_use_cached_wrapped_rpc(transport: str = "grpc_asyn @pytest.mark.asyncio -async def test_get_zone_async( - transport: str = "grpc_asyncio", request_type=service.GetZoneRequest +async def test_list_zones_async( + transport: str = "grpc_asyncio", request_type=service.ListZonesRequest ): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13765,54 +13613,48 @@ async def test_get_zone_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_zone), "__call__") as call: + with mock.patch.object(type(client.transport.list_zones), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - resources.Zone( - name="name_value", - display_name="display_name_value", - state=resources.Zone.State.ADDITIONAL_INFO_NEEDED, - ciq_uri="ciq_uri_value", - globally_unique_id="globally_unique_id_value", + service.ListZonesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], ) ) - response = await client.get_zone(request) + response = await client.list_zones(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = service.GetZoneRequest() + request = service.ListZonesRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, resources.Zone) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.state == resources.Zone.State.ADDITIONAL_INFO_NEEDED - assert response.ciq_uri == "ciq_uri_value" - assert response.globally_unique_id == "globally_unique_id_value" + assert isinstance(response, pagers.ListZonesAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] @pytest.mark.asyncio -async def test_get_zone_async_from_dict(): - await test_get_zone_async(request_type=dict) +async def test_list_zones_async_from_dict(): + await test_list_zones_async(request_type=dict) -def test_get_zone_field_headers(): +def test_list_zones_field_headers(): client = GDCHardwareManagementClient( 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 = service.GetZoneRequest() + request = service.ListZonesRequest() - request.name = "name_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_zone), "__call__") as call: - call.return_value = resources.Zone() - client.get_zone(request) + with mock.patch.object(type(client.transport.list_zones), "__call__") as call: + call.return_value = service.ListZonesResponse() + client.list_zones(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -13823,26 +13665,28 @@ def test_get_zone_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "parent=parent_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_zone_field_headers_async(): +async def test_list_zones_field_headers_async(): client = GDCHardwareManagementAsyncClient( 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 = service.GetZoneRequest() + request = service.ListZonesRequest() - request.name = "name_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_zone), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Zone()) - await client.get_zone(request) + with mock.patch.object(type(client.transport.list_zones), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + service.ListZonesResponse() + ) + await client.list_zones(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -13853,35 +13697,35 @@ async def test_get_zone_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "parent=parent_value", ) in kw["metadata"] -def test_get_zone_flattened(): +def test_list_zones_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_zone), "__call__") as call: + with mock.patch.object(type(client.transport.list_zones), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = resources.Zone() + call.return_value = service.ListZonesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_zone( - name="name_value", + client.list_zones( + 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] - arg = args[0].name - mock_val = "name_value" + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val -def test_get_zone_flattened_error(): +def test_list_zones_flattened_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -13889,41 +13733,43 @@ def test_get_zone_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_zone( - service.GetZoneRequest(), - name="name_value", + client.list_zones( + service.ListZonesRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_get_zone_flattened_async(): +async def test_list_zones_flattened_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_zone), "__call__") as call: + with mock.patch.object(type(client.transport.list_zones), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = resources.Zone() + call.return_value = service.ListZonesResponse() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Zone()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + service.ListZonesResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_zone( - name="name_value", + response = await client.list_zones( + 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] - arg = args[0].name - mock_val = "name_value" + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val @pytest.mark.asyncio -async def test_get_zone_flattened_error_async(): +async def test_list_zones_flattened_error_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -13931,20 +13777,214 @@ async def test_get_zone_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_zone( - service.GetZoneRequest(), - name="name_value", + await client.list_zones( + service.ListZonesRequest(), + parent="parent_value", + ) + + +def test_list_zones_pager(transport_name: str = "grpc"): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_zones), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListZonesResponse( + zones=[ + resources.Zone(), + resources.Zone(), + resources.Zone(), + ], + next_page_token="abc", + ), + service.ListZonesResponse( + zones=[], + next_page_token="def", + ), + service.ListZonesResponse( + zones=[ + resources.Zone(), + ], + next_page_token="ghi", + ), + service.ListZonesResponse( + zones=[ + resources.Zone(), + resources.Zone(), + ], + ), + RuntimeError, + ) + + expected_metadata = () + retry = retries.Retry() + timeout = 5 + expected_metadata = tuple(expected_metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_zones(request={}, retry=retry, timeout=timeout) + + assert pager._metadata == expected_metadata + assert pager._retry == retry + assert pager._timeout == timeout + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, resources.Zone) for i in results) + + +def test_list_zones_pages(transport_name: str = "grpc"): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_zones), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListZonesResponse( + zones=[ + resources.Zone(), + resources.Zone(), + resources.Zone(), + ], + next_page_token="abc", + ), + service.ListZonesResponse( + zones=[], + next_page_token="def", + ), + service.ListZonesResponse( + zones=[ + resources.Zone(), + ], + next_page_token="ghi", + ), + service.ListZonesResponse( + zones=[ + resources.Zone(), + resources.Zone(), + ], + ), + RuntimeError, + ) + pages = list(client.list_zones(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_zones_async_pager(): + client = GDCHardwareManagementAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_zones), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListZonesResponse( + zones=[ + resources.Zone(), + resources.Zone(), + resources.Zone(), + ], + next_page_token="abc", + ), + service.ListZonesResponse( + zones=[], + next_page_token="def", + ), + service.ListZonesResponse( + zones=[ + resources.Zone(), + ], + next_page_token="ghi", + ), + service.ListZonesResponse( + zones=[ + resources.Zone(), + resources.Zone(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_zones( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, resources.Zone) for i in responses) + + +@pytest.mark.asyncio +async def test_list_zones_async_pages(): + client = GDCHardwareManagementAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_zones), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + service.ListZonesResponse( + zones=[ + resources.Zone(), + resources.Zone(), + resources.Zone(), + ], + next_page_token="abc", + ), + service.ListZonesResponse( + zones=[], + next_page_token="def", + ), + service.ListZonesResponse( + zones=[ + resources.Zone(), + ], + next_page_token="ghi", + ), + service.ListZonesResponse( + zones=[ + resources.Zone(), + resources.Zone(), + ], + ), + RuntimeError, ) + pages = [] + # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` + # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 + async for page_ in ( # pragma: no branch + await client.list_zones(request={}) + ).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( "request_type", [ - service.CreateZoneRequest, + service.GetZoneRequest, dict, ], ) -def test_create_zone(request_type, transport: str = "grpc"): +def test_get_zone(request_type, transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -13955,22 +13995,33 @@ def test_create_zone(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_zone), "__call__") as call: + with mock.patch.object(type(client.transport.get_zone), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_zone(request) + call.return_value = resources.Zone( + name="name_value", + display_name="display_name_value", + state=resources.Zone.State.ADDITIONAL_INFO_NEEDED, + ciq_uri="ciq_uri_value", + globally_unique_id="globally_unique_id_value", + ) + response = client.get_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = service.CreateZoneRequest() + request = service.GetZoneRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + assert isinstance(response, resources.Zone) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == resources.Zone.State.ADDITIONAL_INFO_NEEDED + assert response.ciq_uri == "ciq_uri_value" + assert response.globally_unique_id == "globally_unique_id_value" -def test_create_zone_empty_call(): +def test_get_zone_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 = GDCHardwareManagementClient( @@ -13979,17 +14030,17 @@ def test_create_zone_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_zone), "__call__") as call: + with mock.patch.object(type(client.transport.get_zone), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.create_zone() + client.get_zone() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateZoneRequest() + assert args[0] == service.GetZoneRequest() -def test_create_zone_non_empty_request_with_auto_populated_field(): +def test_get_zone_non_empty_request_with_auto_populated_field(): # This test is a coverage failsafe to make sure that UUID4 fields are # automatically populated, according to AIP-4235, with non-empty requests. client = GDCHardwareManagementClient( @@ -14000,26 +14051,24 @@ def test_create_zone_non_empty_request_with_auto_populated_field(): # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. - request = service.CreateZoneRequest( - parent="parent_value", - zone_id="zone_id_value", + request = service.GetZoneRequest( + name="name_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_zone), "__call__") as call: + with mock.patch.object(type(client.transport.get_zone), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.create_zone(request=request) + client.get_zone(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateZoneRequest( - parent="parent_value", - zone_id="zone_id_value", + assert args[0] == service.GetZoneRequest( + name="name_value", ) -def test_create_zone_use_cached_wrapped_rpc(): +def test_get_zone_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -14033,26 +14082,21 @@ def test_create_zone_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_zone in client._transport._wrapped_methods + assert client._transport.get_zone in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_zone] = mock_rpc + client._transport._wrapped_methods[client._transport.get_zone] = mock_rpc request = {} - client.create_zone(request) + client.get_zone(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods call wrapper_fn to build a cached - # client._transport.operations_client instance on first rpc call. - # Subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_zone(request) + client.get_zone(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -14060,7 +14104,7 @@ def test_create_zone_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_create_zone_empty_call_async(): +async def test_get_zone_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GDCHardwareManagementAsyncClient( @@ -14069,21 +14113,25 @@ async def test_create_zone_empty_call_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_zone), "__call__") as call: + with mock.patch.object(type(client.transport.get_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + resources.Zone( + name="name_value", + display_name="display_name_value", + state=resources.Zone.State.ADDITIONAL_INFO_NEEDED, + ciq_uri="ciq_uri_value", + globally_unique_id="globally_unique_id_value", + ) ) - response = await client.create_zone() + response = await client.get_zone() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateZoneRequest() + assert args[0] == service.GetZoneRequest() @pytest.mark.asyncio -async def test_create_zone_async_use_cached_wrapped_rpc( - transport: str = "grpc_asyncio", -): +async def test_get_zone_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: @@ -14098,7 +14146,7 @@ async def test_create_zone_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.create_zone + client._client._transport.get_zone in client._client._transport._wrapped_methods ) @@ -14106,21 +14154,16 @@ async def test_create_zone_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.create_zone + client._client._transport.get_zone ] = mock_rpc request = {} - await client.create_zone(request) + await client.get_zone(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods call wrapper_fn to build a cached - # client._transport.operations_client instance on first rpc call. - # Subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - await client.create_zone(request) + await client.get_zone(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -14128,8 +14171,8 @@ async def test_create_zone_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_create_zone_async( - transport: str = "grpc_asyncio", request_type=service.CreateZoneRequest +async def test_get_zone_async( + transport: str = "grpc_asyncio", request_type=service.GetZoneRequest ): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14141,43 +14184,54 @@ async def test_create_zone_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_zone), "__call__") as call: + with mock.patch.object(type(client.transport.get_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + resources.Zone( + name="name_value", + display_name="display_name_value", + state=resources.Zone.State.ADDITIONAL_INFO_NEEDED, + ciq_uri="ciq_uri_value", + globally_unique_id="globally_unique_id_value", + ) ) - response = await client.create_zone(request) + response = await client.get_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = service.CreateZoneRequest() + request = service.GetZoneRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + assert isinstance(response, resources.Zone) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == resources.Zone.State.ADDITIONAL_INFO_NEEDED + assert response.ciq_uri == "ciq_uri_value" + assert response.globally_unique_id == "globally_unique_id_value" @pytest.mark.asyncio -async def test_create_zone_async_from_dict(): - await test_create_zone_async(request_type=dict) +async def test_get_zone_async_from_dict(): + await test_get_zone_async(request_type=dict) -def test_create_zone_field_headers(): +def test_get_zone_field_headers(): client = GDCHardwareManagementClient( 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 = service.CreateZoneRequest() + request = service.GetZoneRequest() - request.parent = "parent_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_zone), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_zone(request) + with mock.patch.object(type(client.transport.get_zone), "__call__") as call: + call.return_value = resources.Zone() + client.get_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -14188,28 +14242,26 @@ def test_create_zone_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_create_zone_field_headers_async(): +async def test_get_zone_field_headers_async(): client = GDCHardwareManagementAsyncClient( 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 = service.CreateZoneRequest() + request = service.GetZoneRequest() - request.parent = "parent_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_zone), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") - ) - await client.create_zone(request) + with mock.patch.object(type(client.transport.get_zone), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Zone()) + await client.get_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -14220,43 +14272,35 @@ async def test_create_zone_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] -def test_create_zone_flattened(): +def test_get_zone_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_zone), "__call__") as call: + with mock.patch.object(type(client.transport.get_zone), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = resources.Zone() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.create_zone( - parent="parent_value", - zone=resources.Zone(name="name_value"), - zone_id="zone_id_value", + client.get_zone( + 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] - arg = args[0].parent - mock_val = "parent_value" - assert arg == mock_val - arg = args[0].zone - mock_val = resources.Zone(name="name_value") - assert arg == mock_val - arg = args[0].zone_id - mock_val = "zone_id_value" + arg = args[0].name + mock_val = "name_value" assert arg == mock_val -def test_create_zone_flattened_error(): +def test_get_zone_flattened_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -14264,53 +14308,41 @@ def test_create_zone_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_zone( - service.CreateZoneRequest(), - parent="parent_value", - zone=resources.Zone(name="name_value"), - zone_id="zone_id_value", + client.get_zone( + service.GetZoneRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_create_zone_flattened_async(): +async def test_get_zone_flattened_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_zone), "__call__") as call: + with mock.patch.object(type(client.transport.get_zone), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = resources.Zone() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Zone()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.create_zone( - parent="parent_value", - zone=resources.Zone(name="name_value"), - zone_id="zone_id_value", + response = await client.get_zone( + 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] - arg = args[0].parent - mock_val = "parent_value" - assert arg == mock_val - arg = args[0].zone - mock_val = resources.Zone(name="name_value") - assert arg == mock_val - arg = args[0].zone_id - mock_val = "zone_id_value" + arg = args[0].name + mock_val = "name_value" assert arg == mock_val @pytest.mark.asyncio -async def test_create_zone_flattened_error_async(): +async def test_get_zone_flattened_error_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -14318,22 +14350,20 @@ async def test_create_zone_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.create_zone( - service.CreateZoneRequest(), - parent="parent_value", - zone=resources.Zone(name="name_value"), - zone_id="zone_id_value", + await client.get_zone( + service.GetZoneRequest(), + name="name_value", ) @pytest.mark.parametrize( "request_type", [ - service.UpdateZoneRequest, + service.CreateZoneRequest, dict, ], ) -def test_update_zone(request_type, transport: str = "grpc"): +def test_create_zone(request_type, transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -14344,22 +14374,22 @@ def test_update_zone(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_zone), "__call__") as call: + with mock.patch.object(type(client.transport.create_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_zone(request) + response = client.create_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = service.UpdateZoneRequest() + request = service.CreateZoneRequest() assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, future.Future) -def test_update_zone_empty_call(): +def test_create_zone_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 = GDCHardwareManagementClient( @@ -14368,17 +14398,17 @@ def test_update_zone_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_zone), "__call__") as call: + with mock.patch.object(type(client.transport.create_zone), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.update_zone() + client.create_zone() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateZoneRequest() + assert args[0] == service.CreateZoneRequest() -def test_update_zone_non_empty_request_with_auto_populated_field(): +def test_create_zone_non_empty_request_with_auto_populated_field(): # This test is a coverage failsafe to make sure that UUID4 fields are # automatically populated, according to AIP-4235, with non-empty requests. client = GDCHardwareManagementClient( @@ -14389,20 +14419,26 @@ def test_update_zone_non_empty_request_with_auto_populated_field(): # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. - request = service.UpdateZoneRequest() + request = service.CreateZoneRequest( + parent="parent_value", + zone_id="zone_id_value", + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_zone), "__call__") as call: + with mock.patch.object(type(client.transport.create_zone), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.update_zone(request=request) + client.create_zone(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateZoneRequest() + assert args[0] == service.CreateZoneRequest( + parent="parent_value", + zone_id="zone_id_value", + ) -def test_update_zone_use_cached_wrapped_rpc(): +def test_create_zone_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -14416,16 +14452,16 @@ def test_update_zone_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_zone in client._transport._wrapped_methods + assert client._transport.create_zone in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_zone] = mock_rpc + client._transport._wrapped_methods[client._transport.create_zone] = mock_rpc request = {} - client.update_zone(request) + client.create_zone(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -14435,7 +14471,7 @@ def test_update_zone_use_cached_wrapped_rpc(): # Subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.update_zone(request) + client.create_zone(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -14443,7 +14479,7 @@ def test_update_zone_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_update_zone_empty_call_async(): +async def test_create_zone_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GDCHardwareManagementAsyncClient( @@ -14452,19 +14488,19 @@ async def test_update_zone_empty_call_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_zone), "__call__") as call: + with mock.patch.object(type(client.transport.create_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_zone() + response = await client.create_zone() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateZoneRequest() + assert args[0] == service.CreateZoneRequest() @pytest.mark.asyncio -async def test_update_zone_async_use_cached_wrapped_rpc( +async def test_create_zone_async_use_cached_wrapped_rpc( transport: str = "grpc_asyncio", ): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, @@ -14481,7 +14517,7 @@ async def test_update_zone_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.update_zone + client._client._transport.create_zone in client._client._transport._wrapped_methods ) @@ -14489,11 +14525,11 @@ async def test_update_zone_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.update_zone + client._client._transport.create_zone ] = mock_rpc request = {} - await client.update_zone(request) + await client.create_zone(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -14503,7 +14539,7 @@ async def test_update_zone_async_use_cached_wrapped_rpc( # Subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - await client.update_zone(request) + await client.create_zone(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -14511,8 +14547,8 @@ async def test_update_zone_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_update_zone_async( - transport: str = "grpc_asyncio", request_type=service.UpdateZoneRequest +async def test_create_zone_async( + transport: str = "grpc_asyncio", request_type=service.CreateZoneRequest ): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14524,17 +14560,17 @@ async def test_update_zone_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_zone), "__call__") as call: + with mock.patch.object(type(client.transport.create_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_zone(request) + response = await client.create_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = service.UpdateZoneRequest() + request = service.CreateZoneRequest() assert args[0] == request # Establish that the response is the type that we expect. @@ -14542,25 +14578,25 @@ async def test_update_zone_async( @pytest.mark.asyncio -async def test_update_zone_async_from_dict(): - await test_update_zone_async(request_type=dict) +async def test_create_zone_async_from_dict(): + await test_create_zone_async(request_type=dict) -def test_update_zone_field_headers(): +def test_create_zone_field_headers(): client = GDCHardwareManagementClient( 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 = service.UpdateZoneRequest() + request = service.CreateZoneRequest() - request.zone.name = "name_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_zone), "__call__") as call: + with mock.patch.object(type(client.transport.create_zone), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_zone(request) + client.create_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -14571,28 +14607,28 @@ def test_update_zone_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "zone.name=name_value", + "parent=parent_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_zone_field_headers_async(): +async def test_create_zone_field_headers_async(): client = GDCHardwareManagementAsyncClient( 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 = service.UpdateZoneRequest() + request = service.CreateZoneRequest() - request.zone.name = "name_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_zone), "__call__") as call: + with mock.patch.object(type(client.transport.create_zone), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_zone(request) + await client.create_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -14603,39 +14639,43 @@ async def test_update_zone_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "zone.name=name_value", + "parent=parent_value", ) in kw["metadata"] -def test_update_zone_flattened(): +def test_create_zone_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_zone), "__call__") as call: + with mock.patch.object(type(client.transport.create_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_zone( + client.create_zone( + parent="parent_value", zone=resources.Zone(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + zone_id="zone_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] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val arg = args[0].zone mock_val = resources.Zone(name="name_value") assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].zone_id + mock_val = "zone_id_value" assert arg == mock_val -def test_update_zone_flattened_error(): +def test_create_zone_flattened_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -14643,21 +14683,22 @@ def test_update_zone_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_zone( - service.UpdateZoneRequest(), + client.create_zone( + service.CreateZoneRequest(), + parent="parent_value", zone=resources.Zone(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + zone_id="zone_id_value", ) @pytest.mark.asyncio -async def test_update_zone_flattened_async(): +async def test_create_zone_flattened_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_zone), "__call__") as call: + with mock.patch.object(type(client.transport.create_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -14666,25 +14707,29 @@ async def test_update_zone_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_zone( + response = await client.create_zone( + parent="parent_value", zone=resources.Zone(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + zone_id="zone_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] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val arg = args[0].zone mock_val = resources.Zone(name="name_value") assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].zone_id + mock_val = "zone_id_value" assert arg == mock_val @pytest.mark.asyncio -async def test_update_zone_flattened_error_async(): +async def test_create_zone_flattened_error_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -14692,21 +14737,22 @@ async def test_update_zone_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.update_zone( - service.UpdateZoneRequest(), + await client.create_zone( + service.CreateZoneRequest(), + parent="parent_value", zone=resources.Zone(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + zone_id="zone_id_value", ) @pytest.mark.parametrize( "request_type", [ - service.DeleteZoneRequest, + service.UpdateZoneRequest, dict, ], ) -def test_delete_zone(request_type, transport: str = "grpc"): +def test_update_zone(request_type, transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -14717,22 +14763,22 @@ def test_delete_zone(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: + with mock.patch.object(type(client.transport.update_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_zone(request) + response = client.update_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = service.DeleteZoneRequest() + request = service.UpdateZoneRequest() assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, future.Future) -def test_delete_zone_empty_call(): +def test_update_zone_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 = GDCHardwareManagementClient( @@ -14741,17 +14787,17 @@ def test_delete_zone_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: + with mock.patch.object(type(client.transport.update_zone), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.delete_zone() + client.update_zone() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteZoneRequest() + assert args[0] == service.UpdateZoneRequest() -def test_delete_zone_non_empty_request_with_auto_populated_field(): +def test_update_zone_non_empty_request_with_auto_populated_field(): # This test is a coverage failsafe to make sure that UUID4 fields are # automatically populated, according to AIP-4235, with non-empty requests. client = GDCHardwareManagementClient( @@ -14762,24 +14808,20 @@ def test_delete_zone_non_empty_request_with_auto_populated_field(): # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. - request = service.DeleteZoneRequest( - name="name_value", - ) + request = service.UpdateZoneRequest() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: + with mock.patch.object(type(client.transport.update_zone), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.delete_zone(request=request) + client.update_zone(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteZoneRequest( - name="name_value", - ) + assert args[0] == service.UpdateZoneRequest() -def test_delete_zone_use_cached_wrapped_rpc(): +def test_update_zone_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -14793,16 +14835,16 @@ def test_delete_zone_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_zone in client._transport._wrapped_methods + assert client._transport.update_zone in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_zone] = mock_rpc + client._transport._wrapped_methods[client._transport.update_zone] = mock_rpc request = {} - client.delete_zone(request) + client.update_zone(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -14812,7 +14854,7 @@ def test_delete_zone_use_cached_wrapped_rpc(): # Subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.delete_zone(request) + client.update_zone(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -14820,7 +14862,7 @@ def test_delete_zone_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_delete_zone_empty_call_async(): +async def test_update_zone_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GDCHardwareManagementAsyncClient( @@ -14829,19 +14871,19 @@ async def test_delete_zone_empty_call_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: + with mock.patch.object(type(client.transport.update_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_zone() + response = await client.update_zone() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteZoneRequest() + assert args[0] == service.UpdateZoneRequest() @pytest.mark.asyncio -async def test_delete_zone_async_use_cached_wrapped_rpc( +async def test_update_zone_async_use_cached_wrapped_rpc( transport: str = "grpc_asyncio", ): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, @@ -14858,7 +14900,7 @@ async def test_delete_zone_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.delete_zone + client._client._transport.update_zone in client._client._transport._wrapped_methods ) @@ -14866,11 +14908,11 @@ async def test_delete_zone_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.delete_zone + client._client._transport.update_zone ] = mock_rpc request = {} - await client.delete_zone(request) + await client.update_zone(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -14880,7 +14922,7 @@ async def test_delete_zone_async_use_cached_wrapped_rpc( # Subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - await client.delete_zone(request) + await client.update_zone(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -14888,8 +14930,8 @@ async def test_delete_zone_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_delete_zone_async( - transport: str = "grpc_asyncio", request_type=service.DeleteZoneRequest +async def test_update_zone_async( + transport: str = "grpc_asyncio", request_type=service.UpdateZoneRequest ): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14901,17 +14943,17 @@ async def test_delete_zone_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: + with mock.patch.object(type(client.transport.update_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_zone(request) + response = await client.update_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = service.DeleteZoneRequest() + request = service.UpdateZoneRequest() assert args[0] == request # Establish that the response is the type that we expect. @@ -14919,25 +14961,25 @@ async def test_delete_zone_async( @pytest.mark.asyncio -async def test_delete_zone_async_from_dict(): - await test_delete_zone_async(request_type=dict) +async def test_update_zone_async_from_dict(): + await test_update_zone_async(request_type=dict) -def test_delete_zone_field_headers(): +def test_update_zone_field_headers(): client = GDCHardwareManagementClient( 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 = service.DeleteZoneRequest() + request = service.UpdateZoneRequest() - request.name = "name_value" + request.zone.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: + with mock.patch.object(type(client.transport.update_zone), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_zone(request) + client.update_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -14948,28 +14990,28 @@ def test_delete_zone_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "zone.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_delete_zone_field_headers_async(): +async def test_update_zone_field_headers_async(): client = GDCHardwareManagementAsyncClient( 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 = service.DeleteZoneRequest() + request = service.UpdateZoneRequest() - request.name = "name_value" + request.zone.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: + with mock.patch.object(type(client.transport.update_zone), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_zone(request) + await client.update_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -14980,35 +15022,39 @@ async def test_delete_zone_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "zone.name=name_value", ) in kw["metadata"] -def test_delete_zone_flattened(): +def test_update_zone_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: + with mock.patch.object(type(client.transport.update_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_zone( - name="name_value", + client.update_zone( + zone=resources.Zone(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] - arg = args[0].name - mock_val = "name_value" + arg = args[0].zone + mock_val = resources.Zone(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) assert arg == mock_val -def test_delete_zone_flattened_error(): +def test_update_zone_flattened_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -15016,20 +15062,21 @@ def test_delete_zone_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_zone( - service.DeleteZoneRequest(), - name="name_value", + client.update_zone( + service.UpdateZoneRequest(), + zone=resources.Zone(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_delete_zone_flattened_async(): +async def test_update_zone_flattened_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: + with mock.patch.object(type(client.transport.update_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -15038,21 +15085,25 @@ async def test_delete_zone_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_zone( - name="name_value", + response = await client.update_zone( + zone=resources.Zone(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] - arg = args[0].name - mock_val = "name_value" + arg = args[0].zone + mock_val = resources.Zone(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) assert arg == mock_val @pytest.mark.asyncio -async def test_delete_zone_flattened_error_async(): +async def test_update_zone_flattened_error_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -15060,20 +15111,21 @@ async def test_delete_zone_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.delete_zone( - service.DeleteZoneRequest(), - name="name_value", + await client.update_zone( + service.UpdateZoneRequest(), + zone=resources.Zone(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.parametrize( "request_type", [ - service.SignalZoneStateRequest, + service.DeleteZoneRequest, dict, ], ) -def test_signal_zone_state(request_type, transport: str = "grpc"): +def test_delete_zone(request_type, transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -15084,24 +15136,22 @@ def test_signal_zone_state(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.signal_zone_state), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.signal_zone_state(request) + response = client.delete_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = service.SignalZoneStateRequest() + request = service.DeleteZoneRequest() assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, future.Future) -def test_signal_zone_state_empty_call(): +def test_delete_zone_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 = GDCHardwareManagementClient( @@ -15110,19 +15160,17 @@ def test_signal_zone_state_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.signal_zone_state), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.signal_zone_state() + client.delete_zone() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.SignalZoneStateRequest() + assert args[0] == service.DeleteZoneRequest() -def test_signal_zone_state_non_empty_request_with_auto_populated_field(): +def test_delete_zone_non_empty_request_with_auto_populated_field(): # This test is a coverage failsafe to make sure that UUID4 fields are # automatically populated, according to AIP-4235, with non-empty requests. client = GDCHardwareManagementClient( @@ -15133,26 +15181,24 @@ def test_signal_zone_state_non_empty_request_with_auto_populated_field(): # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. - request = service.SignalZoneStateRequest( + request = service.DeleteZoneRequest( name="name_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.signal_zone_state), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.signal_zone_state(request=request) + client.delete_zone(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.SignalZoneStateRequest( + assert args[0] == service.DeleteZoneRequest( name="name_value", ) -def test_signal_zone_state_use_cached_wrapped_rpc(): +def test_delete_zone_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -15166,18 +15212,16 @@ def test_signal_zone_state_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.signal_zone_state in client._transport._wrapped_methods + assert client._transport.delete_zone in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.signal_zone_state - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_zone] = mock_rpc request = {} - client.signal_zone_state(request) + client.delete_zone(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -15187,7 +15231,7 @@ def test_signal_zone_state_use_cached_wrapped_rpc(): # Subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.signal_zone_state(request) + client.delete_zone(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -15195,7 +15239,7 @@ def test_signal_zone_state_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_signal_zone_state_empty_call_async(): +async def test_delete_zone_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GDCHardwareManagementAsyncClient( @@ -15204,21 +15248,19 @@ async def test_signal_zone_state_empty_call_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.signal_zone_state), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.signal_zone_state() + response = await client.delete_zone() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.SignalZoneStateRequest() + assert args[0] == service.DeleteZoneRequest() @pytest.mark.asyncio -async def test_signal_zone_state_async_use_cached_wrapped_rpc( +async def test_delete_zone_async_use_cached_wrapped_rpc( transport: str = "grpc_asyncio", ): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, @@ -15235,7 +15277,7 @@ async def test_signal_zone_state_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.signal_zone_state + client._client._transport.delete_zone in client._client._transport._wrapped_methods ) @@ -15243,11 +15285,11 @@ async def test_signal_zone_state_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.signal_zone_state + client._client._transport.delete_zone ] = mock_rpc request = {} - await client.signal_zone_state(request) + await client.delete_zone(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -15257,7 +15299,7 @@ async def test_signal_zone_state_async_use_cached_wrapped_rpc( # Subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - await client.signal_zone_state(request) + await client.delete_zone(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -15265,8 +15307,8 @@ async def test_signal_zone_state_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_signal_zone_state_async( - transport: str = "grpc_asyncio", request_type=service.SignalZoneStateRequest +async def test_delete_zone_async( + transport: str = "grpc_asyncio", request_type=service.DeleteZoneRequest ): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15278,19 +15320,17 @@ async def test_signal_zone_state_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.signal_zone_state), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.signal_zone_state(request) + response = await client.delete_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = service.SignalZoneStateRequest() + request = service.DeleteZoneRequest() assert args[0] == request # Establish that the response is the type that we expect. @@ -15298,27 +15338,25 @@ async def test_signal_zone_state_async( @pytest.mark.asyncio -async def test_signal_zone_state_async_from_dict(): - await test_signal_zone_state_async(request_type=dict) +async def test_delete_zone_async_from_dict(): + await test_delete_zone_async(request_type=dict) -def test_signal_zone_state_field_headers(): +def test_delete_zone_field_headers(): client = GDCHardwareManagementClient( 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 = service.SignalZoneStateRequest() + request = service.DeleteZoneRequest() request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.signal_zone_state), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.signal_zone_state(request) + client.delete_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -15334,25 +15372,23 @@ def test_signal_zone_state_field_headers(): @pytest.mark.asyncio -async def test_signal_zone_state_field_headers_async(): +async def test_delete_zone_field_headers_async(): client = GDCHardwareManagementAsyncClient( 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 = service.SignalZoneStateRequest() + request = service.DeleteZoneRequest() request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.signal_zone_state), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.signal_zone_state(request) + await client.delete_zone(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -15367,22 +15403,19 @@ async def test_signal_zone_state_field_headers_async(): ) in kw["metadata"] -def test_signal_zone_state_flattened(): +def test_delete_zone_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.signal_zone_state), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.signal_zone_state( + client.delete_zone( name="name_value", - state_signal=service.SignalZoneStateRequest.StateSignal.READY_FOR_SITE_TURNUP, ) # Establish that the underlying call was made with the expected @@ -15392,12 +15425,9 @@ def test_signal_zone_state_flattened(): arg = args[0].name mock_val = "name_value" assert arg == mock_val - arg = args[0].state_signal - mock_val = service.SignalZoneStateRequest.StateSignal.READY_FOR_SITE_TURNUP - assert arg == mock_val -def test_signal_zone_state_flattened_error(): +def test_delete_zone_flattened_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -15405,23 +15435,20 @@ def test_signal_zone_state_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.signal_zone_state( - service.SignalZoneStateRequest(), + client.delete_zone( + service.DeleteZoneRequest(), name="name_value", - state_signal=service.SignalZoneStateRequest.StateSignal.READY_FOR_SITE_TURNUP, ) @pytest.mark.asyncio -async def test_signal_zone_state_flattened_async(): +async def test_delete_zone_flattened_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.signal_zone_state), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_zone), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -15430,9 +15457,8 @@ async def test_signal_zone_state_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.signal_zone_state( + response = await client.delete_zone( name="name_value", - state_signal=service.SignalZoneStateRequest.StateSignal.READY_FOR_SITE_TURNUP, ) # Establish that the underlying call was made with the expected @@ -15442,13 +15468,10 @@ async def test_signal_zone_state_flattened_async(): arg = args[0].name mock_val = "name_value" assert arg == mock_val - arg = args[0].state_signal - mock_val = service.SignalZoneStateRequest.StateSignal.READY_FOR_SITE_TURNUP - assert arg == mock_val @pytest.mark.asyncio -async def test_signal_zone_state_flattened_error_async(): +async def test_delete_zone_flattened_error_async(): client = GDCHardwareManagementAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -15456,56 +15479,845 @@ async def test_signal_zone_state_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.signal_zone_state( - service.SignalZoneStateRequest(), + await client.delete_zone( + service.DeleteZoneRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + service.SignalZoneStateRequest, + dict, + ], +) +def test_signal_zone_state(request_type, transport: str = "grpc"): + client = GDCHardwareManagementClient( + 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.signal_zone_state), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.signal_zone_state(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = service.SignalZoneStateRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_signal_zone_state_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 = GDCHardwareManagementClient( + 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.signal_zone_state), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.signal_zone_state() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.SignalZoneStateRequest() + + +def test_signal_zone_state_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = service.SignalZoneStateRequest( + name="name_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.signal_zone_state), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.signal_zone_state(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.SignalZoneStateRequest( name="name_value", - state_signal=service.SignalZoneStateRequest.StateSignal.READY_FOR_SITE_TURNUP, ) +def test_signal_zone_state_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.signal_zone_state in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.signal_zone_state + ] = mock_rpc + request = {} + client.signal_zone_state(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.signal_zone_state(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_signal_zone_state_empty_call_async(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GDCHardwareManagementAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.signal_zone_state), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.signal_zone_state() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.SignalZoneStateRequest() + + +@pytest.mark.asyncio +async def test_signal_zone_state_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = GDCHardwareManagementAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.signal_zone_state + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.signal_zone_state + ] = mock_rpc + + request = {} + await client.signal_zone_state(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.signal_zone_state(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_signal_zone_state_async( + transport: str = "grpc_asyncio", request_type=service.SignalZoneStateRequest +): + client = GDCHardwareManagementAsyncClient( + 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.signal_zone_state), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.signal_zone_state(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = service.SignalZoneStateRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_signal_zone_state_async_from_dict(): + await test_signal_zone_state_async(request_type=dict) + + +def test_signal_zone_state_field_headers(): + client = GDCHardwareManagementClient( + 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 = service.SignalZoneStateRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.signal_zone_state), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.signal_zone_state(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_signal_zone_state_field_headers_async(): + client = GDCHardwareManagementAsyncClient( + 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 = service.SignalZoneStateRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.signal_zone_state), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.signal_zone_state(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_signal_zone_state_flattened(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.signal_zone_state), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.signal_zone_state( + name="name_value", + state_signal=service.SignalZoneStateRequest.StateSignal.FACTORY_TURNUP_CHECKS_PASSED, + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].state_signal + mock_val = ( + service.SignalZoneStateRequest.StateSignal.FACTORY_TURNUP_CHECKS_PASSED + ) + assert arg == mock_val + + +def test_signal_zone_state_flattened_error(): + client = GDCHardwareManagementClient( + 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.signal_zone_state( + service.SignalZoneStateRequest(), + name="name_value", + state_signal=service.SignalZoneStateRequest.StateSignal.FACTORY_TURNUP_CHECKS_PASSED, + ) + + +@pytest.mark.asyncio +async def test_signal_zone_state_flattened_async(): + client = GDCHardwareManagementAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.signal_zone_state), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.signal_zone_state( + name="name_value", + state_signal=service.SignalZoneStateRequest.StateSignal.FACTORY_TURNUP_CHECKS_PASSED, + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].state_signal + mock_val = ( + service.SignalZoneStateRequest.StateSignal.FACTORY_TURNUP_CHECKS_PASSED + ) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_signal_zone_state_flattened_error_async(): + client = GDCHardwareManagementAsyncClient( + 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.signal_zone_state( + service.SignalZoneStateRequest(), + name="name_value", + state_signal=service.SignalZoneStateRequest.StateSignal.FACTORY_TURNUP_CHECKS_PASSED, + ) + + +@pytest.mark.parametrize( + "request_type", + [ + service.ListOrdersRequest, + dict, + ], +) +def test_list_orders_rest(request_type): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = service.ListOrdersResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service.ListOrdersResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.list_orders(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListOrdersPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +def test_list_orders_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_orders in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.list_orders] = mock_rpc + + request = {} + client.list_orders(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_orders(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_orders_rest_required_fields(request_type=service.ListOrdersRequest): + transport_class = transports.GDCHardwareManagementRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_orders._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_orders._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "filter", + "order_by", + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = service.ListOrdersResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = service.ListOrdersResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.list_orders(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_list_orders_rest_unset_required_fields(): + transport = transports.GDCHardwareManagementRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.list_orders._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "filter", + "orderBy", + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_orders_rest_interceptors(null_interceptor): + transport = transports.GDCHardwareManagementRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.GDCHardwareManagementRestInterceptor(), + ) + client = GDCHardwareManagementClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_list_orders" + ) as post, mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_list_orders" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = service.ListOrdersRequest.pb(service.ListOrdersRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = service.ListOrdersResponse.to_json( + service.ListOrdersResponse() + ) + + request = service.ListOrdersRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = service.ListOrdersResponse() + + client.list_orders( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_orders_rest_bad_request( + transport: str = "rest", request_type=service.ListOrdersRequest +): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_orders(request) + + +def test_list_orders_rest_flattened(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = service.ListOrdersResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service.ListOrdersResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.list_orders(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1alpha/{parent=projects/*/locations/*}/orders" + % client.transport._host, + args[1], + ) + + +def test_list_orders_rest_flattened_error(transport: str = "rest"): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_orders( + service.ListOrdersRequest(), + parent="parent_value", + ) + + +def test_list_orders_rest_pager(transport: str = "rest"): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + service.ListOrdersResponse( + orders=[ + resources.Order(), + resources.Order(), + resources.Order(), + ], + next_page_token="abc", + ), + service.ListOrdersResponse( + orders=[], + next_page_token="def", + ), + service.ListOrdersResponse( + orders=[ + resources.Order(), + ], + next_page_token="ghi", + ), + service.ListOrdersResponse( + orders=[ + resources.Order(), + resources.Order(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(service.ListOrdersResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_orders(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, resources.Order) for i in results) + + pages = list(client.list_orders(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + @pytest.mark.parametrize( "request_type", [ - service.ListOrdersRequest, + service.GetOrderRequest, dict, ], ) -def test_list_orders_rest(request_type): +def test_get_order_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"name": "projects/sample1/locations/sample2/orders/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service.ListOrdersResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + return_value = resources.Order( + name="name_value", + display_name="display_name_value", + state=resources.Order.State.DRAFT, + target_workloads=["target_workloads_value"], + customer_motivation="customer_motivation_value", + region_code="region_code_value", + order_form_uri="order_form_uri_value", + type_=resources.Order.Type.PAID, + billing_id="billing_id_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListOrdersResponse.pb(return_value) + return_value = resources.Order.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_orders(request) + response = client.get_order(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListOrdersPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, resources.Order) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == resources.Order.State.DRAFT + assert response.target_workloads == ["target_workloads_value"] + assert response.customer_motivation == "customer_motivation_value" + assert response.region_code == "region_code_value" + assert response.order_form_uri == "order_form_uri_value" + assert response.type_ == resources.Order.Type.PAID + assert response.billing_id == "billing_id_value" -def test_list_orders_rest_use_cached_wrapped_rpc(): +def test_get_order_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -15519,33 +16331,33 @@ def test_list_orders_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_orders in client._transport._wrapped_methods + assert client._transport.get_order in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_orders] = mock_rpc + client._transport._wrapped_methods[client._transport.get_order] = mock_rpc request = {} - client.list_orders(request) + client.get_order(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_orders(request) + client.get_order(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_orders_rest_required_fields(request_type=service.ListOrdersRequest): +def test_get_order_rest_required_fields(request_type=service.GetOrderRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["parent"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -15556,30 +16368,21 @@ def test_list_orders_rest_required_fields(request_type=service.ListOrdersRequest unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_orders._get_unset_required_fields(jsonified_request) + ).get_order._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_orders._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "filter", - "order_by", - "page_size", - "page_token", - ) - ) + ).get_order._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15588,7 +16391,7 @@ def test_list_orders_rest_required_fields(request_type=service.ListOrdersRequest request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = service.ListOrdersResponse() + return_value = resources.Order() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -15609,40 +16412,30 @@ def test_list_orders_rest_required_fields(request_type=service.ListOrdersRequest response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListOrdersResponse.pb(return_value) + return_value = resources.Order.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_orders(request) + response = client.get_order(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_orders_rest_unset_required_fields(): +def test_get_order_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_orders._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "filter", - "orderBy", - "pageSize", - "pageToken", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.get_order._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_orders_rest_interceptors(null_interceptor): +def test_get_order_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -15655,13 +16448,13 @@ def test_list_orders_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_orders" + transports.GDCHardwareManagementRestInterceptor, "post_get_order" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_orders" + transports.GDCHardwareManagementRestInterceptor, "pre_get_order" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.ListOrdersRequest.pb(service.ListOrdersRequest()) + pb_message = service.GetOrderRequest.pb(service.GetOrderRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -15672,19 +16465,17 @@ def test_list_orders_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = service.ListOrdersResponse.to_json( - service.ListOrdersResponse() - ) + req.return_value._content = resources.Order.to_json(resources.Order()) - request = service.ListOrdersRequest() + request = service.GetOrderRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = service.ListOrdersResponse() + post.return_value = resources.Order() - client.list_orders( + client.get_order( request, metadata=[ ("key", "val"), @@ -15696,8 +16487,8 @@ def test_list_orders_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_orders_rest_bad_request( - transport: str = "rest", request_type=service.ListOrdersRequest +def test_get_order_rest_bad_request( + transport: str = "rest", request_type=service.GetOrderRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15705,7 +16496,7 @@ def test_list_orders_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"name": "projects/sample1/locations/sample2/orders/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -15717,10 +16508,10 @@ def test_list_orders_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.list_orders(request) + client.get_order(request) -def test_list_orders_rest_flattened(): +def test_get_order_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -15729,14 +16520,14 @@ def test_list_orders_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service.ListOrdersResponse() + return_value = resources.Order() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = {"name": "projects/sample1/locations/sample2/orders/sample3"} # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + name="name_value", ) mock_args.update(sample_request) @@ -15744,25 +16535,25 @@ def test_list_orders_rest_flattened(): response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListOrdersResponse.pb(return_value) + return_value = resources.Order.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.list_orders(**mock_args) + client.get_order(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{parent=projects/*/locations/*}/orders" + "%s/v1alpha/{name=projects/*/locations/*/orders/*}" % client.transport._host, args[1], ) -def test_list_orders_rest_flattened_error(transport: str = "rest"): +def test_get_order_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -15771,130 +16562,182 @@ def test_list_orders_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_orders( - service.ListOrdersRequest(), - parent="parent_value", + client.get_order( + service.GetOrderRequest(), + name="name_value", ) -def test_list_orders_rest_pager(transport: str = "rest"): +def test_get_order_rest_error(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + service.CreateOrderRequest, + dict, + ], +) +def test_create_order_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + transport="rest", ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - service.ListOrdersResponse( - orders=[ - resources.Order(), - resources.Order(), - resources.Order(), - ], - next_page_token="abc", - ), - service.ListOrdersResponse( - orders=[], - next_page_token="def", - ), - service.ListOrdersResponse( - orders=[ - resources.Order(), - ], - next_page_token="ghi", - ), - service.ListOrdersResponse( - orders=[ - resources.Order(), - resources.Order(), - ], - ), - ) - # Two responses for two calls - response = response + response + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["order"] = { + "name": "name_value", + "display_name": "display_name_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "labels": {}, + "state": 1, + "organization_contact": { + "address": { + "revision": 879, + "region_code": "region_code_value", + "language_code": "language_code_value", + "postal_code": "postal_code_value", + "sorting_code": "sorting_code_value", + "administrative_area": "administrative_area_value", + "locality": "locality_value", + "sublocality": "sublocality_value", + "address_lines": ["address_lines_value1", "address_lines_value2"], + "recipients": ["recipients_value1", "recipients_value2"], + "organization": "organization_value", + }, + "email": "email_value", + "phone": "phone_value", + "contacts": [ + { + "given_name": "given_name_value", + "family_name": "family_name_value", + "email": "email_value", + "phone": "phone_value", + "time_zone": {"id": "id_value", "version": "version_value"}, + "reachable_times": [ + { + "start_time": { + "hours": 561, + "minutes": 773, + "seconds": 751, + "nanos": 543, + }, + "end_time": {}, + "days": [1], + } + ], + } + ], + }, + "target_workloads": ["target_workloads_value1", "target_workloads_value2"], + "customer_motivation": "customer_motivation_value", + "fulfillment_time": {}, + "region_code": "region_code_value", + "order_form_uri": "order_form_uri_value", + "type_": 1, + "submit_time": {}, + "billing_id": "billing_id_value", + "existing_hardware": [ + { + "site": "site_value", + "rack_location": "rack_location_value", + "rack_space": [{"start_rack_unit": 1613, "end_rack_unit": 1366}], + } + ], + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 - # Wrap the values into proper Response objs - response = tuple(service.ListOrdersResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values + # Determine if the message type is proto-plus or protobuf + test_field = service.CreateOrderRequest.meta.fields["order"] - sample_request = {"parent": "projects/sample1/locations/sample2"} + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] - pager = client.list_orders(request=sample_request) + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, resources.Order) for i in results) + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields - pages = list(client.list_orders(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + subfields_not_in_runtime = [] -@pytest.mark.parametrize( - "request_type", - [ - service.GetOrderRequest, - dict, - ], -) -def test_get_order_rest(request_type): - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["order"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value - # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/orders/sample3"} + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["order"][field])): + del request_init["order"][field][i][subfield] + else: + del request_init["order"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = resources.Order( - name="name_value", - display_name="display_name_value", - state=resources.Order.State.DRAFT, - target_workloads=["target_workloads_value"], - customer_motivation="customer_motivation_value", - region_code="region_code_value", - order_form_uri="order_form_uri_value", - type_=resources.Order.Type.PAID, - billing_id="billing_id_value", - ) + return_value = operations_pb2.Operation(name="operations/spam") # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = resources.Order.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_order(request) + response = client.create_order(request) # Establish that the response is the type that we expect. - assert isinstance(response, resources.Order) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.state == resources.Order.State.DRAFT - assert response.target_workloads == ["target_workloads_value"] - assert response.customer_motivation == "customer_motivation_value" - assert response.region_code == "region_code_value" - assert response.order_form_uri == "order_form_uri_value" - assert response.type_ == resources.Order.Type.PAID - assert response.billing_id == "billing_id_value" + assert response.operation.name == "operations/spam" -def test_get_order_rest_use_cached_wrapped_rpc(): +def test_create_order_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -15908,33 +16751,37 @@ def test_get_order_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_order in client._transport._wrapped_methods + assert client._transport.create_order in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_order] = mock_rpc + client._transport._wrapped_methods[client._transport.create_order] = mock_rpc request = {} - client.get_order(request) + client.create_order(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_order(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_order(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_order_rest_required_fields(request_type=service.GetOrderRequest): +def test_create_order_rest_required_fields(request_type=service.CreateOrderRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -15945,21 +16792,28 @@ def test_get_order_rest_required_fields(request_type=service.GetOrderRequest): unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_order._get_unset_required_fields(jsonified_request) + ).create_order._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_order._get_unset_required_fields(jsonified_request) + ).create_order._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "order_id", + "request_id", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15968,7 +16822,7 @@ def test_get_order_rest_required_fields(request_type=service.GetOrderRequest): request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = resources.Order() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -15980,39 +16834,50 @@ def test_get_order_rest_required_fields(request_type=service.GetOrderRequest): pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = resources.Order.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_order(request) + response = client.create_order(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_order_rest_unset_required_fields(): +def test_create_order_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_order._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_order._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "orderId", + "requestId", + ) + ) + & set( + ( + "parent", + "order", + ) + ) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_order_rest_interceptors(null_interceptor): +def test_create_order_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -16025,13 +16890,15 @@ def test_get_order_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_order" + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_create_order" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_order" + transports.GDCHardwareManagementRestInterceptor, "pre_create_order" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.GetOrderRequest.pb(service.GetOrderRequest()) + pb_message = service.CreateOrderRequest.pb(service.CreateOrderRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -16042,17 +16909,19 @@ def test_get_order_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = resources.Order.to_json(resources.Order()) + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) - request = service.GetOrderRequest() + request = service.CreateOrderRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = resources.Order() + post.return_value = operations_pb2.Operation() - client.get_order( + client.create_order( request, metadata=[ ("key", "val"), @@ -16064,8 +16933,8 @@ def test_get_order_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_order_rest_bad_request( - transport: str = "rest", request_type=service.GetOrderRequest +def test_create_order_rest_bad_request( + transport: str = "rest", request_type=service.CreateOrderRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16073,7 +16942,7 @@ def test_get_order_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/orders/sample3"} + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -16085,10 +16954,10 @@ def test_get_order_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_order(request) + client.create_order(request) -def test_get_order_rest_flattened(): +def test_create_order_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -16097,40 +16966,40 @@ def test_get_order_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = resources.Order() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"name": "projects/sample1/locations/sample2/orders/sample3"} + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + order=resources.Order(name="name_value"), + order_id="order_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = resources.Order.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.get_order(**mock_args) + client.create_order(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{name=projects/*/locations/*/orders/*}" + "%s/v1alpha/{parent=projects/*/locations/*}/orders" % client.transport._host, args[1], ) -def test_get_order_rest_flattened_error(transport: str = "rest"): +def test_create_order_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -16139,13 +17008,15 @@ def test_get_order_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_order( - service.GetOrderRequest(), - name="name_value", + client.create_order( + service.CreateOrderRequest(), + parent="parent_value", + order=resources.Order(name="name_value"), + order_id="order_id_value", ) -def test_get_order_rest_error(): +def test_create_order_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -16154,20 +17025,22 @@ def test_get_order_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.CreateOrderRequest, + service.UpdateOrderRequest, dict, ], ) -def test_create_order_rest(request_type): +def test_update_order_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = { + "order": {"name": "projects/sample1/locations/sample2/orders/sample3"} + } request_init["order"] = { - "name": "name_value", + "name": "projects/sample1/locations/sample2/orders/sample3", "display_name": "display_name_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, @@ -16232,7 +17105,7 @@ def test_create_order_rest(request_type): # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = service.CreateOrderRequest.meta.fields["order"] + test_field = service.UpdateOrderRequest.meta.fields["order"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -16308,13 +17181,13 @@ def get_message_fields(field): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_order(request) + response = client.update_order(request) # Establish that the response is the type that we expect. assert response.operation.name == "operations/spam" -def test_create_order_rest_use_cached_wrapped_rpc(): +def test_update_order_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -16328,17 +17201,17 @@ def test_create_order_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_order in client._transport._wrapped_methods + assert client._transport.update_order in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_order] = mock_rpc + client._transport._wrapped_methods[client._transport.update_order] = mock_rpc request = {} - client.create_order(request) + client.update_order(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -16347,18 +17220,17 @@ def test_create_order_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.create_order(request) + client.update_order(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_order_rest_required_fields(request_type=service.CreateOrderRequest): +def test_update_order_rest_required_fields(request_type=service.UpdateOrderRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -16369,28 +17241,24 @@ def test_create_order_rest_required_fields(request_type=service.CreateOrderReque unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_order._get_unset_required_fields(jsonified_request) + ).update_order._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_order._get_unset_required_fields(jsonified_request) + ).update_order._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( ( - "order_id", "request_id", + "update_mask", ) ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16411,7 +17279,7 @@ def test_create_order_rest_required_fields(request_type=service.CreateOrderReque pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "patch", "query_params": pb_request, } transcode_result["body"] = pb_request @@ -16424,29 +17292,29 @@ def test_create_order_rest_required_fields(request_type=service.CreateOrderReque response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_order(request) + response = client.update_order(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_order_rest_unset_required_fields(): +def test_update_order_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_order._get_unset_required_fields({}) + unset_fields = transport.update_order._get_unset_required_fields({}) assert set(unset_fields) == ( set( ( - "orderId", "requestId", + "updateMask", ) ) & set( ( - "parent", + "updateMask", "order", ) ) @@ -16454,7 +17322,7 @@ def test_create_order_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_order_rest_interceptors(null_interceptor): +def test_update_order_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -16469,13 +17337,13 @@ def test_create_order_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_order" + transports.GDCHardwareManagementRestInterceptor, "post_update_order" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_order" + transports.GDCHardwareManagementRestInterceptor, "pre_update_order" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.CreateOrderRequest.pb(service.CreateOrderRequest()) + pb_message = service.UpdateOrderRequest.pb(service.UpdateOrderRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -16490,7 +17358,7 @@ def test_create_order_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = service.CreateOrderRequest() + request = service.UpdateOrderRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -16498,7 +17366,7 @@ def test_create_order_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.create_order( + client.update_order( request, metadata=[ ("key", "val"), @@ -16510,8 +17378,8 @@ def test_create_order_rest_interceptors(null_interceptor): post.assert_called_once() -def test_create_order_rest_bad_request( - transport: str = "rest", request_type=service.CreateOrderRequest +def test_update_order_rest_bad_request( + transport: str = "rest", request_type=service.UpdateOrderRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16519,7 +17387,9 @@ def test_create_order_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = { + "order": {"name": "projects/sample1/locations/sample2/orders/sample3"} + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -16531,10 +17401,10 @@ def test_create_order_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.create_order(request) + client.update_order(request) -def test_create_order_rest_flattened(): +def test_update_order_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -16546,13 +17416,14 @@ def test_create_order_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "order": {"name": "projects/sample1/locations/sample2/orders/sample3"} + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", order=resources.Order(name="name_value"), - order_id="order_id_value", + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) @@ -16563,20 +17434,20 @@ def test_create_order_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.create_order(**mock_args) + client.update_order(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{parent=projects/*/locations/*}/orders" + "%s/v1alpha/{order.name=projects/*/locations/*/orders/*}" % client.transport._host, args[1], ) -def test_create_order_rest_flattened_error(transport: str = "rest"): +def test_update_order_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -16585,15 +17456,14 @@ def test_create_order_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_order( - service.CreateOrderRequest(), - parent="parent_value", + client.update_order( + service.UpdateOrderRequest(), order=resources.Order(name="name_value"), - order_id="order_id_value", + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_create_order_rest_error(): +def test_update_order_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -16602,148 +17472,18 @@ def test_create_order_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.UpdateOrderRequest, + service.DeleteOrderRequest, dict, ], ) -def test_update_order_rest(request_type): +def test_delete_order_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = { - "order": {"name": "projects/sample1/locations/sample2/orders/sample3"} - } - request_init["order"] = { - "name": "projects/sample1/locations/sample2/orders/sample3", - "display_name": "display_name_value", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "labels": {}, - "state": 1, - "organization_contact": { - "address": { - "revision": 879, - "region_code": "region_code_value", - "language_code": "language_code_value", - "postal_code": "postal_code_value", - "sorting_code": "sorting_code_value", - "administrative_area": "administrative_area_value", - "locality": "locality_value", - "sublocality": "sublocality_value", - "address_lines": ["address_lines_value1", "address_lines_value2"], - "recipients": ["recipients_value1", "recipients_value2"], - "organization": "organization_value", - }, - "email": "email_value", - "phone": "phone_value", - "contacts": [ - { - "given_name": "given_name_value", - "family_name": "family_name_value", - "email": "email_value", - "phone": "phone_value", - "time_zone": {"id": "id_value", "version": "version_value"}, - "reachable_times": [ - { - "start_time": { - "hours": 561, - "minutes": 773, - "seconds": 751, - "nanos": 543, - }, - "end_time": {}, - "days": [1], - } - ], - } - ], - }, - "target_workloads": ["target_workloads_value1", "target_workloads_value2"], - "customer_motivation": "customer_motivation_value", - "fulfillment_time": {}, - "region_code": "region_code_value", - "order_form_uri": "order_form_uri_value", - "type_": 1, - "submit_time": {}, - "billing_id": "billing_id_value", - "existing_hardware": [ - { - "site": "site_value", - "rack_location": "rack_location_value", - "rack_space": [{"start_rack_unit": 1613, "end_rack_unit": 1366}], - } - ], - } - # The version of a generated dependency at test runtime may differ from the version used during generation. - # Delete any fields which are not present in the current runtime dependency - # See https://github.com/googleapis/gapic-generator-python/issues/1748 - - # Determine if the message type is proto-plus or protobuf - test_field = service.UpdateOrderRequest.meta.fields["order"] - - def get_message_fields(field): - # Given a field which is a message (composite type), return a list with - # all the fields of the message. - # If the field is not a composite type, return an empty list. - message_fields = [] - - if hasattr(field, "message") and field.message: - is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - - if is_field_type_proto_plus_type: - message_fields = field.message.meta.fields.values() - # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER - message_fields = field.message.DESCRIPTOR.fields - return message_fields - - runtime_nested_fields = [ - (field.name, nested_field.name) - for field in get_message_fields(test_field) - for nested_field in get_message_fields(field) - ] - - subfields_not_in_runtime = [] - - # For each item in the sample request, create a list of sub fields which are not present at runtime - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["order"].items(): # pragma: NO COVER - result = None - is_repeated = False - # For repeated fields - if isinstance(value, list) and len(value): - is_repeated = True - result = value[0] - # For fields where the type is another message - if isinstance(value, dict): - result = value - - if result and hasattr(result, "keys"): - for subfield in result.keys(): - if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) - - # Remove fields from the sample request which are not present in the runtime version of the dependency - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER - field = subfield_to_delete.get("field") - field_repeated = subfield_to_delete.get("is_repeated") - subfield = subfield_to_delete.get("subfield") - if subfield: - if field_repeated: - for i in range(0, len(request_init["order"][field])): - del request_init["order"][field][i][subfield] - else: - del request_init["order"][field][subfield] + request_init = {"name": "projects/sample1/locations/sample2/orders/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -16758,13 +17498,13 @@ def get_message_fields(field): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_order(request) + response = client.delete_order(request) # Establish that the response is the type that we expect. assert response.operation.name == "operations/spam" -def test_update_order_rest_use_cached_wrapped_rpc(): +def test_delete_order_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -16778,17 +17518,17 @@ def test_update_order_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_order in client._transport._wrapped_methods + assert client._transport.delete_order in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_order] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_order] = mock_rpc request = {} - client.update_order(request) + client.delete_order(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -16797,17 +17537,18 @@ def test_update_order_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.update_order(request) + client.delete_order(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_order_rest_required_fields(request_type=service.UpdateOrderRequest): +def test_delete_order_rest_required_fields(request_type=service.DeleteOrderRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -16818,24 +17559,28 @@ def test_update_order_rest_required_fields(request_type=service.UpdateOrderReque unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_order._get_unset_required_fields(jsonified_request) + ).delete_order._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_order._get_unset_required_fields(jsonified_request) + ).delete_order._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( ( + "force", "request_id", - "update_mask", ) ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16856,10 +17601,9 @@ def test_update_order_rest_required_fields(request_type=service.UpdateOrderReque pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "delete", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -16869,37 +17613,32 @@ def test_update_order_rest_required_fields(request_type=service.UpdateOrderReque response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_order(request) + response = client.delete_order(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_update_order_rest_unset_required_fields(): +def test_delete_order_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_order._get_unset_required_fields({}) + unset_fields = transport.delete_order._get_unset_required_fields({}) assert set(unset_fields) == ( set( ( - "requestId", - "updateMask", - ) - ) - & set( - ( - "updateMask", - "order", + "force", + "requestId", ) ) + & set(("name",)) ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_order_rest_interceptors(null_interceptor): +def test_delete_order_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -16914,13 +17653,13 @@ def test_update_order_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_update_order" + transports.GDCHardwareManagementRestInterceptor, "post_delete_order" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_update_order" + transports.GDCHardwareManagementRestInterceptor, "pre_delete_order" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.UpdateOrderRequest.pb(service.UpdateOrderRequest()) + pb_message = service.DeleteOrderRequest.pb(service.DeleteOrderRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -16935,7 +17674,7 @@ def test_update_order_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = service.UpdateOrderRequest() + request = service.DeleteOrderRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -16943,7 +17682,7 @@ def test_update_order_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.update_order( + client.delete_order( request, metadata=[ ("key", "val"), @@ -16955,8 +17694,8 @@ def test_update_order_rest_interceptors(null_interceptor): post.assert_called_once() -def test_update_order_rest_bad_request( - transport: str = "rest", request_type=service.UpdateOrderRequest +def test_delete_order_rest_bad_request( + transport: str = "rest", request_type=service.DeleteOrderRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16964,9 +17703,7 @@ def test_update_order_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = { - "order": {"name": "projects/sample1/locations/sample2/orders/sample3"} - } + request_init = {"name": "projects/sample1/locations/sample2/orders/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -16978,10 +17715,10 @@ def test_update_order_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.update_order(request) + client.delete_order(request) -def test_update_order_rest_flattened(): +def test_delete_order_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -16993,14 +17730,11 @@ def test_update_order_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "order": {"name": "projects/sample1/locations/sample2/orders/sample3"} - } + sample_request = {"name": "projects/sample1/locations/sample2/orders/sample3"} # get truthy value for each flattened field mock_args = dict( - order=resources.Order(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) @@ -17011,20 +17745,20 @@ def test_update_order_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.update_order(**mock_args) + client.delete_order(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{order.name=projects/*/locations/*/orders/*}" + "%s/v1alpha/{name=projects/*/locations/*/orders/*}" % client.transport._host, args[1], ) -def test_update_order_rest_flattened_error(transport: str = "rest"): +def test_delete_order_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -17033,14 +17767,13 @@ def test_update_order_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_order( - service.UpdateOrderRequest(), - order=resources.Order(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.delete_order( + service.DeleteOrderRequest(), + name="name_value", ) -def test_update_order_rest_error(): +def test_delete_order_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -17049,11 +17782,11 @@ def test_update_order_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.DeleteOrderRequest, + service.SubmitOrderRequest, dict, ], ) -def test_delete_order_rest(request_type): +def test_submit_order_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -17075,13 +17808,13 @@ def test_delete_order_rest(request_type): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_order(request) + response = client.submit_order(request) # Establish that the response is the type that we expect. assert response.operation.name == "operations/spam" -def test_delete_order_rest_use_cached_wrapped_rpc(): +def test_submit_order_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -17095,17 +17828,17 @@ def test_delete_order_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_order in client._transport._wrapped_methods + assert client._transport.submit_order in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_order] = mock_rpc + client._transport._wrapped_methods[client._transport.submit_order] = mock_rpc request = {} - client.delete_order(request) + client.submit_order(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -17114,14 +17847,14 @@ def test_delete_order_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.delete_order(request) + client.submit_order(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_order_rest_required_fields(request_type=service.DeleteOrderRequest): +def test_submit_order_rest_required_fields(request_type=service.SubmitOrderRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} @@ -17136,7 +17869,7 @@ def test_delete_order_rest_required_fields(request_type=service.DeleteOrderReque unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_order._get_unset_required_fields(jsonified_request) + ).submit_order._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -17145,14 +17878,7 @@ def test_delete_order_rest_required_fields(request_type=service.DeleteOrderReque unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_order._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "force", - "request_id", - ) - ) + ).submit_order._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -17178,9 +17904,10 @@ def test_delete_order_rest_required_fields(request_type=service.DeleteOrderReque pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -17190,32 +17917,24 @@ def test_delete_order_rest_required_fields(request_type=service.DeleteOrderReque response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_order(request) + response = client.submit_order(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_delete_order_rest_unset_required_fields(): +def test_submit_order_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_order._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "force", - "requestId", - ) - ) - & set(("name",)) - ) + unset_fields = transport.submit_order._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_order_rest_interceptors(null_interceptor): +def test_submit_order_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -17230,13 +17949,13 @@ def test_delete_order_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_delete_order" + transports.GDCHardwareManagementRestInterceptor, "post_submit_order" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_delete_order" + transports.GDCHardwareManagementRestInterceptor, "pre_submit_order" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.DeleteOrderRequest.pb(service.DeleteOrderRequest()) + pb_message = service.SubmitOrderRequest.pb(service.SubmitOrderRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -17251,7 +17970,7 @@ def test_delete_order_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = service.DeleteOrderRequest() + request = service.SubmitOrderRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -17259,7 +17978,7 @@ def test_delete_order_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.delete_order( + client.submit_order( request, metadata=[ ("key", "val"), @@ -17271,8 +17990,8 @@ def test_delete_order_rest_interceptors(null_interceptor): post.assert_called_once() -def test_delete_order_rest_bad_request( - transport: str = "rest", request_type=service.DeleteOrderRequest +def test_submit_order_rest_bad_request( + transport: str = "rest", request_type=service.SubmitOrderRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17292,10 +18011,10 @@ def test_delete_order_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.delete_order(request) + client.submit_order(request) -def test_delete_order_rest_flattened(): +def test_submit_order_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -17322,20 +18041,20 @@ def test_delete_order_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.delete_order(**mock_args) + client.submit_order(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{name=projects/*/locations/*/orders/*}" + "%s/v1alpha/{name=projects/*/locations/*/orders/*}:submit" % client.transport._host, args[1], ) -def test_delete_order_rest_flattened_error(transport: str = "rest"): +def test_submit_order_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -17344,13 +18063,13 @@ def test_delete_order_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_order( - service.DeleteOrderRequest(), + client.submit_order( + service.SubmitOrderRequest(), name="name_value", ) -def test_delete_order_rest_error(): +def test_submit_order_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -17359,39 +18078,46 @@ def test_delete_order_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.SubmitOrderRequest, + service.ListSitesRequest, dict, ], ) -def test_submit_order_rest(request_type): +def test_list_sites_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/orders/sample3"} + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListSitesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service.ListSitesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.submit_order(request) + response = client.list_sites(request) # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" + assert isinstance(response, pagers.ListSitesPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] -def test_submit_order_rest_use_cached_wrapped_rpc(): +def test_list_sites_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -17405,37 +18131,33 @@ def test_submit_order_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.submit_order in client._transport._wrapped_methods + assert client._transport.list_sites in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.submit_order] = mock_rpc + client._transport._wrapped_methods[client._transport.list_sites] = mock_rpc request = {} - client.submit_order(request) + client.list_sites(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.submit_order(request) + client.list_sites(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_submit_order_rest_required_fields(request_type=service.SubmitOrderRequest): +def test_list_sites_rest_required_fields(request_type=service.ListSitesRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -17446,21 +18168,30 @@ def test_submit_order_rest_required_fields(request_type=service.SubmitOrderReque unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).submit_order._get_unset_required_fields(jsonified_request) + ).list_sites._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).submit_order._get_unset_required_fields(jsonified_request) + ).list_sites._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "filter", + "order_by", + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17469,7 +18200,7 @@ def test_submit_order_rest_required_fields(request_type=service.SubmitOrderReque request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListSitesResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -17481,37 +18212,49 @@ def test_submit_order_rest_required_fields(request_type=service.SubmitOrderReque pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = service.ListSitesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.submit_order(request) + response = client.list_sites(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_submit_order_rest_unset_required_fields(): +def test_list_sites_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.submit_order._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.list_sites._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "filter", + "orderBy", + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_submit_order_rest_interceptors(null_interceptor): +def test_list_sites_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -17524,15 +18267,13 @@ def test_submit_order_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_submit_order" + transports.GDCHardwareManagementRestInterceptor, "post_list_sites" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_submit_order" + transports.GDCHardwareManagementRestInterceptor, "pre_list_sites" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.SubmitOrderRequest.pb(service.SubmitOrderRequest()) + pb_message = service.ListSitesRequest.pb(service.ListSitesRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -17543,19 +18284,19 @@ def test_submit_order_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson( - operations_pb2.Operation() + req.return_value._content = service.ListSitesResponse.to_json( + service.ListSitesResponse() ) - request = service.SubmitOrderRequest() + request = service.ListSitesRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() + post.return_value = service.ListSitesResponse() - client.submit_order( + client.list_sites( request, metadata=[ ("key", "val"), @@ -17567,8 +18308,8 @@ def test_submit_order_rest_interceptors(null_interceptor): post.assert_called_once() -def test_submit_order_rest_bad_request( - transport: str = "rest", request_type=service.SubmitOrderRequest +def test_list_sites_rest_bad_request( + transport: str = "rest", request_type=service.ListSitesRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17576,7 +18317,7 @@ def test_submit_order_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/orders/sample3"} + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -17588,10 +18329,10 @@ def test_submit_order_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.submit_order(request) + client.list_sites(request) -def test_submit_order_rest_flattened(): +def test_list_sites_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -17600,38 +18341,39 @@ def test_submit_order_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListSitesResponse() # get arguments that satisfy an http rule for this method - sample_request = {"name": "projects/sample1/locations/sample2/orders/sample3"} + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service.ListSitesResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.submit_order(**mock_args) + client.list_sites(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{name=projects/*/locations/*/orders/*}:submit" - % client.transport._host, + "%s/v1alpha/{parent=projects/*/locations/*}/sites" % client.transport._host, args[1], ) -def test_submit_order_rest_flattened_error(transport: str = "rest"): +def test_list_sites_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -17640,61 +18382,124 @@ def test_submit_order_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.submit_order( - service.SubmitOrderRequest(), - name="name_value", + client.list_sites( + service.ListSitesRequest(), + parent="parent_value", ) -def test_submit_order_rest_error(): +def test_list_sites_rest_pager(transport: str = "rest"): client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + service.ListSitesResponse( + sites=[ + resources.Site(), + resources.Site(), + resources.Site(), + ], + next_page_token="abc", + ), + service.ListSitesResponse( + sites=[], + next_page_token="def", + ), + service.ListSitesResponse( + sites=[ + resources.Site(), + ], + next_page_token="ghi", + ), + service.ListSitesResponse( + sites=[ + resources.Site(), + resources.Site(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(service.ListSitesResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_sites(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, resources.Site) for i in results) + + pages = list(client.list_sites(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + @pytest.mark.parametrize( "request_type", [ - service.ListSitesRequest, + service.GetSiteRequest, dict, ], ) -def test_list_sites_rest(request_type): +def test_get_site_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"name": "projects/sample1/locations/sample2/sites/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service.ListSitesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + return_value = resources.Site( + name="name_value", + display_name="display_name_value", + description="description_value", + google_maps_pin_uri="google_maps_pin_uri_value", + notes="notes_value", + customer_site_id="customer_site_id_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListSitesResponse.pb(return_value) + return_value = resources.Site.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_sites(request) + response = client.get_site(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSitesPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, resources.Site) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.google_maps_pin_uri == "google_maps_pin_uri_value" + assert response.notes == "notes_value" + assert response.customer_site_id == "customer_site_id_value" -def test_list_sites_rest_use_cached_wrapped_rpc(): +def test_get_site_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -17708,33 +18513,33 @@ def test_list_sites_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_sites in client._transport._wrapped_methods + assert client._transport.get_site in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_sites] = mock_rpc + client._transport._wrapped_methods[client._transport.get_site] = mock_rpc request = {} - client.list_sites(request) + client.get_site(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_sites(request) + client.get_site(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_sites_rest_required_fields(request_type=service.ListSitesRequest): +def test_get_site_rest_required_fields(request_type=service.GetSiteRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["parent"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -17745,30 +18550,21 @@ def test_list_sites_rest_required_fields(request_type=service.ListSitesRequest): unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_sites._get_unset_required_fields(jsonified_request) + ).get_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_sites._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "filter", - "order_by", - "page_size", - "page_token", - ) - ) + ).get_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17777,7 +18573,7 @@ def test_list_sites_rest_required_fields(request_type=service.ListSitesRequest): request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = service.ListSitesResponse() + return_value = resources.Site() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -17798,40 +18594,30 @@ def test_list_sites_rest_required_fields(request_type=service.ListSitesRequest): response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListSitesResponse.pb(return_value) + return_value = resources.Site.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_sites(request) + response = client.get_site(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_sites_rest_unset_required_fields(): +def test_get_site_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_sites._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "filter", - "orderBy", - "pageSize", - "pageToken", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.get_site._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_sites_rest_interceptors(null_interceptor): +def test_get_site_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -17844,13 +18630,13 @@ def test_list_sites_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_sites" + transports.GDCHardwareManagementRestInterceptor, "post_get_site" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_sites" + transports.GDCHardwareManagementRestInterceptor, "pre_get_site" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.ListSitesRequest.pb(service.ListSitesRequest()) + pb_message = service.GetSiteRequest.pb(service.GetSiteRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -17861,19 +18647,17 @@ def test_list_sites_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = service.ListSitesResponse.to_json( - service.ListSitesResponse() - ) + req.return_value._content = resources.Site.to_json(resources.Site()) - request = service.ListSitesRequest() + request = service.GetSiteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = service.ListSitesResponse() + post.return_value = resources.Site() - client.list_sites( + client.get_site( request, metadata=[ ("key", "val"), @@ -17885,8 +18669,8 @@ def test_list_sites_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_sites_rest_bad_request( - transport: str = "rest", request_type=service.ListSitesRequest +def test_get_site_rest_bad_request( + transport: str = "rest", request_type=service.GetSiteRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17894,7 +18678,7 @@ def test_list_sites_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"name": "projects/sample1/locations/sample2/sites/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -17906,10 +18690,10 @@ def test_list_sites_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.list_sites(request) + client.get_site(request) -def test_list_sites_rest_flattened(): +def test_get_site_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -17918,163 +18702,212 @@ def test_list_sites_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service.ListSitesResponse() + return_value = resources.Site() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = {"name": "projects/sample1/locations/sample2/sites/sample3"} # get truthy value for each flattened field mock_args = dict( - parent="parent_value", - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - # Convert return value to protobuf type - return_value = service.ListSitesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - - client.list_sites(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1alpha/{parent=projects/*/locations/*}/sites" % client.transport._host, - args[1], - ) - - -def test_list_sites_rest_flattened_error(transport: str = "rest"): - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_sites( - service.ListSitesRequest(), - parent="parent_value", + name="name_value", ) - - -def test_list_sites_rest_pager(transport: str = "rest"): - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - service.ListSitesResponse( - sites=[ - resources.Site(), - resources.Site(), - resources.Site(), - ], - next_page_token="abc", - ), - service.ListSitesResponse( - sites=[], - next_page_token="def", - ), - service.ListSitesResponse( - sites=[ - resources.Site(), - ], - next_page_token="ghi", - ), - service.ListSitesResponse( - sites=[ - resources.Site(), - resources.Site(), - ], - ), + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = resources.Site.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.get_site(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1alpha/{name=projects/*/locations/*/sites/*}" % client.transport._host, + args[1], ) - # Two responses for two calls - response = response + response - # Wrap the values into proper Response objs - response = tuple(service.ListSitesResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - sample_request = {"parent": "projects/sample1/locations/sample2"} +def test_get_site_rest_flattened_error(transport: str = "rest"): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - pager = client.list_sites(request=sample_request) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_site( + service.GetSiteRequest(), + name="name_value", + ) - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, resources.Site) for i in results) - pages = list(client.list_sites(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token +def test_get_site_rest_error(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) @pytest.mark.parametrize( "request_type", [ - service.GetSiteRequest, + service.CreateSiteRequest, dict, ], ) -def test_get_site_rest(request_type): +def test_create_site_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/sites/sample3"} + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["site"] = { + "name": "name_value", + "display_name": "display_name_value", + "description": "description_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "labels": {}, + "organization_contact": { + "address": { + "revision": 879, + "region_code": "region_code_value", + "language_code": "language_code_value", + "postal_code": "postal_code_value", + "sorting_code": "sorting_code_value", + "administrative_area": "administrative_area_value", + "locality": "locality_value", + "sublocality": "sublocality_value", + "address_lines": ["address_lines_value1", "address_lines_value2"], + "recipients": ["recipients_value1", "recipients_value2"], + "organization": "organization_value", + }, + "email": "email_value", + "phone": "phone_value", + "contacts": [ + { + "given_name": "given_name_value", + "family_name": "family_name_value", + "email": "email_value", + "phone": "phone_value", + "time_zone": {"id": "id_value", "version": "version_value"}, + "reachable_times": [ + { + "start_time": { + "hours": 561, + "minutes": 773, + "seconds": 751, + "nanos": 543, + }, + "end_time": {}, + "days": [1], + } + ], + } + ], + }, + "google_maps_pin_uri": "google_maps_pin_uri_value", + "access_times": {}, + "notes": "notes_value", + "customer_site_id": "customer_site_id_value", + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = service.CreateSiteRequest.meta.fields["site"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["site"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["site"][field])): + del request_init["site"][field][i][subfield] + else: + del request_init["site"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = resources.Site( - name="name_value", - display_name="display_name_value", - description="description_value", - google_maps_pin_uri="google_maps_pin_uri_value", - notes="notes_value", - ) + return_value = operations_pb2.Operation(name="operations/spam") # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = resources.Site.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_site(request) + response = client.create_site(request) # Establish that the response is the type that we expect. - assert isinstance(response, resources.Site) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.google_maps_pin_uri == "google_maps_pin_uri_value" - assert response.notes == "notes_value" + assert response.operation.name == "operations/spam" -def test_get_site_rest_use_cached_wrapped_rpc(): +def test_create_site_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -18088,33 +18921,37 @@ def test_get_site_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_site in client._transport._wrapped_methods + assert client._transport.create_site in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_site] = mock_rpc + client._transport._wrapped_methods[client._transport.create_site] = mock_rpc request = {} - client.get_site(request) + client.create_site(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_site(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_site(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_site_rest_required_fields(request_type=service.GetSiteRequest): +def test_create_site_rest_required_fields(request_type=service.CreateSiteRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -18125,21 +18962,28 @@ def test_get_site_rest_required_fields(request_type=service.GetSiteRequest): unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_site._get_unset_required_fields(jsonified_request) + ).create_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_site._get_unset_required_fields(jsonified_request) + ).create_site._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "request_id", + "site_id", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18148,7 +18992,7 @@ def test_get_site_rest_required_fields(request_type=service.GetSiteRequest): request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = resources.Site() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -18160,39 +19004,50 @@ def test_get_site_rest_required_fields(request_type=service.GetSiteRequest): pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = resources.Site.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_site(request) + response = client.create_site(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_site_rest_unset_required_fields(): +def test_create_site_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_site._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) - + unset_fields = transport.create_site._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "requestId", + "siteId", + ) + ) + & set( + ( + "parent", + "site", + ) + ) + ) + @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_site_rest_interceptors(null_interceptor): +def test_create_site_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -18205,13 +19060,15 @@ def test_get_site_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_site" + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_create_site" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_site" + transports.GDCHardwareManagementRestInterceptor, "pre_create_site" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.GetSiteRequest.pb(service.GetSiteRequest()) + pb_message = service.CreateSiteRequest.pb(service.CreateSiteRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -18222,17 +19079,19 @@ def test_get_site_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = resources.Site.to_json(resources.Site()) + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) - request = service.GetSiteRequest() + request = service.CreateSiteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = resources.Site() + post.return_value = operations_pb2.Operation() - client.get_site( + client.create_site( request, metadata=[ ("key", "val"), @@ -18244,8 +19103,8 @@ def test_get_site_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_site_rest_bad_request( - transport: str = "rest", request_type=service.GetSiteRequest +def test_create_site_rest_bad_request( + transport: str = "rest", request_type=service.CreateSiteRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18253,7 +19112,7 @@ def test_get_site_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/sites/sample3"} + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -18265,10 +19124,10 @@ def test_get_site_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_site(request) + client.create_site(request) -def test_get_site_rest_flattened(): +def test_create_site_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -18277,39 +19136,39 @@ def test_get_site_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = resources.Site() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"name": "projects/sample1/locations/sample2/sites/sample3"} + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + site=resources.Site(name="name_value"), + site_id="site_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = resources.Site.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.get_site(**mock_args) + client.create_site(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{name=projects/*/locations/*/sites/*}" % client.transport._host, + "%s/v1alpha/{parent=projects/*/locations/*}/sites" % client.transport._host, args[1], ) -def test_get_site_rest_flattened_error(transport: str = "rest"): +def test_create_site_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -18318,13 +19177,15 @@ def test_get_site_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_site( - service.GetSiteRequest(), - name="name_value", + client.create_site( + service.CreateSiteRequest(), + parent="parent_value", + site=resources.Site(name="name_value"), + site_id="site_id_value", ) -def test_get_site_rest_error(): +def test_create_site_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -18333,20 +19194,22 @@ def test_get_site_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.CreateSiteRequest, + service.UpdateSiteRequest, dict, ], ) -def test_create_site_rest(request_type): +def test_update_site_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = { + "site": {"name": "projects/sample1/locations/sample2/sites/sample3"} + } request_init["site"] = { - "name": "name_value", + "name": "projects/sample1/locations/sample2/sites/sample3", "display_name": "display_name_value", "description": "description_value", "create_time": {"seconds": 751, "nanos": 543}, @@ -18393,13 +19256,14 @@ def test_create_site_rest(request_type): "google_maps_pin_uri": "google_maps_pin_uri_value", "access_times": {}, "notes": "notes_value", + "customer_site_id": "customer_site_id_value", } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = service.CreateSiteRequest.meta.fields["site"] + test_field = service.UpdateSiteRequest.meta.fields["site"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -18475,13 +19339,13 @@ def get_message_fields(field): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_site(request) + response = client.update_site(request) # Establish that the response is the type that we expect. assert response.operation.name == "operations/spam" -def test_create_site_rest_use_cached_wrapped_rpc(): +def test_update_site_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -18495,17 +19359,17 @@ def test_create_site_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_site in client._transport._wrapped_methods + assert client._transport.update_site in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_site] = mock_rpc + client._transport._wrapped_methods[client._transport.update_site] = mock_rpc request = {} - client.create_site(request) + client.update_site(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -18514,18 +19378,17 @@ def test_create_site_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.create_site(request) + client.update_site(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_site_rest_required_fields(request_type=service.CreateSiteRequest): +def test_update_site_rest_required_fields(request_type=service.UpdateSiteRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -18536,28 +19399,24 @@ def test_create_site_rest_required_fields(request_type=service.CreateSiteRequest unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_site._get_unset_required_fields(jsonified_request) + ).update_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_site._get_unset_required_fields(jsonified_request) + ).update_site._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( ( "request_id", - "site_id", + "update_mask", ) ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18578,7 +19437,7 @@ def test_create_site_rest_required_fields(request_type=service.CreateSiteRequest pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "patch", "query_params": pb_request, } transcode_result["body"] = pb_request @@ -18591,29 +19450,29 @@ def test_create_site_rest_required_fields(request_type=service.CreateSiteRequest response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_site(request) + response = client.update_site(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_site_rest_unset_required_fields(): +def test_update_site_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_site._get_unset_required_fields({}) + unset_fields = transport.update_site._get_unset_required_fields({}) assert set(unset_fields) == ( set( ( "requestId", - "siteId", + "updateMask", ) ) & set( ( - "parent", + "updateMask", "site", ) ) @@ -18621,7 +19480,7 @@ def test_create_site_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_site_rest_interceptors(null_interceptor): +def test_update_site_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -18636,13 +19495,13 @@ def test_create_site_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_site" + transports.GDCHardwareManagementRestInterceptor, "post_update_site" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_site" + transports.GDCHardwareManagementRestInterceptor, "pre_update_site" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.CreateSiteRequest.pb(service.CreateSiteRequest()) + pb_message = service.UpdateSiteRequest.pb(service.UpdateSiteRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -18657,7 +19516,7 @@ def test_create_site_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = service.CreateSiteRequest() + request = service.UpdateSiteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -18665,7 +19524,7 @@ def test_create_site_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.create_site( + client.update_site( request, metadata=[ ("key", "val"), @@ -18677,8 +19536,8 @@ def test_create_site_rest_interceptors(null_interceptor): post.assert_called_once() -def test_create_site_rest_bad_request( - transport: str = "rest", request_type=service.CreateSiteRequest +def test_update_site_rest_bad_request( + transport: str = "rest", request_type=service.UpdateSiteRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18686,7 +19545,9 @@ def test_create_site_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = { + "site": {"name": "projects/sample1/locations/sample2/sites/sample3"} + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -18698,10 +19559,10 @@ def test_create_site_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.create_site(request) + client.update_site(request) -def test_create_site_rest_flattened(): +def test_update_site_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -18713,13 +19574,14 @@ def test_create_site_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "site": {"name": "projects/sample1/locations/sample2/sites/sample3"} + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", site=resources.Site(name="name_value"), - site_id="site_id_value", + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) @@ -18730,195 +19592,84 @@ def test_create_site_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.create_site(**mock_args) + client.update_site(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{parent=projects/*/locations/*}/sites" % client.transport._host, + "%s/v1alpha/{site.name=projects/*/locations/*/sites/*}" + % client.transport._host, args[1], ) -def test_create_site_rest_flattened_error(transport: str = "rest"): - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_site( - service.CreateSiteRequest(), - parent="parent_value", - site=resources.Site(name="name_value"), - site_id="site_id_value", - ) - - -def test_create_site_rest_error(): - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" - ) - - -@pytest.mark.parametrize( - "request_type", - [ - service.UpdateSiteRequest, - dict, - ], -) -def test_update_site_rest(request_type): +def test_update_site_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = { - "site": {"name": "projects/sample1/locations/sample2/sites/sample3"} - } - request_init["site"] = { - "name": "projects/sample1/locations/sample2/sites/sample3", - "display_name": "display_name_value", - "description": "description_value", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "labels": {}, - "organization_contact": { - "address": { - "revision": 879, - "region_code": "region_code_value", - "language_code": "language_code_value", - "postal_code": "postal_code_value", - "sorting_code": "sorting_code_value", - "administrative_area": "administrative_area_value", - "locality": "locality_value", - "sublocality": "sublocality_value", - "address_lines": ["address_lines_value1", "address_lines_value2"], - "recipients": ["recipients_value1", "recipients_value2"], - "organization": "organization_value", - }, - "email": "email_value", - "phone": "phone_value", - "contacts": [ - { - "given_name": "given_name_value", - "family_name": "family_name_value", - "email": "email_value", - "phone": "phone_value", - "time_zone": {"id": "id_value", "version": "version_value"}, - "reachable_times": [ - { - "start_time": { - "hours": 561, - "minutes": 773, - "seconds": 751, - "nanos": 543, - }, - "end_time": {}, - "days": [1], - } - ], - } - ], - }, - "google_maps_pin_uri": "google_maps_pin_uri_value", - "access_times": {}, - "notes": "notes_value", - } - # The version of a generated dependency at test runtime may differ from the version used during generation. - # Delete any fields which are not present in the current runtime dependency - # See https://github.com/googleapis/gapic-generator-python/issues/1748 - - # Determine if the message type is proto-plus or protobuf - test_field = service.UpdateSiteRequest.meta.fields["site"] - - def get_message_fields(field): - # Given a field which is a message (composite type), return a list with - # all the fields of the message. - # If the field is not a composite type, return an empty list. - message_fields = [] - - if hasattr(field, "message") and field.message: - is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - - if is_field_type_proto_plus_type: - message_fields = field.message.meta.fields.values() - # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER - message_fields = field.message.DESCRIPTOR.fields - return message_fields + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - runtime_nested_fields = [ - (field.name, nested_field.name) - for field in get_message_fields(test_field) - for nested_field in get_message_fields(field) - ] + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_site( + service.UpdateSiteRequest(), + site=resources.Site(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) - subfields_not_in_runtime = [] - # For each item in the sample request, create a list of sub fields which are not present at runtime - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["site"].items(): # pragma: NO COVER - result = None - is_repeated = False - # For repeated fields - if isinstance(value, list) and len(value): - is_repeated = True - result = value[0] - # For fields where the type is another message - if isinstance(value, dict): - result = value +def test_update_site_rest_error(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) - if result and hasattr(result, "keys"): - for subfield in result.keys(): - if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) - # Remove fields from the sample request which are not present in the runtime version of the dependency - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER - field = subfield_to_delete.get("field") - field_repeated = subfield_to_delete.get("is_repeated") - subfield = subfield_to_delete.get("subfield") - if subfield: - if field_repeated: - for i in range(0, len(request_init["site"][field])): - del request_init["site"][field][i][subfield] - else: - del request_init["site"][field][subfield] +@pytest.mark.parametrize( + "request_type", + [ + service.ListHardwareGroupsRequest, + dict, + ], +) +def test_list_hardware_groups_rest(request_type): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListHardwareGroupsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service.ListHardwareGroupsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_site(request) + response = client.list_hardware_groups(request) # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" + assert isinstance(response, pagers.ListHardwareGroupsPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] -def test_update_site_rest_use_cached_wrapped_rpc(): +def test_list_hardware_groups_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -18932,36 +19683,39 @@ def test_update_site_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_site in client._transport._wrapped_methods + assert ( + client._transport.list_hardware_groups in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_site] = mock_rpc + client._transport._wrapped_methods[ + client._transport.list_hardware_groups + ] = mock_rpc request = {} - client.update_site(request) + client.list_hardware_groups(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.update_site(request) + client.list_hardware_groups(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_site_rest_required_fields(request_type=service.UpdateSiteRequest): +def test_list_hardware_groups_rest_required_fields( + request_type=service.ListHardwareGroupsRequest, +): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -18972,24 +19726,30 @@ def test_update_site_rest_required_fields(request_type=service.UpdateSiteRequest unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_site._get_unset_required_fields(jsonified_request) + ).list_hardware_groups._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["parent"] = "parent_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_site._get_unset_required_fields(jsonified_request) + ).list_hardware_groups._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( ( - "request_id", - "update_mask", + "filter", + "order_by", + "page_size", + "page_token", ) ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18998,7 +19758,7 @@ def test_update_site_rest_required_fields(request_type=service.UpdateSiteRequest request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListHardwareGroupsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -19010,50 +19770,49 @@ def test_update_site_rest_required_fields(request_type=service.UpdateSiteRequest pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = service.ListHardwareGroupsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_site(request) + response = client.list_hardware_groups(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_update_site_rest_unset_required_fields(): +def test_list_hardware_groups_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_site._get_unset_required_fields({}) + unset_fields = transport.list_hardware_groups._get_unset_required_fields({}) assert set(unset_fields) == ( set( ( - "requestId", - "updateMask", - ) - ) - & set( - ( - "updateMask", - "site", + "filter", + "orderBy", + "pageSize", + "pageToken", ) ) + & set(("parent",)) ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_site_rest_interceptors(null_interceptor): +def test_list_hardware_groups_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -19066,15 +19825,15 @@ def test_update_site_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_update_site" + transports.GDCHardwareManagementRestInterceptor, "post_list_hardware_groups" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_update_site" + transports.GDCHardwareManagementRestInterceptor, "pre_list_hardware_groups" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.UpdateSiteRequest.pb(service.UpdateSiteRequest()) + pb_message = service.ListHardwareGroupsRequest.pb( + service.ListHardwareGroupsRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -19085,19 +19844,19 @@ def test_update_site_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson( - operations_pb2.Operation() + req.return_value._content = service.ListHardwareGroupsResponse.to_json( + service.ListHardwareGroupsResponse() ) - request = service.UpdateSiteRequest() + request = service.ListHardwareGroupsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() + post.return_value = service.ListHardwareGroupsResponse() - client.update_site( + client.list_hardware_groups( request, metadata=[ ("key", "val"), @@ -19109,8 +19868,8 @@ def test_update_site_rest_interceptors(null_interceptor): post.assert_called_once() -def test_update_site_rest_bad_request( - transport: str = "rest", request_type=service.UpdateSiteRequest +def test_list_hardware_groups_rest_bad_request( + transport: str = "rest", request_type=service.ListHardwareGroupsRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19118,9 +19877,7 @@ def test_update_site_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = { - "site": {"name": "projects/sample1/locations/sample2/sites/sample3"} - } + request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -19132,10 +19889,10 @@ def test_update_site_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.update_site(request) + client.list_hardware_groups(request) -def test_update_site_rest_flattened(): +def test_list_hardware_groups_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -19144,105 +19901,168 @@ def test_update_site_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListHardwareGroupsResponse() # get arguments that satisfy an http rule for this method - sample_request = { - "site": {"name": "projects/sample1/locations/sample2/sites/sample3"} - } + sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} # get truthy value for each flattened field mock_args = dict( - site=resources.Site(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + parent="parent_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service.ListHardwareGroupsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.update_site(**mock_args) + client.list_hardware_groups(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{site.name=projects/*/locations/*/sites/*}" + "%s/v1alpha/{parent=projects/*/locations/*/orders/*}/hardwareGroups" % client.transport._host, args[1], ) -def test_update_site_rest_flattened_error(transport: str = "rest"): - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_site( - service.UpdateSiteRequest(), - site=resources.Site(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), - ) +def test_list_hardware_groups_rest_flattened_error(transport: str = "rest"): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_hardware_groups( + service.ListHardwareGroupsRequest(), + parent="parent_value", + ) + + +def test_list_hardware_groups_rest_pager(transport: str = "rest"): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + service.ListHardwareGroupsResponse( + hardware_groups=[ + resources.HardwareGroup(), + resources.HardwareGroup(), + resources.HardwareGroup(), + ], + next_page_token="abc", + ), + service.ListHardwareGroupsResponse( + hardware_groups=[], + next_page_token="def", + ), + service.ListHardwareGroupsResponse( + hardware_groups=[ + resources.HardwareGroup(), + ], + next_page_token="ghi", + ), + service.ListHardwareGroupsResponse( + hardware_groups=[ + resources.HardwareGroup(), + resources.HardwareGroup(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + service.ListHardwareGroupsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + + pager = client.list_hardware_groups(request=sample_request) + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, resources.HardwareGroup) for i in results) -def test_update_site_rest_error(): - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" - ) + pages = list(client.list_hardware_groups(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( "request_type", [ - service.ListHardwareGroupsRequest, + service.GetHardwareGroupRequest, dict, ], ) -def test_list_hardware_groups_rest(request_type): +def test_get_hardware_group_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service.ListHardwareGroupsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + return_value = resources.HardwareGroup( + name="name_value", + hardware_count=1494, + site="site_value", + state=resources.HardwareGroup.State.ADDITIONAL_INFO_NEEDED, + zone="zone_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListHardwareGroupsResponse.pb(return_value) + return_value = resources.HardwareGroup.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_hardware_groups(request) + response = client.get_hardware_group(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListHardwareGroupsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, resources.HardwareGroup) + assert response.name == "name_value" + assert response.hardware_count == 1494 + assert response.site == "site_value" + assert response.state == resources.HardwareGroup.State.ADDITIONAL_INFO_NEEDED + assert response.zone == "zone_value" -def test_list_hardware_groups_rest_use_cached_wrapped_rpc(): +def test_get_hardware_group_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -19257,7 +20077,7 @@ def test_list_hardware_groups_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.list_hardware_groups in client._transport._wrapped_methods + client._transport.get_hardware_group in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -19266,29 +20086,29 @@ def test_list_hardware_groups_rest_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.list_hardware_groups + client._transport.get_hardware_group ] = mock_rpc request = {} - client.list_hardware_groups(request) + client.get_hardware_group(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_hardware_groups(request) + client.get_hardware_group(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_hardware_groups_rest_required_fields( - request_type=service.ListHardwareGroupsRequest, +def test_get_hardware_group_rest_required_fields( + request_type=service.GetHardwareGroupRequest, ): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["parent"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -19299,30 +20119,21 @@ def test_list_hardware_groups_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_hardware_groups._get_unset_required_fields(jsonified_request) + ).get_hardware_group._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_hardware_groups._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "filter", - "order_by", - "page_size", - "page_token", - ) - ) + ).get_hardware_group._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19331,7 +20142,7 @@ def test_list_hardware_groups_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = service.ListHardwareGroupsResponse() + return_value = resources.HardwareGroup() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -19352,40 +20163,30 @@ def test_list_hardware_groups_rest_required_fields( response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListHardwareGroupsResponse.pb(return_value) + return_value = resources.HardwareGroup.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_hardware_groups(request) + response = client.get_hardware_group(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_hardware_groups_rest_unset_required_fields(): +def test_get_hardware_group_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_hardware_groups._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "filter", - "orderBy", - "pageSize", - "pageToken", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.get_hardware_group._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_hardware_groups_rest_interceptors(null_interceptor): +def test_get_hardware_group_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -19398,14 +20199,14 @@ def test_list_hardware_groups_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_hardware_groups" + transports.GDCHardwareManagementRestInterceptor, "post_get_hardware_group" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_hardware_groups" + transports.GDCHardwareManagementRestInterceptor, "pre_get_hardware_group" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.ListHardwareGroupsRequest.pb( - service.ListHardwareGroupsRequest() + pb_message = service.GetHardwareGroupRequest.pb( + service.GetHardwareGroupRequest() ) transcode.return_value = { "method": "post", @@ -19417,19 +20218,19 @@ def test_list_hardware_groups_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = service.ListHardwareGroupsResponse.to_json( - service.ListHardwareGroupsResponse() + req.return_value._content = resources.HardwareGroup.to_json( + resources.HardwareGroup() ) - request = service.ListHardwareGroupsRequest() + request = service.GetHardwareGroupRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = service.ListHardwareGroupsResponse() + post.return_value = resources.HardwareGroup() - client.list_hardware_groups( + client.get_hardware_group( request, metadata=[ ("key", "val"), @@ -19441,8 +20242,8 @@ def test_list_hardware_groups_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_hardware_groups_rest_bad_request( - transport: str = "rest", request_type=service.ListHardwareGroupsRequest +def test_get_hardware_group_rest_bad_request( + transport: str = "rest", request_type=service.GetHardwareGroupRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19450,7 +20251,9 @@ def test_list_hardware_groups_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -19462,10 +20265,10 @@ def test_list_hardware_groups_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.list_hardware_groups(request) + client.get_hardware_group(request) -def test_list_hardware_groups_rest_flattened(): +def test_get_hardware_group_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -19474,14 +20277,16 @@ def test_list_hardware_groups_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service.ListHardwareGroupsResponse() + return_value = resources.HardwareGroup() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + sample_request = { + "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + name="name_value", ) mock_args.update(sample_request) @@ -19489,25 +20294,25 @@ def test_list_hardware_groups_rest_flattened(): response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListHardwareGroupsResponse.pb(return_value) + return_value = resources.HardwareGroup.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.list_hardware_groups(**mock_args) + client.get_hardware_group(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{parent=projects/*/locations/*/orders/*}/hardwareGroups" + "%s/v1alpha/{name=projects/*/locations/*/orders/*/hardwareGroups/*}" % client.transport._host, args[1], ) -def test_list_hardware_groups_rest_flattened_error(transport: str = "rest"): +def test_get_hardware_group_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -19516,126 +20321,137 @@ def test_list_hardware_groups_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_hardware_groups( - service.ListHardwareGroupsRequest(), - parent="parent_value", + client.get_hardware_group( + service.GetHardwareGroupRequest(), + name="name_value", ) -def test_list_hardware_groups_rest_pager(transport: str = "rest"): +def test_get_hardware_group_rest_error(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + service.CreateHardwareGroupRequest, + dict, + ], +) +def test_create_hardware_group_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + transport="rest", ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - service.ListHardwareGroupsResponse( - hardware_groups=[ - resources.HardwareGroup(), - resources.HardwareGroup(), - resources.HardwareGroup(), - ], - next_page_token="abc", - ), - service.ListHardwareGroupsResponse( - hardware_groups=[], - next_page_token="def", - ), - service.ListHardwareGroupsResponse( - hardware_groups=[ - resources.HardwareGroup(), - ], - next_page_token="ghi", - ), - service.ListHardwareGroupsResponse( - hardware_groups=[ - resources.HardwareGroup(), - resources.HardwareGroup(), - ], - ), - ) - # Two responses for two calls - response = response + response + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + request_init["hardware_group"] = { + "name": "name_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "labels": {}, + "hardware_count": 1494, + "config": { + "sku": "sku_value", + "power_supply": 1, + "subscription_duration_months": 3042, + }, + "site": "site_value", + "state": 1, + "zone": "zone_value", + "requested_installation_date": {"year": 433, "month": 550, "day": 318}, + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 - # Wrap the values into proper Response objs - response = tuple( - service.ListHardwareGroupsResponse.to_json(x) for x in response - ) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values + # Determine if the message type is proto-plus or protobuf + test_field = service.CreateHardwareGroupRequest.meta.fields["hardware_group"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] - sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - pager = client.list_hardware_groups(request=sample_request) + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, resources.HardwareGroup) for i in results) + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] - pages = list(client.list_hardware_groups(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + subfields_not_in_runtime = [] + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["hardware_group"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value -@pytest.mark.parametrize( - "request_type", - [ - service.GetHardwareGroupRequest, - dict, - ], -) -def test_get_hardware_group_rest(request_type): - client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) - # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" - } + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["hardware_group"][field])): + del request_init["hardware_group"][field][i][subfield] + else: + del request_init["hardware_group"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = resources.HardwareGroup( - name="name_value", - hardware_count=1494, - site="site_value", - state=resources.HardwareGroup.State.ADDITIONAL_INFO_NEEDED, - zone="zone_value", - ) + return_value = operations_pb2.Operation(name="operations/spam") # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = resources.HardwareGroup.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_hardware_group(request) + response = client.create_hardware_group(request) # Establish that the response is the type that we expect. - assert isinstance(response, resources.HardwareGroup) - assert response.name == "name_value" - assert response.hardware_count == 1494 - assert response.site == "site_value" - assert response.state == resources.HardwareGroup.State.ADDITIONAL_INFO_NEEDED - assert response.zone == "zone_value" + assert response.operation.name == "operations/spam" -def test_get_hardware_group_rest_use_cached_wrapped_rpc(): +def test_create_hardware_group_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -19650,7 +20466,8 @@ def test_get_hardware_group_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.get_hardware_group in client._transport._wrapped_methods + client._transport.create_hardware_group + in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -19659,29 +20476,33 @@ def test_get_hardware_group_rest_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.get_hardware_group + client._transport.create_hardware_group ] = mock_rpc request = {} - client.get_hardware_group(request) + client.create_hardware_group(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_hardware_group(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_hardware_group(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_hardware_group_rest_required_fields( - request_type=service.GetHardwareGroupRequest, +def test_create_hardware_group_rest_required_fields( + request_type=service.CreateHardwareGroupRequest, ): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -19692,21 +20513,28 @@ def test_get_hardware_group_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_hardware_group._get_unset_required_fields(jsonified_request) + ).create_hardware_group._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_hardware_group._get_unset_required_fields(jsonified_request) + ).create_hardware_group._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "hardware_group_id", + "request_id", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19715,7 +20543,7 @@ def test_get_hardware_group_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = resources.HardwareGroup() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -19727,39 +20555,50 @@ def test_get_hardware_group_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = resources.HardwareGroup.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_hardware_group(request) + response = client.create_hardware_group(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_hardware_group_rest_unset_required_fields(): +def test_create_hardware_group_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_hardware_group._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_hardware_group._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "hardwareGroupId", + "requestId", + ) + ) + & set( + ( + "parent", + "hardwareGroup", + ) + ) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_hardware_group_rest_interceptors(null_interceptor): +def test_create_hardware_group_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -19772,14 +20611,16 @@ def test_get_hardware_group_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_hardware_group" + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_create_hardware_group" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_hardware_group" + transports.GDCHardwareManagementRestInterceptor, "pre_create_hardware_group" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.GetHardwareGroupRequest.pb( - service.GetHardwareGroupRequest() + pb_message = service.CreateHardwareGroupRequest.pb( + service.CreateHardwareGroupRequest() ) transcode.return_value = { "method": "post", @@ -19791,19 +20632,19 @@ def test_get_hardware_group_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = resources.HardwareGroup.to_json( - resources.HardwareGroup() + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() ) - request = service.GetHardwareGroupRequest() + request = service.CreateHardwareGroupRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = resources.HardwareGroup() + post.return_value = operations_pb2.Operation() - client.get_hardware_group( + client.create_hardware_group( request, metadata=[ ("key", "val"), @@ -19815,8 +20656,8 @@ def test_get_hardware_group_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_hardware_group_rest_bad_request( - transport: str = "rest", request_type=service.GetHardwareGroupRequest +def test_create_hardware_group_rest_bad_request( + transport: str = "rest", request_type=service.CreateHardwareGroupRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19824,9 +20665,7 @@ def test_get_hardware_group_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" - } + request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -19838,10 +20677,10 @@ def test_get_hardware_group_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_hardware_group(request) + client.create_hardware_group(request) -def test_get_hardware_group_rest_flattened(): +def test_create_hardware_group_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -19850,42 +20689,40 @@ def test_get_hardware_group_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = resources.HardwareGroup() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" - } + sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + hardware_group=resources.HardwareGroup(name="name_value"), + hardware_group_id="hardware_group_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = resources.HardwareGroup.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.get_hardware_group(**mock_args) + client.create_hardware_group(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{name=projects/*/locations/*/orders/*/hardwareGroups/*}" + "%s/v1alpha/{parent=projects/*/locations/*/orders/*}/hardwareGroups" % client.transport._host, args[1], ) -def test_get_hardware_group_rest_flattened_error(transport: str = "rest"): +def test_create_hardware_group_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -19894,13 +20731,15 @@ def test_get_hardware_group_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_hardware_group( - service.GetHardwareGroupRequest(), - name="name_value", + client.create_hardware_group( + service.CreateHardwareGroupRequest(), + parent="parent_value", + hardware_group=resources.HardwareGroup(name="name_value"), + hardware_group_id="hardware_group_id_value", ) -def test_get_hardware_group_rest_error(): +def test_create_hardware_group_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -19909,20 +20748,24 @@ def test_get_hardware_group_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.CreateHardwareGroupRequest, + service.UpdateHardwareGroupRequest, dict, ], ) -def test_create_hardware_group_rest(request_type): +def test_update_hardware_group_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + request_init = { + "hardware_group": { + "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" + } + } request_init["hardware_group"] = { - "name": "name_value", + "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, "labels": {}, @@ -19942,7 +20785,7 @@ def test_create_hardware_group_rest(request_type): # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = service.CreateHardwareGroupRequest.meta.fields["hardware_group"] + test_field = service.UpdateHardwareGroupRequest.meta.fields["hardware_group"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -20018,13 +20861,13 @@ def get_message_fields(field): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_hardware_group(request) + response = client.update_hardware_group(request) # Establish that the response is the type that we expect. assert response.operation.name == "operations/spam" -def test_create_hardware_group_rest_use_cached_wrapped_rpc(): +def test_update_hardware_group_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -20039,7 +20882,7 @@ def test_create_hardware_group_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.create_hardware_group + client._transport.update_hardware_group in client._transport._wrapped_methods ) @@ -20049,11 +20892,11 @@ def test_create_hardware_group_rest_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.create_hardware_group + client._transport.update_hardware_group ] = mock_rpc request = {} - client.create_hardware_group(request) + client.update_hardware_group(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -20062,20 +20905,19 @@ def test_create_hardware_group_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.create_hardware_group(request) + client.update_hardware_group(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_hardware_group_rest_required_fields( - request_type=service.CreateHardwareGroupRequest, +def test_update_hardware_group_rest_required_fields( + request_type=service.UpdateHardwareGroupRequest, ): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -20086,28 +20928,24 @@ def test_create_hardware_group_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_hardware_group._get_unset_required_fields(jsonified_request) + ).update_hardware_group._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_hardware_group._get_unset_required_fields(jsonified_request) + ).update_hardware_group._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( ( - "hardware_group_id", "request_id", + "update_mask", ) ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20128,7 +20966,7 @@ def test_create_hardware_group_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "patch", "query_params": pb_request, } transcode_result["body"] = pb_request @@ -20141,29 +20979,29 @@ def test_create_hardware_group_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_hardware_group(request) + response = client.update_hardware_group(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_hardware_group_rest_unset_required_fields(): +def test_update_hardware_group_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_hardware_group._get_unset_required_fields({}) + unset_fields = transport.update_hardware_group._get_unset_required_fields({}) assert set(unset_fields) == ( set( ( - "hardwareGroupId", "requestId", + "updateMask", ) ) & set( ( - "parent", + "updateMask", "hardwareGroup", ) ) @@ -20171,7 +21009,7 @@ def test_create_hardware_group_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_hardware_group_rest_interceptors(null_interceptor): +def test_update_hardware_group_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -20186,14 +21024,14 @@ def test_create_hardware_group_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_hardware_group" + transports.GDCHardwareManagementRestInterceptor, "post_update_hardware_group" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_hardware_group" + transports.GDCHardwareManagementRestInterceptor, "pre_update_hardware_group" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.CreateHardwareGroupRequest.pb( - service.CreateHardwareGroupRequest() + pb_message = service.UpdateHardwareGroupRequest.pb( + service.UpdateHardwareGroupRequest() ) transcode.return_value = { "method": "post", @@ -20209,7 +21047,7 @@ def test_create_hardware_group_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = service.CreateHardwareGroupRequest() + request = service.UpdateHardwareGroupRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -20217,7 +21055,7 @@ def test_create_hardware_group_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.create_hardware_group( + client.update_hardware_group( request, metadata=[ ("key", "val"), @@ -20229,8 +21067,8 @@ def test_create_hardware_group_rest_interceptors(null_interceptor): post.assert_called_once() -def test_create_hardware_group_rest_bad_request( - transport: str = "rest", request_type=service.CreateHardwareGroupRequest +def test_update_hardware_group_rest_bad_request( + transport: str = "rest", request_type=service.UpdateHardwareGroupRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20238,7 +21076,11 @@ def test_create_hardware_group_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + request_init = { + "hardware_group": { + "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" + } + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -20250,10 +21092,10 @@ def test_create_hardware_group_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.create_hardware_group(request) + client.update_hardware_group(request) -def test_create_hardware_group_rest_flattened(): +def test_update_hardware_group_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20265,13 +21107,16 @@ def test_create_hardware_group_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + sample_request = { + "hardware_group": { + "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" + } + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", hardware_group=resources.HardwareGroup(name="name_value"), - hardware_group_id="hardware_group_id_value", + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) @@ -20282,20 +21127,20 @@ def test_create_hardware_group_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.create_hardware_group(**mock_args) + client.update_hardware_group(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{parent=projects/*/locations/*/orders/*}/hardwareGroups" + "%s/v1alpha/{hardware_group.name=projects/*/locations/*/orders/*/hardwareGroups/*}" % client.transport._host, args[1], ) -def test_create_hardware_group_rest_flattened_error(transport: str = "rest"): +def test_update_hardware_group_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -20304,15 +21149,14 @@ def test_create_hardware_group_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_hardware_group( - service.CreateHardwareGroupRequest(), - parent="parent_value", + client.update_hardware_group( + service.UpdateHardwareGroupRequest(), hardware_group=resources.HardwareGroup(name="name_value"), - hardware_group_id="hardware_group_id_value", + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_create_hardware_group_rest_error(): +def test_update_hardware_group_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -20321,11 +21165,11 @@ def test_create_hardware_group_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.UpdateHardwareGroupRequest, + service.DeleteHardwareGroupRequest, dict, ], ) -def test_update_hardware_group_rest(request_type): +def test_delete_hardware_group_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20333,93 +21177,8 @@ def test_update_hardware_group_rest(request_type): # send a request that will satisfy transcoding request_init = { - "hardware_group": { - "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" - } - } - request_init["hardware_group"] = { - "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "labels": {}, - "hardware_count": 1494, - "config": { - "sku": "sku_value", - "power_supply": 1, - "subscription_duration_months": 3042, - }, - "site": "site_value", - "state": 1, - "zone": "zone_value", - "requested_installation_date": {"year": 433, "month": 550, "day": 318}, + "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" } - # The version of a generated dependency at test runtime may differ from the version used during generation. - # Delete any fields which are not present in the current runtime dependency - # See https://github.com/googleapis/gapic-generator-python/issues/1748 - - # Determine if the message type is proto-plus or protobuf - test_field = service.UpdateHardwareGroupRequest.meta.fields["hardware_group"] - - def get_message_fields(field): - # Given a field which is a message (composite type), return a list with - # all the fields of the message. - # If the field is not a composite type, return an empty list. - message_fields = [] - - if hasattr(field, "message") and field.message: - is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - - if is_field_type_proto_plus_type: - message_fields = field.message.meta.fields.values() - # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER - message_fields = field.message.DESCRIPTOR.fields - return message_fields - - runtime_nested_fields = [ - (field.name, nested_field.name) - for field in get_message_fields(test_field) - for nested_field in get_message_fields(field) - ] - - subfields_not_in_runtime = [] - - # For each item in the sample request, create a list of sub fields which are not present at runtime - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["hardware_group"].items(): # pragma: NO COVER - result = None - is_repeated = False - # For repeated fields - if isinstance(value, list) and len(value): - is_repeated = True - result = value[0] - # For fields where the type is another message - if isinstance(value, dict): - result = value - - if result and hasattr(result, "keys"): - for subfield in result.keys(): - if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) - - # Remove fields from the sample request which are not present in the runtime version of the dependency - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER - field = subfield_to_delete.get("field") - field_repeated = subfield_to_delete.get("is_repeated") - subfield = subfield_to_delete.get("subfield") - if subfield: - if field_repeated: - for i in range(0, len(request_init["hardware_group"][field])): - del request_init["hardware_group"][field][i][subfield] - else: - del request_init["hardware_group"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -20434,13 +21193,13 @@ def get_message_fields(field): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_hardware_group(request) + response = client.delete_hardware_group(request) # Establish that the response is the type that we expect. assert response.operation.name == "operations/spam" -def test_update_hardware_group_rest_use_cached_wrapped_rpc(): +def test_delete_hardware_group_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -20455,7 +21214,7 @@ def test_update_hardware_group_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.update_hardware_group + client._transport.delete_hardware_group in client._transport._wrapped_methods ) @@ -20465,11 +21224,11 @@ def test_update_hardware_group_rest_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.update_hardware_group + client._transport.delete_hardware_group ] = mock_rpc request = {} - client.update_hardware_group(request) + client.delete_hardware_group(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -20478,19 +21237,20 @@ def test_update_hardware_group_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.update_hardware_group(request) + client.delete_hardware_group(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_hardware_group_rest_required_fields( - request_type=service.UpdateHardwareGroupRequest, +def test_delete_hardware_group_rest_required_fields( + request_type=service.DeleteHardwareGroupRequest, ): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -20501,24 +21261,23 @@ def test_update_hardware_group_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_hardware_group._get_unset_required_fields(jsonified_request) + ).delete_hardware_group._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_hardware_group._get_unset_required_fields(jsonified_request) + ).delete_hardware_group._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "request_id", - "update_mask", - ) - ) + assert not set(unset_fields) - set(("request_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20539,10 +21298,9 @@ def test_update_hardware_group_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "delete", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -20552,37 +21310,24 @@ def test_update_hardware_group_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_hardware_group(request) + response = client.delete_hardware_group(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_update_hardware_group_rest_unset_required_fields(): +def test_delete_hardware_group_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_hardware_group._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "requestId", - "updateMask", - ) - ) - & set( - ( - "updateMask", - "hardwareGroup", - ) - ) - ) + unset_fields = transport.delete_hardware_group._get_unset_required_fields({}) + assert set(unset_fields) == (set(("requestId",)) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_hardware_group_rest_interceptors(null_interceptor): +def test_delete_hardware_group_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -20597,14 +21342,14 @@ def test_update_hardware_group_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_update_hardware_group" + transports.GDCHardwareManagementRestInterceptor, "post_delete_hardware_group" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_update_hardware_group" + transports.GDCHardwareManagementRestInterceptor, "pre_delete_hardware_group" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.UpdateHardwareGroupRequest.pb( - service.UpdateHardwareGroupRequest() + pb_message = service.DeleteHardwareGroupRequest.pb( + service.DeleteHardwareGroupRequest() ) transcode.return_value = { "method": "post", @@ -20620,7 +21365,7 @@ def test_update_hardware_group_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = service.UpdateHardwareGroupRequest() + request = service.DeleteHardwareGroupRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -20628,7 +21373,7 @@ def test_update_hardware_group_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.update_hardware_group( + client.delete_hardware_group( request, metadata=[ ("key", "val"), @@ -20640,8 +21385,8 @@ def test_update_hardware_group_rest_interceptors(null_interceptor): post.assert_called_once() -def test_update_hardware_group_rest_bad_request( - transport: str = "rest", request_type=service.UpdateHardwareGroupRequest +def test_delete_hardware_group_rest_bad_request( + transport: str = "rest", request_type=service.DeleteHardwareGroupRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20650,9 +21395,7 @@ def test_update_hardware_group_rest_bad_request( # send a request that will satisfy transcoding request_init = { - "hardware_group": { - "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" - } + "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" } request = request_type(**request_init) @@ -20665,10 +21408,10 @@ def test_update_hardware_group_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.update_hardware_group(request) + client.delete_hardware_group(request) -def test_update_hardware_group_rest_flattened(): +def test_delete_hardware_group_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20681,15 +21424,12 @@ def test_update_hardware_group_rest_flattened(): # get arguments that satisfy an http rule for this method sample_request = { - "hardware_group": { - "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" - } + "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" } # get truthy value for each flattened field mock_args = dict( - hardware_group=resources.HardwareGroup(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) @@ -20700,20 +21440,20 @@ def test_update_hardware_group_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.update_hardware_group(**mock_args) + client.delete_hardware_group(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{hardware_group.name=projects/*/locations/*/orders/*/hardwareGroups/*}" + "%s/v1alpha/{name=projects/*/locations/*/orders/*/hardwareGroups/*}" % client.transport._host, args[1], ) -def test_update_hardware_group_rest_flattened_error(transport: str = "rest"): +def test_delete_hardware_group_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -20722,14 +21462,13 @@ def test_update_hardware_group_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_hardware_group( - service.UpdateHardwareGroupRequest(), - hardware_group=resources.HardwareGroup(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.delete_hardware_group( + service.DeleteHardwareGroupRequest(), + name="name_value", ) -def test_update_hardware_group_rest_error(): +def test_delete_hardware_group_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -20738,41 +21477,46 @@ def test_update_hardware_group_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.DeleteHardwareGroupRequest, + service.ListHardwareRequest, dict, ], ) -def test_delete_hardware_group_rest(request_type): +def test_list_hardware_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" - } + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListHardwareResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service.ListHardwareResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_hardware_group(request) + response = client.list_hardware(request) # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" + assert isinstance(response, pagers.ListHardwarePager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] -def test_delete_hardware_group_rest_use_cached_wrapped_rpc(): +def test_list_hardware_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -20786,44 +21530,33 @@ def test_delete_hardware_group_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.delete_hardware_group - in client._transport._wrapped_methods - ) + assert client._transport.list_hardware in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_hardware_group - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_hardware] = mock_rpc request = {} - client.delete_hardware_group(request) + client.list_hardware(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.delete_hardware_group(request) + client.list_hardware(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_hardware_group_rest_required_fields( - request_type=service.DeleteHardwareGroupRequest, -): +def test_list_hardware_rest_required_fields(request_type=service.ListHardwareRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -20834,23 +21567,30 @@ def test_delete_hardware_group_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_hardware_group._get_unset_required_fields(jsonified_request) + ).list_hardware._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_hardware_group._get_unset_required_fields(jsonified_request) + ).list_hardware._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("request_id",)) + assert not set(unset_fields) - set( + ( + "filter", + "order_by", + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20859,7 +21599,7 @@ def test_delete_hardware_group_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListHardwareResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -20871,36 +21611,49 @@ def test_delete_hardware_group_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "get", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = service.ListHardwareResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_hardware_group(request) + response = client.list_hardware(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_delete_hardware_group_rest_unset_required_fields(): +def test_list_hardware_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_hardware_group._get_unset_required_fields({}) - assert set(unset_fields) == (set(("requestId",)) & set(("name",))) + unset_fields = transport.list_hardware._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "filter", + "orderBy", + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_hardware_group_rest_interceptors(null_interceptor): +def test_list_hardware_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -20913,17 +21666,13 @@ def test_delete_hardware_group_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_delete_hardware_group" + transports.GDCHardwareManagementRestInterceptor, "post_list_hardware" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_delete_hardware_group" + transports.GDCHardwareManagementRestInterceptor, "pre_list_hardware" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.DeleteHardwareGroupRequest.pb( - service.DeleteHardwareGroupRequest() - ) + pb_message = service.ListHardwareRequest.pb(service.ListHardwareRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -20934,19 +21683,19 @@ def test_delete_hardware_group_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson( - operations_pb2.Operation() + req.return_value._content = service.ListHardwareResponse.to_json( + service.ListHardwareResponse() ) - request = service.DeleteHardwareGroupRequest() + request = service.ListHardwareRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() + post.return_value = service.ListHardwareResponse() - client.delete_hardware_group( + client.list_hardware( request, metadata=[ ("key", "val"), @@ -20958,8 +21707,8 @@ def test_delete_hardware_group_rest_interceptors(null_interceptor): post.assert_called_once() -def test_delete_hardware_group_rest_bad_request( - transport: str = "rest", request_type=service.DeleteHardwareGroupRequest +def test_list_hardware_rest_bad_request( + transport: str = "rest", request_type=service.ListHardwareRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20967,9 +21716,7 @@ def test_delete_hardware_group_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" - } + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -20981,10 +21728,10 @@ def test_delete_hardware_group_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.delete_hardware_group(request) + client.list_hardware(request) -def test_delete_hardware_group_rest_flattened(): +def test_list_hardware_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20993,40 +21740,40 @@ def test_delete_hardware_group_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListHardwareResponse() # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/orders/sample3/hardwareGroups/sample4" - } + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service.ListHardwareResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.delete_hardware_group(**mock_args) + client.list_hardware(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{name=projects/*/locations/*/orders/*/hardwareGroups/*}" + "%s/v1alpha/{parent=projects/*/locations/*}/hardware" % client.transport._host, args[1], ) -def test_delete_hardware_group_rest_flattened_error(transport: str = "rest"): +def test_list_hardware_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -21035,61 +21782,128 @@ def test_delete_hardware_group_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_hardware_group( - service.DeleteHardwareGroupRequest(), - name="name_value", + client.list_hardware( + service.ListHardwareRequest(), + parent="parent_value", ) -def test_delete_hardware_group_rest_error(): +def test_list_hardware_rest_pager(transport: str = "rest"): client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + service.ListHardwareResponse( + hardware=[ + resources.Hardware(), + resources.Hardware(), + resources.Hardware(), + ], + next_page_token="abc", + ), + service.ListHardwareResponse( + hardware=[], + next_page_token="def", + ), + service.ListHardwareResponse( + hardware=[ + resources.Hardware(), + ], + next_page_token="ghi", + ), + service.ListHardwareResponse( + hardware=[ + resources.Hardware(), + resources.Hardware(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(service.ListHardwareResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_hardware(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, resources.Hardware) for i in results) + + pages = list(client.list_hardware(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + @pytest.mark.parametrize( "request_type", [ - service.ListHardwareRequest, + service.GetHardwareRequest, dict, ], ) -def test_list_hardware_rest(request_type): +def test_get_hardware_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"name": "projects/sample1/locations/sample2/hardware/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service.ListHardwareResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + return_value = resources.Hardware( + name="name_value", + display_name="display_name_value", + order="order_value", + hardware_group="hardware_group_value", + site="site_value", + state=resources.Hardware.State.ADDITIONAL_INFO_NEEDED, + ciq_uri="ciq_uri_value", + zone="zone_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListHardwareResponse.pb(return_value) + return_value = resources.Hardware.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_hardware(request) + response = client.get_hardware(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListHardwarePager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, resources.Hardware) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.order == "order_value" + assert response.hardware_group == "hardware_group_value" + assert response.site == "site_value" + assert response.state == resources.Hardware.State.ADDITIONAL_INFO_NEEDED + assert response.ciq_uri == "ciq_uri_value" + assert response.zone == "zone_value" -def test_list_hardware_rest_use_cached_wrapped_rpc(): +def test_get_hardware_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -21103,33 +21917,33 @@ def test_list_hardware_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_hardware in client._transport._wrapped_methods + assert client._transport.get_hardware in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_hardware] = mock_rpc + client._transport._wrapped_methods[client._transport.get_hardware] = mock_rpc request = {} - client.list_hardware(request) + client.get_hardware(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_hardware(request) + client.get_hardware(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_hardware_rest_required_fields(request_type=service.ListHardwareRequest): +def test_get_hardware_rest_required_fields(request_type=service.GetHardwareRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["parent"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -21140,30 +21954,21 @@ def test_list_hardware_rest_required_fields(request_type=service.ListHardwareReq unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_hardware._get_unset_required_fields(jsonified_request) + ).get_hardware._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_hardware._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "filter", - "order_by", - "page_size", - "page_token", - ) - ) + ).get_hardware._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -21172,7 +21977,7 @@ def test_list_hardware_rest_required_fields(request_type=service.ListHardwareReq request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = service.ListHardwareResponse() + return_value = resources.Hardware() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -21193,40 +21998,30 @@ def test_list_hardware_rest_required_fields(request_type=service.ListHardwareReq response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListHardwareResponse.pb(return_value) + return_value = resources.Hardware.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_hardware(request) + response = client.get_hardware(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_hardware_rest_unset_required_fields(): +def test_get_hardware_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_hardware._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "filter", - "orderBy", - "pageSize", - "pageToken", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.get_hardware._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_hardware_rest_interceptors(null_interceptor): +def test_get_hardware_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -21239,13 +22034,13 @@ def test_list_hardware_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_hardware" + transports.GDCHardwareManagementRestInterceptor, "post_get_hardware" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_hardware" + transports.GDCHardwareManagementRestInterceptor, "pre_get_hardware" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.ListHardwareRequest.pb(service.ListHardwareRequest()) + pb_message = service.GetHardwareRequest.pb(service.GetHardwareRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -21256,19 +22051,17 @@ def test_list_hardware_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = service.ListHardwareResponse.to_json( - service.ListHardwareResponse() - ) + req.return_value._content = resources.Hardware.to_json(resources.Hardware()) - request = service.ListHardwareRequest() + request = service.GetHardwareRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = service.ListHardwareResponse() + post.return_value = resources.Hardware() - client.list_hardware( + client.get_hardware( request, metadata=[ ("key", "val"), @@ -21280,8 +22073,8 @@ def test_list_hardware_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_hardware_rest_bad_request( - transport: str = "rest", request_type=service.ListHardwareRequest +def test_get_hardware_rest_bad_request( + transport: str = "rest", request_type=service.GetHardwareRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -21289,7 +22082,7 @@ def test_list_hardware_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"name": "projects/sample1/locations/sample2/hardware/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -21301,10 +22094,10 @@ def test_list_hardware_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.list_hardware(request) + client.get_hardware(request) -def test_list_hardware_rest_flattened(): +def test_get_hardware_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -21313,14 +22106,14 @@ def test_list_hardware_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service.ListHardwareResponse() + return_value = resources.Hardware() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = {"name": "projects/sample1/locations/sample2/hardware/sample3"} # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + name="name_value", ) mock_args.update(sample_request) @@ -21328,25 +22121,25 @@ def test_list_hardware_rest_flattened(): response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListHardwareResponse.pb(return_value) + return_value = resources.Hardware.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.list_hardware(**mock_args) + client.get_hardware(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{parent=projects/*/locations/*}/hardware" + "%s/v1alpha/{name=projects/*/locations/*/hardware/*}" % client.transport._host, args[1], ) -def test_list_hardware_rest_flattened_error(transport: str = "rest"): +def test_get_hardware_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -21355,128 +22148,160 @@ def test_list_hardware_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_hardware( - service.ListHardwareRequest(), - parent="parent_value", + client.get_hardware( + service.GetHardwareRequest(), + name="name_value", ) -def test_list_hardware_rest_pager(transport: str = "rest"): +def test_get_hardware_rest_error(): client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - service.ListHardwareResponse( - hardware=[ - resources.Hardware(), - resources.Hardware(), - resources.Hardware(), - ], - next_page_token="abc", - ), - service.ListHardwareResponse( - hardware=[], - next_page_token="def", - ), - service.ListHardwareResponse( - hardware=[ - resources.Hardware(), - ], - next_page_token="ghi", - ), - service.ListHardwareResponse( - hardware=[ - resources.Hardware(), - resources.Hardware(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(service.ListHardwareResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_hardware(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, resources.Hardware) for i in results) - - pages = list(client.list_hardware(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - @pytest.mark.parametrize( "request_type", [ - service.GetHardwareRequest, + service.CreateHardwareRequest, dict, ], ) -def test_get_hardware_rest(request_type): +def test_create_hardware_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) - # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/hardware/sample3"} + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["hardware"] = { + "name": "name_value", + "display_name": "display_name_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "labels": {}, + "order": "order_value", + "hardware_group": "hardware_group_value", + "site": "site_value", + "state": 1, + "ciq_uri": "ciq_uri_value", + "config": { + "sku": "sku_value", + "power_supply": 1, + "subscription_duration_months": 3042, + }, + "estimated_installation_date": {"year": 433, "month": 550, "day": 318}, + "physical_info": { + "power_receptacle": 1, + "network_uplink": 1, + "voltage": 1, + "amperes": 1, + }, + "installation_info": { + "rack_location": "rack_location_value", + "power_distance_meters": 2246, + "switch_distance_meters": 2347, + "rack_unit_dimensions": { + "width_inches": 0.1273, + "height_inches": 0.13620000000000002, + "depth_inches": 0.1262, + }, + "rack_space": {"start_rack_unit": 1613, "end_rack_unit": 1366}, + "rack_type": 1, + }, + "zone": "zone_value", + "requested_installation_date": {}, + "actual_installation_date": {}, + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = service.CreateHardwareRequest.meta.fields["hardware"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["hardware"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["hardware"][field])): + del request_init["hardware"][field][i][subfield] + else: + del request_init["hardware"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = resources.Hardware( - name="name_value", - display_name="display_name_value", - order="order_value", - hardware_group="hardware_group_value", - site="site_value", - state=resources.Hardware.State.ADDITIONAL_INFO_NEEDED, - ciq_uri="ciq_uri_value", - zone="zone_value", - ) + return_value = operations_pb2.Operation(name="operations/spam") # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = resources.Hardware.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_hardware(request) + response = client.create_hardware(request) # Establish that the response is the type that we expect. - assert isinstance(response, resources.Hardware) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.order == "order_value" - assert response.hardware_group == "hardware_group_value" - assert response.site == "site_value" - assert response.state == resources.Hardware.State.ADDITIONAL_INFO_NEEDED - assert response.ciq_uri == "ciq_uri_value" - assert response.zone == "zone_value" + assert response.operation.name == "operations/spam" -def test_get_hardware_rest_use_cached_wrapped_rpc(): +def test_create_hardware_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -21490,33 +22315,39 @@ def test_get_hardware_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_hardware in client._transport._wrapped_methods + assert client._transport.create_hardware in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_hardware] = mock_rpc + client._transport._wrapped_methods[client._transport.create_hardware] = mock_rpc request = {} - client.get_hardware(request) + client.create_hardware(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_hardware(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_hardware(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_hardware_rest_required_fields(request_type=service.GetHardwareRequest): +def test_create_hardware_rest_required_fields( + request_type=service.CreateHardwareRequest, +): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -21527,21 +22358,23 @@ def test_get_hardware_rest_required_fields(request_type=service.GetHardwareReque unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_hardware._get_unset_required_fields(jsonified_request) + ).create_hardware._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_hardware._get_unset_required_fields(jsonified_request) + ).create_hardware._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("hardware_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -21550,7 +22383,7 @@ def test_get_hardware_rest_required_fields(request_type=service.GetHardwareReque request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = resources.Hardware() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -21562,39 +22395,45 @@ def test_get_hardware_rest_required_fields(request_type=service.GetHardwareReque pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = resources.Hardware.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_hardware(request) + response = client.create_hardware(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_hardware_rest_unset_required_fields(): +def test_create_hardware_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_hardware._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_hardware._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("hardwareId",)) + & set( + ( + "parent", + "hardware", + ) + ) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_hardware_rest_interceptors(null_interceptor): +def test_create_hardware_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -21607,13 +22446,15 @@ def test_get_hardware_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_hardware" + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_create_hardware" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_hardware" + transports.GDCHardwareManagementRestInterceptor, "pre_create_hardware" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.GetHardwareRequest.pb(service.GetHardwareRequest()) + pb_message = service.CreateHardwareRequest.pb(service.CreateHardwareRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -21624,17 +22465,19 @@ def test_get_hardware_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = resources.Hardware.to_json(resources.Hardware()) + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) - request = service.GetHardwareRequest() + request = service.CreateHardwareRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = resources.Hardware() + post.return_value = operations_pb2.Operation() - client.get_hardware( + client.create_hardware( request, metadata=[ ("key", "val"), @@ -21646,8 +22489,8 @@ def test_get_hardware_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_hardware_rest_bad_request( - transport: str = "rest", request_type=service.GetHardwareRequest +def test_create_hardware_rest_bad_request( + transport: str = "rest", request_type=service.CreateHardwareRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -21655,7 +22498,7 @@ def test_get_hardware_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/hardware/sample3"} + request_init = {"parent": "projects/sample1/locations/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -21667,10 +22510,10 @@ def test_get_hardware_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_hardware(request) + client.create_hardware(request) -def test_get_hardware_rest_flattened(): +def test_create_hardware_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -21679,40 +22522,40 @@ def test_get_hardware_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = resources.Hardware() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"name": "projects/sample1/locations/sample2/hardware/sample3"} + sample_request = {"parent": "projects/sample1/locations/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + hardware=resources.Hardware(name="name_value"), + hardware_id="hardware_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = resources.Hardware.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.get_hardware(**mock_args) + client.create_hardware(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{name=projects/*/locations/*/hardware/*}" + "%s/v1alpha/{parent=projects/*/locations/*}/hardware" % client.transport._host, args[1], ) -def test_get_hardware_rest_flattened_error(transport: str = "rest"): +def test_create_hardware_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -21721,13 +22564,15 @@ def test_get_hardware_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_hardware( - service.GetHardwareRequest(), - name="name_value", + client.create_hardware( + service.CreateHardwareRequest(), + parent="parent_value", + hardware=resources.Hardware(name="name_value"), + hardware_id="hardware_id_value", ) -def test_get_hardware_rest_error(): +def test_create_hardware_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -21736,20 +22581,22 @@ def test_get_hardware_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.CreateHardwareRequest, + service.UpdateHardwareRequest, dict, ], ) -def test_create_hardware_rest(request_type): +def test_update_hardware_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = { + "hardware": {"name": "projects/sample1/locations/sample2/hardware/sample3"} + } request_init["hardware"] = { - "name": "name_value", + "name": "projects/sample1/locations/sample2/hardware/sample3", "display_name": "display_name_value", "create_time": {"seconds": 751, "nanos": 543}, "update_time": {}, @@ -21792,7 +22639,7 @@ def test_create_hardware_rest(request_type): # See https://github.com/googleapis/gapic-generator-python/issues/1748 # Determine if the message type is proto-plus or protobuf - test_field = service.CreateHardwareRequest.meta.fields["hardware"] + test_field = service.UpdateHardwareRequest.meta.fields["hardware"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -21868,13 +22715,13 @@ def get_message_fields(field): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_hardware(request) + response = client.update_hardware(request) # Establish that the response is the type that we expect. assert response.operation.name == "operations/spam" -def test_create_hardware_rest_use_cached_wrapped_rpc(): +def test_update_hardware_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -21888,17 +22735,17 @@ def test_create_hardware_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_hardware in client._transport._wrapped_methods + assert client._transport.update_hardware in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_hardware] = mock_rpc + client._transport._wrapped_methods[client._transport.update_hardware] = mock_rpc request = {} - client.create_hardware(request) + client.update_hardware(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -21907,20 +22754,19 @@ def test_create_hardware_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.create_hardware(request) + client.update_hardware(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_hardware_rest_required_fields( - request_type=service.CreateHardwareRequest, +def test_update_hardware_rest_required_fields( + request_type=service.UpdateHardwareRequest, ): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -21931,23 +22777,24 @@ def test_create_hardware_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_hardware._get_unset_required_fields(jsonified_request) + ).update_hardware._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_hardware._get_unset_required_fields(jsonified_request) + ).update_hardware._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("hardware_id",)) + assert not set(unset_fields) - set( + ( + "request_id", + "update_mask", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -21968,7 +22815,7 @@ def test_create_hardware_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "patch", "query_params": pb_request, } transcode_result["body"] = pb_request @@ -21981,24 +22828,29 @@ def test_create_hardware_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_hardware(request) + response = client.update_hardware(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_hardware_rest_unset_required_fields(): +def test_update_hardware_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_hardware._get_unset_required_fields({}) + unset_fields = transport.update_hardware._get_unset_required_fields({}) assert set(unset_fields) == ( - set(("hardwareId",)) + set( + ( + "requestId", + "updateMask", + ) + ) & set( ( - "parent", + "updateMask", "hardware", ) ) @@ -22006,7 +22858,7 @@ def test_create_hardware_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_hardware_rest_interceptors(null_interceptor): +def test_update_hardware_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -22021,13 +22873,13 @@ def test_create_hardware_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_hardware" + transports.GDCHardwareManagementRestInterceptor, "post_update_hardware" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_hardware" + transports.GDCHardwareManagementRestInterceptor, "pre_update_hardware" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.CreateHardwareRequest.pb(service.CreateHardwareRequest()) + pb_message = service.UpdateHardwareRequest.pb(service.UpdateHardwareRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -22042,7 +22894,7 @@ def test_create_hardware_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = service.CreateHardwareRequest() + request = service.UpdateHardwareRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -22050,7 +22902,7 @@ def test_create_hardware_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.create_hardware( + client.update_hardware( request, metadata=[ ("key", "val"), @@ -22062,8 +22914,8 @@ def test_create_hardware_rest_interceptors(null_interceptor): post.assert_called_once() -def test_create_hardware_rest_bad_request( - transport: str = "rest", request_type=service.CreateHardwareRequest +def test_update_hardware_rest_bad_request( + transport: str = "rest", request_type=service.UpdateHardwareRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -22071,7 +22923,9 @@ def test_create_hardware_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = { + "hardware": {"name": "projects/sample1/locations/sample2/hardware/sample3"} + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -22083,10 +22937,10 @@ def test_create_hardware_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.create_hardware(request) + client.update_hardware(request) -def test_create_hardware_rest_flattened(): +def test_update_hardware_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -22098,13 +22952,14 @@ def test_create_hardware_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "hardware": {"name": "projects/sample1/locations/sample2/hardware/sample3"} + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", hardware=resources.Hardware(name="name_value"), - hardware_id="hardware_id_value", + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) @@ -22115,37 +22970,36 @@ def test_create_hardware_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.create_hardware(**mock_args) + client.update_hardware(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{parent=projects/*/locations/*}/hardware" + "%s/v1alpha/{hardware.name=projects/*/locations/*/hardware/*}" % client.transport._host, args[1], ) -def test_create_hardware_rest_flattened_error(transport: str = "rest"): +def test_update_hardware_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_hardware( - service.CreateHardwareRequest(), - parent="parent_value", + # fields is an error. + with pytest.raises(ValueError): + client.update_hardware( + service.UpdateHardwareRequest(), hardware=resources.Hardware(name="name_value"), - hardware_id="hardware_id_value", + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_create_hardware_rest_error(): +def test_update_hardware_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -22154,126 +23008,18 @@ def test_create_hardware_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.UpdateHardwareRequest, + service.DeleteHardwareRequest, dict, ], ) -def test_update_hardware_rest(request_type): +def test_delete_hardware_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = { - "hardware": {"name": "projects/sample1/locations/sample2/hardware/sample3"} - } - request_init["hardware"] = { - "name": "projects/sample1/locations/sample2/hardware/sample3", - "display_name": "display_name_value", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "labels": {}, - "order": "order_value", - "hardware_group": "hardware_group_value", - "site": "site_value", - "state": 1, - "ciq_uri": "ciq_uri_value", - "config": { - "sku": "sku_value", - "power_supply": 1, - "subscription_duration_months": 3042, - }, - "estimated_installation_date": {"year": 433, "month": 550, "day": 318}, - "physical_info": { - "power_receptacle": 1, - "network_uplink": 1, - "voltage": 1, - "amperes": 1, - }, - "installation_info": { - "rack_location": "rack_location_value", - "power_distance_meters": 2246, - "switch_distance_meters": 2347, - "rack_unit_dimensions": { - "width_inches": 0.1273, - "height_inches": 0.13620000000000002, - "depth_inches": 0.1262, - }, - "rack_space": {"start_rack_unit": 1613, "end_rack_unit": 1366}, - "rack_type": 1, - }, - "zone": "zone_value", - "requested_installation_date": {}, - "actual_installation_date": {}, - } - # The version of a generated dependency at test runtime may differ from the version used during generation. - # Delete any fields which are not present in the current runtime dependency - # See https://github.com/googleapis/gapic-generator-python/issues/1748 - - # Determine if the message type is proto-plus or protobuf - test_field = service.UpdateHardwareRequest.meta.fields["hardware"] - - def get_message_fields(field): - # Given a field which is a message (composite type), return a list with - # all the fields of the message. - # If the field is not a composite type, return an empty list. - message_fields = [] - - if hasattr(field, "message") and field.message: - is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - - if is_field_type_proto_plus_type: - message_fields = field.message.meta.fields.values() - # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER - message_fields = field.message.DESCRIPTOR.fields - return message_fields - - runtime_nested_fields = [ - (field.name, nested_field.name) - for field in get_message_fields(test_field) - for nested_field in get_message_fields(field) - ] - - subfields_not_in_runtime = [] - - # For each item in the sample request, create a list of sub fields which are not present at runtime - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["hardware"].items(): # pragma: NO COVER - result = None - is_repeated = False - # For repeated fields - if isinstance(value, list) and len(value): - is_repeated = True - result = value[0] - # For fields where the type is another message - if isinstance(value, dict): - result = value - - if result and hasattr(result, "keys"): - for subfield in result.keys(): - if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) - - # Remove fields from the sample request which are not present in the runtime version of the dependency - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER - field = subfield_to_delete.get("field") - field_repeated = subfield_to_delete.get("is_repeated") - subfield = subfield_to_delete.get("subfield") - if subfield: - if field_repeated: - for i in range(0, len(request_init["hardware"][field])): - del request_init["hardware"][field][i][subfield] - else: - del request_init["hardware"][field][subfield] + request_init = {"name": "projects/sample1/locations/sample2/hardware/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -22288,13 +23034,13 @@ def get_message_fields(field): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_hardware(request) + response = client.delete_hardware(request) # Establish that the response is the type that we expect. assert response.operation.name == "operations/spam" -def test_update_hardware_rest_use_cached_wrapped_rpc(): +def test_delete_hardware_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -22308,17 +23054,17 @@ def test_update_hardware_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_hardware in client._transport._wrapped_methods + assert client._transport.delete_hardware in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_hardware] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_hardware] = mock_rpc request = {} - client.update_hardware(request) + client.delete_hardware(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 @@ -22327,19 +23073,20 @@ def test_update_hardware_rest_use_cached_wrapped_rpc(): # subsequent calls should use the cached wrapper wrapper_fn.reset_mock() - client.update_hardware(request) + client.delete_hardware(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_hardware_rest_required_fields( - request_type=service.UpdateHardwareRequest, +def test_delete_hardware_rest_required_fields( + request_type=service.DeleteHardwareRequest, ): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -22350,24 +23097,23 @@ def test_update_hardware_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_hardware._get_unset_required_fields(jsonified_request) + ).delete_hardware._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["name"] = "name_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_hardware._get_unset_required_fields(jsonified_request) + ).delete_hardware._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "request_id", - "update_mask", - ) - ) + assert not set(unset_fields) - set(("request_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -22388,10 +23134,9 @@ def test_update_hardware_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "delete", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -22401,37 +23146,24 @@ def test_update_hardware_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_hardware(request) + response = client.delete_hardware(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_update_hardware_rest_unset_required_fields(): +def test_delete_hardware_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_hardware._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "requestId", - "updateMask", - ) - ) - & set( - ( - "updateMask", - "hardware", - ) - ) - ) + unset_fields = transport.delete_hardware._get_unset_required_fields({}) + assert set(unset_fields) == (set(("requestId",)) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_hardware_rest_interceptors(null_interceptor): +def test_delete_hardware_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -22446,13 +23178,13 @@ def test_update_hardware_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_update_hardware" + transports.GDCHardwareManagementRestInterceptor, "post_delete_hardware" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_update_hardware" + transports.GDCHardwareManagementRestInterceptor, "pre_delete_hardware" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.UpdateHardwareRequest.pb(service.UpdateHardwareRequest()) + pb_message = service.DeleteHardwareRequest.pb(service.DeleteHardwareRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -22467,7 +23199,7 @@ def test_update_hardware_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = service.UpdateHardwareRequest() + request = service.DeleteHardwareRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -22475,7 +23207,7 @@ def test_update_hardware_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.update_hardware( + client.delete_hardware( request, metadata=[ ("key", "val"), @@ -22487,8 +23219,8 @@ def test_update_hardware_rest_interceptors(null_interceptor): post.assert_called_once() -def test_update_hardware_rest_bad_request( - transport: str = "rest", request_type=service.UpdateHardwareRequest +def test_delete_hardware_rest_bad_request( + transport: str = "rest", request_type=service.DeleteHardwareRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -22496,9 +23228,7 @@ def test_update_hardware_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = { - "hardware": {"name": "projects/sample1/locations/sample2/hardware/sample3"} - } + request_init = {"name": "projects/sample1/locations/sample2/hardware/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -22510,10 +23240,10 @@ def test_update_hardware_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.update_hardware(request) + client.delete_hardware(request) -def test_update_hardware_rest_flattened(): +def test_delete_hardware_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -22525,14 +23255,11 @@ def test_update_hardware_rest_flattened(): return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "hardware": {"name": "projects/sample1/locations/sample2/hardware/sample3"} - } + sample_request = {"name": "projects/sample1/locations/sample2/hardware/sample3"} # get truthy value for each flattened field mock_args = dict( - hardware=resources.Hardware(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + name="name_value", ) mock_args.update(sample_request) @@ -22543,20 +23270,20 @@ def test_update_hardware_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.update_hardware(**mock_args) + client.delete_hardware(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{hardware.name=projects/*/locations/*/hardware/*}" + "%s/v1alpha/{name=projects/*/locations/*/hardware/*}" % client.transport._host, args[1], ) -def test_update_hardware_rest_flattened_error(transport: str = "rest"): +def test_delete_hardware_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -22565,14 +23292,13 @@ def test_update_hardware_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_hardware( - service.UpdateHardwareRequest(), - hardware=resources.Hardware(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.delete_hardware( + service.DeleteHardwareRequest(), + name="name_value", ) -def test_update_hardware_rest_error(): +def test_delete_hardware_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -22581,39 +23307,46 @@ def test_update_hardware_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.DeleteHardwareRequest, + service.ListCommentsRequest, dict, ], ) -def test_delete_hardware_rest(request_type): +def test_list_comments_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/hardware/sample3"} + request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListCommentsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service.ListCommentsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_hardware(request) + response = client.list_comments(request) # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" + assert isinstance(response, pagers.ListCommentsPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] -def test_delete_hardware_rest_use_cached_wrapped_rpc(): +def test_list_comments_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -22627,39 +23360,33 @@ def test_delete_hardware_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_hardware in client._transport._wrapped_methods + assert client._transport.list_comments in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_hardware] = mock_rpc + client._transport._wrapped_methods[client._transport.list_comments] = mock_rpc request = {} - client.delete_hardware(request) + client.list_comments(request) # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() + assert mock_rpc.call_count == 1 - client.delete_hardware(request) + client.list_comments(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_hardware_rest_required_fields( - request_type=service.DeleteHardwareRequest, -): +def test_list_comments_rest_required_fields(request_type=service.ListCommentsRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -22670,23 +23397,30 @@ def test_delete_hardware_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_hardware._get_unset_required_fields(jsonified_request) + ).list_comments._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_hardware._get_unset_required_fields(jsonified_request) + ).list_comments._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("request_id",)) + assert not set(unset_fields) - set( + ( + "filter", + "order_by", + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -22695,7 +23429,7 @@ def test_delete_hardware_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListCommentsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -22707,36 +23441,49 @@ def test_delete_hardware_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "get", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = service.ListCommentsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_hardware(request) + response = client.list_comments(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_delete_hardware_rest_unset_required_fields(): +def test_list_comments_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_hardware._get_unset_required_fields({}) - assert set(unset_fields) == (set(("requestId",)) & set(("name",))) + unset_fields = transport.list_comments._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "filter", + "orderBy", + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_hardware_rest_interceptors(null_interceptor): +def test_list_comments_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -22749,15 +23496,13 @@ def test_delete_hardware_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_delete_hardware" + transports.GDCHardwareManagementRestInterceptor, "post_list_comments" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_delete_hardware" + transports.GDCHardwareManagementRestInterceptor, "pre_list_comments" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.DeleteHardwareRequest.pb(service.DeleteHardwareRequest()) + pb_message = service.ListCommentsRequest.pb(service.ListCommentsRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -22768,19 +23513,19 @@ def test_delete_hardware_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson( - operations_pb2.Operation() + req.return_value._content = service.ListCommentsResponse.to_json( + service.ListCommentsResponse() ) - request = service.DeleteHardwareRequest() + request = service.ListCommentsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() + post.return_value = service.ListCommentsResponse() - client.delete_hardware( + client.list_comments( request, metadata=[ ("key", "val"), @@ -22792,8 +23537,8 @@ def test_delete_hardware_rest_interceptors(null_interceptor): post.assert_called_once() -def test_delete_hardware_rest_bad_request( - transport: str = "rest", request_type=service.DeleteHardwareRequest +def test_list_comments_rest_bad_request( + transport: str = "rest", request_type=service.ListCommentsRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -22801,7 +23546,7 @@ def test_delete_hardware_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/hardware/sample3"} + request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -22813,10 +23558,10 @@ def test_delete_hardware_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.delete_hardware(request) + client.list_comments(request) -def test_delete_hardware_rest_flattened(): +def test_list_comments_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -22825,38 +23570,40 @@ def test_delete_hardware_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = service.ListCommentsResponse() # get arguments that satisfy an http rule for this method - sample_request = {"name": "projects/sample1/locations/sample2/hardware/sample3"} + sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = service.ListCommentsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.delete_hardware(**mock_args) + client.list_comments(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{name=projects/*/locations/*/hardware/*}" + "%s/v1alpha/{parent=projects/*/locations/*/orders/*}/comments" % client.transport._host, args[1], ) -def test_delete_hardware_rest_flattened_error(transport: str = "rest"): +def test_list_comments_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -22865,61 +23612,122 @@ def test_delete_hardware_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_hardware( - service.DeleteHardwareRequest(), - name="name_value", + client.list_comments( + service.ListCommentsRequest(), + parent="parent_value", ) -def test_delete_hardware_rest_error(): +def test_list_comments_rest_pager(transport: str = "rest"): client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + service.ListCommentsResponse( + comments=[ + resources.Comment(), + resources.Comment(), + resources.Comment(), + ], + next_page_token="abc", + ), + service.ListCommentsResponse( + comments=[], + next_page_token="def", + ), + service.ListCommentsResponse( + comments=[ + resources.Comment(), + ], + next_page_token="ghi", + ), + service.ListCommentsResponse( + comments=[ + resources.Comment(), + resources.Comment(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(service.ListCommentsResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + + pager = client.list_comments(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, resources.Comment) for i in results) + + pages = list(client.list_comments(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + @pytest.mark.parametrize( "request_type", [ - service.ListCommentsRequest, + service.GetCommentRequest, dict, ], ) -def test_list_comments_rest(request_type): +def test_get_comment_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/orders/sample3/comments/sample4" + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service.ListCommentsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], + return_value = resources.Comment( + name="name_value", + author="author_value", + text="text_value", + author_entity=resources.Entity.GOOGLE, ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListCommentsResponse.pb(return_value) + return_value = resources.Comment.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_comments(request) + response = client.get_comment(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListCommentsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] + assert isinstance(response, resources.Comment) + assert response.name == "name_value" + assert response.author == "author_value" + assert response.text == "text_value" + assert response.author_entity == resources.Entity.GOOGLE -def test_list_comments_rest_use_cached_wrapped_rpc(): +def test_get_comment_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -22933,33 +23741,33 @@ def test_list_comments_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_comments in client._transport._wrapped_methods + assert client._transport.get_comment in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_comments] = mock_rpc + client._transport._wrapped_methods[client._transport.get_comment] = mock_rpc request = {} - client.list_comments(request) + client.get_comment(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_comments(request) + client.get_comment(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_comments_rest_required_fields(request_type=service.ListCommentsRequest): +def test_get_comment_rest_required_fields(request_type=service.GetCommentRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["parent"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -22970,30 +23778,21 @@ def test_list_comments_rest_required_fields(request_type=service.ListCommentsReq unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_comments._get_unset_required_fields(jsonified_request) + ).get_comment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_comments._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "filter", - "order_by", - "page_size", - "page_token", - ) - ) + ).get_comment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23002,7 +23801,7 @@ def test_list_comments_rest_required_fields(request_type=service.ListCommentsReq request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = service.ListCommentsResponse() + return_value = resources.Comment() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -23023,40 +23822,30 @@ def test_list_comments_rest_required_fields(request_type=service.ListCommentsReq response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListCommentsResponse.pb(return_value) + return_value = resources.Comment.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_comments(request) + response = client.get_comment(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_comments_rest_unset_required_fields(): +def test_get_comment_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_comments._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "filter", - "orderBy", - "pageSize", - "pageToken", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.get_comment._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_comments_rest_interceptors(null_interceptor): +def test_get_comment_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -23069,13 +23858,13 @@ def test_list_comments_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_comments" + transports.GDCHardwareManagementRestInterceptor, "post_get_comment" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_comments" + transports.GDCHardwareManagementRestInterceptor, "pre_get_comment" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.ListCommentsRequest.pb(service.ListCommentsRequest()) + pb_message = service.GetCommentRequest.pb(service.GetCommentRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -23086,19 +23875,17 @@ def test_list_comments_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = service.ListCommentsResponse.to_json( - service.ListCommentsResponse() - ) + req.return_value._content = resources.Comment.to_json(resources.Comment()) - request = service.ListCommentsRequest() + request = service.GetCommentRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = service.ListCommentsResponse() + post.return_value = resources.Comment() - client.list_comments( + client.get_comment( request, metadata=[ ("key", "val"), @@ -23110,8 +23897,8 @@ def test_list_comments_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_comments_rest_bad_request( - transport: str = "rest", request_type=service.ListCommentsRequest +def test_get_comment_rest_bad_request( + transport: str = "rest", request_type=service.GetCommentRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23119,7 +23906,9 @@ def test_list_comments_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/orders/sample3/comments/sample4" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -23131,10 +23920,10 @@ def test_list_comments_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.list_comments(request) + client.get_comment(request) -def test_list_comments_rest_flattened(): +def test_get_comment_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -23143,14 +23932,16 @@ def test_list_comments_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = service.ListCommentsResponse() + return_value = resources.Comment() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + sample_request = { + "name": "projects/sample1/locations/sample2/orders/sample3/comments/sample4" + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + name="name_value", ) mock_args.update(sample_request) @@ -23158,25 +23949,25 @@ def test_list_comments_rest_flattened(): response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = service.ListCommentsResponse.pb(return_value) + return_value = resources.Comment.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.list_comments(**mock_args) + client.get_comment(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{parent=projects/*/locations/*/orders/*}/comments" + "%s/v1alpha/{name=projects/*/locations/*/orders/*/comments/*}" % client.transport._host, args[1], ) -def test_list_comments_rest_flattened_error(transport: str = "rest"): +def test_get_comment_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -23185,120 +23976,130 @@ def test_list_comments_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_comments( - service.ListCommentsRequest(), - parent="parent_value", + client.get_comment( + service.GetCommentRequest(), + name="name_value", ) -def test_list_comments_rest_pager(transport: str = "rest"): +def test_get_comment_rest_error(): client = GDCHardwareManagementClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - service.ListCommentsResponse( - comments=[ - resources.Comment(), - resources.Comment(), - resources.Comment(), - ], - next_page_token="abc", - ), - service.ListCommentsResponse( - comments=[], - next_page_token="def", - ), - service.ListCommentsResponse( - comments=[ - resources.Comment(), - ], - next_page_token="ghi", - ), - service.ListCommentsResponse( - comments=[ - resources.Comment(), - resources.Comment(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(service.ListCommentsResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} - - pager = client.list_comments(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, resources.Comment) for i in results) - - pages = list(client.list_comments(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - @pytest.mark.parametrize( "request_type", [ - service.GetCommentRequest, + service.CreateCommentRequest, dict, ], ) -def test_get_comment_rest(request_type): +def test_create_comment_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/orders/sample3/comments/sample4" + request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + request_init["comment"] = { + "name": "name_value", + "create_time": {"seconds": 751, "nanos": 543}, + "labels": {}, + "author": "author_value", + "text": "text_value", + "customer_viewed_time": {}, + "author_entity": 1, } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = service.CreateCommentRequest.meta.fields["comment"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["comment"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["comment"][field])): + del request_init["comment"][field][i][subfield] + else: + del request_init["comment"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = resources.Comment( - name="name_value", - author="author_value", - text="text_value", - ) + return_value = operations_pb2.Operation(name="operations/spam") # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = resources.Comment.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_comment(request) + response = client.create_comment(request) # Establish that the response is the type that we expect. - assert isinstance(response, resources.Comment) - assert response.name == "name_value" - assert response.author == "author_value" - assert response.text == "text_value" + assert response.operation.name == "operations/spam" -def test_get_comment_rest_use_cached_wrapped_rpc(): +def test_create_comment_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -23312,33 +24113,37 @@ def test_get_comment_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_comment in client._transport._wrapped_methods + assert client._transport.create_comment in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_comment] = mock_rpc + client._transport._wrapped_methods[client._transport.create_comment] = mock_rpc request = {} - client.get_comment(request) + client.create_comment(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_comment(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_comment(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_comment_rest_required_fields(request_type=service.GetCommentRequest): +def test_create_comment_rest_required_fields(request_type=service.CreateCommentRequest): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -23349,21 +24154,28 @@ def test_get_comment_rest_required_fields(request_type=service.GetCommentRequest unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_comment._get_unset_required_fields(jsonified_request) + ).create_comment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_comment._get_unset_required_fields(jsonified_request) + ).create_comment._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "comment_id", + "request_id", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23372,7 +24184,7 @@ def test_get_comment_rest_required_fields(request_type=service.GetCommentRequest request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = resources.Comment() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -23384,39 +24196,50 @@ def test_get_comment_rest_required_fields(request_type=service.GetCommentRequest pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = resources.Comment.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_comment(request) + response = client.create_comment(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_comment_rest_unset_required_fields(): +def test_create_comment_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_comment._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.create_comment._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "commentId", + "requestId", + ) + ) + & set( + ( + "parent", + "comment", + ) + ) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_comment_rest_interceptors(null_interceptor): +def test_create_comment_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -23429,13 +24252,15 @@ def test_get_comment_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_comment" + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_create_comment" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_comment" + transports.GDCHardwareManagementRestInterceptor, "pre_create_comment" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.GetCommentRequest.pb(service.GetCommentRequest()) + pb_message = service.CreateCommentRequest.pb(service.CreateCommentRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -23446,17 +24271,19 @@ def test_get_comment_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = resources.Comment.to_json(resources.Comment()) + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) - request = service.GetCommentRequest() + request = service.CreateCommentRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = resources.Comment() + post.return_value = operations_pb2.Operation() - client.get_comment( + client.create_comment( request, metadata=[ ("key", "val"), @@ -23468,8 +24295,8 @@ def test_get_comment_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_comment_rest_bad_request( - transport: str = "rest", request_type=service.GetCommentRequest +def test_create_comment_rest_bad_request( + transport: str = "rest", request_type=service.CreateCommentRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23477,9 +24304,7 @@ def test_get_comment_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = { - "name": "projects/sample1/locations/sample2/orders/sample3/comments/sample4" - } + request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -23491,10 +24316,10 @@ def test_get_comment_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_comment(request) + client.create_comment(request) -def test_get_comment_rest_flattened(): +def test_create_comment_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -23503,42 +24328,40 @@ def test_get_comment_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = resources.Comment() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/orders/sample3/comments/sample4" - } + sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + comment=resources.Comment(name="name_value"), + comment_id="comment_id_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - # Convert return value to protobuf type - return_value = resources.Comment.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.get_comment(**mock_args) + client.create_comment(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{name=projects/*/locations/*/orders/*/comments/*}" + "%s/v1alpha/{parent=projects/*/locations/*/orders/*}/comments" % client.transport._host, args[1], ) -def test_get_comment_rest_flattened_error(transport: str = "rest"): +def test_create_comment_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -23547,13 +24370,15 @@ def test_get_comment_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_comment( - service.GetCommentRequest(), - name="name_value", + client.create_comment( + service.CreateCommentRequest(), + parent="parent_value", + comment=resources.Comment(name="name_value"), + comment_id="comment_id_value", ) -def test_get_comment_rest_error(): +def test_create_comment_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -23562,113 +24387,52 @@ def test_get_comment_rest_error(): @pytest.mark.parametrize( "request_type", [ - service.CreateCommentRequest, + service.RecordActionOnCommentRequest, dict, ], ) -def test_create_comment_rest(request_type): +def test_record_action_on_comment_rest(request_type): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} - request_init["comment"] = { - "name": "name_value", - "create_time": {"seconds": 751, "nanos": 543}, - "labels": {}, - "author": "author_value", - "text": "text_value", + request_init = { + "name": "projects/sample1/locations/sample2/orders/sample3/comments/sample4" } - # The version of a generated dependency at test runtime may differ from the version used during generation. - # Delete any fields which are not present in the current runtime dependency - # See https://github.com/googleapis/gapic-generator-python/issues/1748 - - # Determine if the message type is proto-plus or protobuf - test_field = service.CreateCommentRequest.meta.fields["comment"] - - def get_message_fields(field): - # Given a field which is a message (composite type), return a list with - # all the fields of the message. - # If the field is not a composite type, return an empty list. - message_fields = [] - - if hasattr(field, "message") and field.message: - is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - - if is_field_type_proto_plus_type: - message_fields = field.message.meta.fields.values() - # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER - message_fields = field.message.DESCRIPTOR.fields - return message_fields - - runtime_nested_fields = [ - (field.name, nested_field.name) - for field in get_message_fields(test_field) - for nested_field in get_message_fields(field) - ] - - subfields_not_in_runtime = [] - - # For each item in the sample request, create a list of sub fields which are not present at runtime - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["comment"].items(): # pragma: NO COVER - result = None - is_repeated = False - # For repeated fields - if isinstance(value, list) and len(value): - is_repeated = True - result = value[0] - # For fields where the type is another message - if isinstance(value, dict): - result = value - - if result and hasattr(result, "keys"): - for subfield in result.keys(): - if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - { - "field": field, - "subfield": subfield, - "is_repeated": is_repeated, - } - ) - - # Remove fields from the sample request which are not present in the runtime version of the dependency - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER - field = subfield_to_delete.get("field") - field_repeated = subfield_to_delete.get("is_repeated") - subfield = subfield_to_delete.get("subfield") - if subfield: - if field_repeated: - for i in range(0, len(request_init["comment"][field])): - del request_init["comment"][field][i][subfield] - else: - del request_init["comment"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = resources.Comment( + name="name_value", + author="author_value", + text="text_value", + author_entity=resources.Entity.GOOGLE, + ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = resources.Comment.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_comment(request) + response = client.record_action_on_comment(request) # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" + assert isinstance(response, resources.Comment) + assert response.name == "name_value" + assert response.author == "author_value" + assert response.text == "text_value" + assert response.author_entity == resources.Entity.GOOGLE -def test_create_comment_rest_use_cached_wrapped_rpc(): +def test_record_action_on_comment_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -23682,37 +24446,40 @@ def test_create_comment_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_comment in client._transport._wrapped_methods + assert ( + client._transport.record_action_on_comment + in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_comment] = mock_rpc + client._transport._wrapped_methods[ + client._transport.record_action_on_comment + ] = mock_rpc request = {} - client.create_comment(request) + client.record_action_on_comment(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - # Operation methods build a cached wrapper on first rpc call - # subsequent calls should use the cached wrapper - wrapper_fn.reset_mock() - - client.create_comment(request) + client.record_action_on_comment(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_comment_rest_required_fields(request_type=service.CreateCommentRequest): +def test_record_action_on_comment_rest_required_fields( + request_type=service.RecordActionOnCommentRequest, +): transport_class = transports.GDCHardwareManagementRestTransport request_init = {} - request_init["parent"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -23723,28 +24490,21 @@ def test_create_comment_rest_required_fields(request_type=service.CreateCommentR unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_comment._get_unset_required_fields(jsonified_request) + ).record_action_on_comment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_comment._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "comment_id", - "request_id", - ) - ) + ).record_action_on_comment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23753,7 +24513,7 @@ def test_create_comment_rest_required_fields(request_type=service.CreateCommentR request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = resources.Comment() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -23773,42 +24533,40 @@ def test_create_comment_rest_required_fields(request_type=service.CreateCommentR response_value = Response() response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = resources.Comment.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_comment(request) + response = client.record_action_on_comment(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_comment_rest_unset_required_fields(): +def test_record_action_on_comment_rest_unset_required_fields(): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_comment._get_unset_required_fields({}) + unset_fields = transport.record_action_on_comment._get_unset_required_fields({}) assert set(unset_fields) == ( - set( - ( - "commentId", - "requestId", - ) - ) + set(()) & set( ( - "parent", - "comment", + "name", + "actionType", ) ) ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_comment_rest_interceptors(null_interceptor): +def test_record_action_on_comment_rest_interceptors(null_interceptor): transport = transports.GDCHardwareManagementRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -23821,15 +24579,15 @@ def test_create_comment_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_comment" + transports.GDCHardwareManagementRestInterceptor, "post_record_action_on_comment" ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_comment" + transports.GDCHardwareManagementRestInterceptor, "pre_record_action_on_comment" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = service.CreateCommentRequest.pb(service.CreateCommentRequest()) + pb_message = service.RecordActionOnCommentRequest.pb( + service.RecordActionOnCommentRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -23840,19 +24598,17 @@ def test_create_comment_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson( - operations_pb2.Operation() - ) + req.return_value._content = resources.Comment.to_json(resources.Comment()) - request = service.CreateCommentRequest() + request = service.RecordActionOnCommentRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() + post.return_value = resources.Comment() - client.create_comment( + client.record_action_on_comment( request, metadata=[ ("key", "val"), @@ -23864,8 +24620,8 @@ def test_create_comment_rest_interceptors(null_interceptor): post.assert_called_once() -def test_create_comment_rest_bad_request( - transport: str = "rest", request_type=service.CreateCommentRequest +def test_record_action_on_comment_rest_bad_request( + transport: str = "rest", request_type=service.RecordActionOnCommentRequest ): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23873,7 +24629,9 @@ def test_create_comment_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/orders/sample3/comments/sample4" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -23885,10 +24643,10 @@ def test_create_comment_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.create_comment(request) + client.record_action_on_comment(request) -def test_create_comment_rest_flattened(): +def test_record_action_on_comment_rest_flattened(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -23897,40 +24655,43 @@ def test_create_comment_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = resources.Comment() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2/orders/sample3"} + sample_request = { + "name": "projects/sample1/locations/sample2/orders/sample3/comments/sample4" + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", - comment=resources.Comment(name="name_value"), - comment_id="comment_id_value", + name="name_value", + action_type=service.RecordActionOnCommentRequest.ActionType.READ, ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 + # Convert return value to protobuf type + return_value = resources.Comment.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.create_comment(**mock_args) + client.record_action_on_comment(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1alpha/{parent=projects/*/locations/*/orders/*}/comments" + "%s/v1alpha/{name=projects/*/locations/*/orders/*/comments/*}:recordAction" % client.transport._host, args[1], ) -def test_create_comment_rest_flattened_error(transport: str = "rest"): +def test_record_action_on_comment_rest_flattened_error(transport: str = "rest"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -23939,15 +24700,14 @@ def test_create_comment_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_comment( - service.CreateCommentRequest(), - parent="parent_value", - comment=resources.Comment(name="name_value"), - comment_id="comment_id_value", + client.record_action_on_comment( + service.RecordActionOnCommentRequest(), + name="name_value", + action_type=service.RecordActionOnCommentRequest.ActionType.READ, ) -def test_create_comment_rest_error(): +def test_record_action_on_comment_rest_error(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -26069,6 +26829,13 @@ def test_create_zone_rest(request_type): "kubernetes_ipv4_subnet": {}, }, "globally_unique_id": "globally_unique_id_value", + "subscription_configs": [ + { + "subscription_id": "subscription_id_value", + "billing_id": "billing_id_value", + "state": 1, + } + ], } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency @@ -26498,6 +27265,13 @@ def test_update_zone_rest(request_type): "kubernetes_ipv4_subnet": {}, }, "globally_unique_id": "globally_unique_id_value", + "subscription_configs": [ + { + "subscription_id": "subscription_id_value", + "billing_id": "billing_id_value", + "state": 1, + } + ], } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency @@ -27428,7 +28202,7 @@ def test_signal_zone_state_rest_flattened(): # get truthy value for each flattened field mock_args = dict( name="name_value", - state_signal=service.SignalZoneStateRequest.StateSignal.READY_FOR_SITE_TURNUP, + state_signal=service.SignalZoneStateRequest.StateSignal.FACTORY_TURNUP_CHECKS_PASSED, ) mock_args.update(sample_request) @@ -27464,7 +28238,7 @@ def test_signal_zone_state_rest_flattened_error(transport: str = "rest"): client.signal_zone_state( service.SignalZoneStateRequest(), name="name_value", - state_signal=service.SignalZoneStateRequest.StateSignal.READY_FOR_SITE_TURNUP, + state_signal=service.SignalZoneStateRequest.StateSignal.FACTORY_TURNUP_CHECKS_PASSED, ) @@ -27636,6 +28410,7 @@ def test_gdc_hardware_management_base_transport(): "list_comments", "get_comment", "create_comment", + "record_action_on_comment", "list_change_log_entries", "get_change_log_entry", "list_skus", @@ -28005,6 +28780,9 @@ def test_gdc_hardware_management_client_transport_session_collision(transport_na session1 = client1.transport.create_comment._session session2 = client2.transport.create_comment._session assert session1 != session2 + session1 = client1.transport.record_action_on_comment._session + session2 = client2.transport.record_action_on_comment._session + assert session1 != session2 session1 = client1.transport.list_change_log_entries._session session2 = client2.transport.list_change_log_entries._session assert session1 != session2