From 187a03605cd5d5d314c47a44dbf5227fb0af204a Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 17 Apr 2024 20:17:57 -0400 Subject: [PATCH] feat: [google-apps-chat] add UpdateMembership API (#12589) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 625805898 Source-Link: https://github.com/googleapis/googleapis/commit/c106d2f8cfecf198fddb491b926a795dd58005b2 Source-Link: https://github.com/googleapis/googleapis-gen/commit/593bb0cb6cafe7cb71c36774f26c7f5c88cbb5d9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFwcHMtY2hhdC8uT3dsQm90LnlhbWwiLCJoIjoiNTkzYmIwY2I2Y2FmZTdjYjcxYzM2Nzc0ZjI2YzdmNWM4OGNiYjVkOSJ9 --------- Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- .../google/apps/chat/__init__.py | 2 + .../google/apps/chat/gapic_version.py | 2 +- .../google/apps/chat_v1/__init__.py | 2 + .../google/apps/chat_v1/gapic_metadata.json | 15 + .../google/apps/chat_v1/gapic_version.py | 2 +- .../services/chat_service/async_client.py | 133 ++ .../chat_v1/services/chat_service/client.py | 124 ++ .../services/chat_service/transports/base.py | 23 + .../services/chat_service/transports/grpc.py | 27 + .../chat_service/transports/grpc_asyncio.py | 29 + .../services/chat_service/transports/rest.py | 140 ++ .../google/apps/chat_v1/types/__init__.py | 2 + .../google/apps/chat_v1/types/membership.py | 32 +- ...ed_chat_service_update_membership_async.py | 51 + ...ted_chat_service_update_membership_sync.py | 51 + .../snippet_metadata_google.chat.v1.json | 171 +- .../scripts/fixup_chat_v1_keywords.py | 1 + .../unit/gapic/chat_v1/test_chat_service.py | 1668 ++++++++++++----- 18 files changed, 1976 insertions(+), 499 deletions(-) create mode 100644 packages/google-apps-chat/samples/generated_samples/chat_v1_generated_chat_service_update_membership_async.py create mode 100644 packages/google-apps-chat/samples/generated_samples/chat_v1_generated_chat_service_update_membership_sync.py diff --git a/packages/google-apps-chat/google/apps/chat/__init__.py b/packages/google-apps-chat/google/apps/chat/__init__.py index 47013aaccf2c..06a3f991c7c2 100644 --- a/packages/google-apps-chat/google/apps/chat/__init__.py +++ b/packages/google-apps-chat/google/apps/chat/__init__.py @@ -51,6 +51,7 @@ ListMembershipsRequest, ListMembershipsResponse, Membership, + UpdateMembershipRequest, ) from google.apps.chat_v1.types.message import ( AccessoryWidget, @@ -123,6 +124,7 @@ "ListMembershipsRequest", "ListMembershipsResponse", "Membership", + "UpdateMembershipRequest", "AccessoryWidget", "ActionResponse", "AttachedGif", diff --git a/packages/google-apps-chat/google/apps/chat/gapic_version.py b/packages/google-apps-chat/google/apps/chat/gapic_version.py index 114e40645800..558c8aab67c5 100644 --- a/packages/google-apps-chat/google/apps/chat/gapic_version.py +++ b/packages/google-apps-chat/google/apps/chat/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.3" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-apps-chat/google/apps/chat_v1/__init__.py b/packages/google-apps-chat/google/apps/chat_v1/__init__.py index dd7857646391..7fd079e04022 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/__init__.py +++ b/packages/google-apps-chat/google/apps/chat_v1/__init__.py @@ -48,6 +48,7 @@ ListMembershipsRequest, ListMembershipsResponse, Membership, + UpdateMembershipRequest, ) from .types.message import ( AccessoryWidget, @@ -150,6 +151,7 @@ "SlashCommandMetadata", "Space", "Thread", + "UpdateMembershipRequest", "UpdateMessageRequest", "UpdateSpaceRequest", "UploadAttachmentRequest", diff --git a/packages/google-apps-chat/google/apps/chat_v1/gapic_metadata.json b/packages/google-apps-chat/google/apps/chat_v1/gapic_metadata.json index 5c89a784ee6f..a6e730534f52 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/gapic_metadata.json +++ b/packages/google-apps-chat/google/apps/chat_v1/gapic_metadata.json @@ -105,6 +105,11 @@ "set_up_space" ] }, + "UpdateMembership": { + "methods": [ + "update_membership" + ] + }, "UpdateMessage": { "methods": [ "update_message" @@ -220,6 +225,11 @@ "set_up_space" ] }, + "UpdateMembership": { + "methods": [ + "update_membership" + ] + }, "UpdateMessage": { "methods": [ "update_message" @@ -335,6 +345,11 @@ "set_up_space" ] }, + "UpdateMembership": { + "methods": [ + "update_membership" + ] + }, "UpdateMessage": { "methods": [ "update_message" diff --git a/packages/google-apps-chat/google/apps/chat_v1/gapic_version.py b/packages/google-apps-chat/google/apps/chat_v1/gapic_version.py index 114e40645800..558c8aab67c5 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/gapic_version.py +++ b/packages/google-apps-chat/google/apps/chat_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.3" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/async_client.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/async_client.py index d53f6e29063f..188238936a98 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/async_client.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/async_client.py @@ -2638,6 +2638,139 @@ async def sample_create_membership(): # Done; return the response. return response + async def update_membership( + self, + request: Optional[Union[gc_membership.UpdateMembershipRequest, dict]] = None, + *, + membership: Optional[gc_membership.Membership] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gc_membership.Membership: + r"""Updates a membership. Requires `user + authentication `__. + + .. 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.apps import chat_v1 + + async def sample_update_membership(): + # Create a client + client = chat_v1.ChatServiceAsyncClient() + + # Initialize request argument(s) + request = chat_v1.UpdateMembershipRequest( + ) + + # Make the request + response = await client.update_membership(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.apps.chat_v1.types.UpdateMembershipRequest, dict]]): + The request object. Request message for updating a + membership. + membership (:class:`google.apps.chat_v1.types.Membership`): + Required. The membership to update. Only fields + specified by ``update_mask`` are updated. + + This corresponds to the ``membership`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. The field paths to update. Separate multiple + values with commas or use ``*`` to update all field + paths. + + Currently supported field paths: + + - ``role`` + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_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.apps.chat_v1.types.Membership: + Represents a membership relation in + Google Chat, such as whether a user or + Chat app is invited to, part of, or + absent from a space. + + """ + # 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([membership, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = gc_membership.UpdateMembershipRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if membership is not None: + request.membership = membership + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_membership, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("membership.name", request.membership.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 delete_membership( self, request: Optional[Union[membership.DeleteMembershipRequest, dict]] = None, diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/client.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/client.py index dca2e903f993..a4ff5ca01940 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/client.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/client.py @@ -2987,6 +2987,130 @@ def sample_create_membership(): # Done; return the response. return response + def update_membership( + self, + request: Optional[Union[gc_membership.UpdateMembershipRequest, dict]] = None, + *, + membership: Optional[gc_membership.Membership] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gc_membership.Membership: + r"""Updates a membership. Requires `user + authentication `__. + + .. 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.apps import chat_v1 + + def sample_update_membership(): + # Create a client + client = chat_v1.ChatServiceClient() + + # Initialize request argument(s) + request = chat_v1.UpdateMembershipRequest( + ) + + # Make the request + response = client.update_membership(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.apps.chat_v1.types.UpdateMembershipRequest, dict]): + The request object. Request message for updating a + membership. + membership (google.apps.chat_v1.types.Membership): + Required. The membership to update. Only fields + specified by ``update_mask`` are updated. + + This corresponds to the ``membership`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. The field paths to update. Separate multiple + values with commas or use ``*`` to update all field + paths. + + Currently supported field paths: + + - ``role`` + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.apps.chat_v1.types.Membership: + Represents a membership relation in + Google Chat, such as whether a user or + Chat app is invited to, part of, or + absent from a space. + + """ + # 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([membership, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a gc_membership.UpdateMembershipRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, gc_membership.UpdateMembershipRequest): + request = gc_membership.UpdateMembershipRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if membership is not None: + request.membership = membership + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_membership] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("membership.name", request.membership.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 delete_membership( self, request: Optional[Union[membership.DeleteMembershipRequest, dict]] = None, diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/base.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/base.py index 18967675f0ad..c25351e30420 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/base.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/base.py @@ -404,6 +404,20 @@ def _prep_wrapped_messages(self, client_info): default_timeout=30.0, client_info=client_info, ), + self.update_membership: gapic_v1.method.wrap_method( + self.update_membership, + default_retry=retries.Retry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), self.delete_membership: gapic_v1.method.wrap_method( self.delete_membership, default_retry=retries.Retry( @@ -633,6 +647,15 @@ def create_membership( ]: raise NotImplementedError() + @property + def update_membership( + self, + ) -> Callable[ + [gc_membership.UpdateMembershipRequest], + Union[gc_membership.Membership, Awaitable[gc_membership.Membership]], + ]: + raise NotImplementedError() + @property def delete_membership( self, diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc.py index 46b78f97581e..4cee90744449 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc.py @@ -933,6 +933,33 @@ def create_membership( ) return self._stubs["create_membership"] + @property + def update_membership( + self, + ) -> Callable[[gc_membership.UpdateMembershipRequest], gc_membership.Membership]: + r"""Return a callable for the update membership method over gRPC. + + Updates a membership. Requires `user + authentication `__. + + Returns: + Callable[[~.UpdateMembershipRequest], + ~.Membership]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_membership" not in self._stubs: + self._stubs["update_membership"] = self.grpc_channel.unary_unary( + "/google.chat.v1.ChatService/UpdateMembership", + request_serializer=gc_membership.UpdateMembershipRequest.serialize, + response_deserializer=gc_membership.Membership.deserialize, + ) + return self._stubs["update_membership"] + @property def delete_membership( self, diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc_asyncio.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc_asyncio.py index d6e52e95539f..328ab4fd0e5d 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc_asyncio.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc_asyncio.py @@ -952,6 +952,35 @@ def create_membership( ) return self._stubs["create_membership"] + @property + def update_membership( + self, + ) -> Callable[ + [gc_membership.UpdateMembershipRequest], Awaitable[gc_membership.Membership] + ]: + r"""Return a callable for the update membership method over gRPC. + + Updates a membership. Requires `user + authentication `__. + + Returns: + Callable[[~.UpdateMembershipRequest], + Awaitable[~.Membership]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_membership" not in self._stubs: + self._stubs["update_membership"] = self.grpc_channel.unary_unary( + "/google.chat.v1.ChatService/UpdateMembership", + request_serializer=gc_membership.UpdateMembershipRequest.serialize, + response_deserializer=gc_membership.Membership.deserialize, + ) + return self._stubs["update_membership"] + @property def delete_membership( self, diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/rest.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/rest.py index 8ae042967e1d..7b93be5a6fbe 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/rest.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/rest.py @@ -214,6 +214,14 @@ def post_set_up_space(self, response): logging.log(f"Received response: {response}") return response + def pre_update_membership(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_membership(self, response): + logging.log(f"Received response: {response}") + return response + def pre_update_message(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -622,6 +630,29 @@ def post_set_up_space(self, response: space.Space) -> space.Space: """ return response + def pre_update_membership( + self, + request: gc_membership.UpdateMembershipRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[gc_membership.UpdateMembershipRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for update_membership + + Override in a subclass to manipulate the request or metadata + before they are sent to the ChatService server. + """ + return request, metadata + + def post_update_membership( + self, response: gc_membership.Membership + ) -> gc_membership.Membership: + """Post-rpc interceptor for update_membership + + Override in a subclass to manipulate the response + after it is returned by the ChatService server but before + it is returned to user code. + """ + return response + def pre_update_message( self, request: gc_message.UpdateMessageRequest, @@ -2450,6 +2481,107 @@ def __call__( resp = self._interceptor.post_set_up_space(resp) return resp + class _UpdateMembership(ChatServiceRestStub): + def __hash__(self): + return hash("UpdateMembership") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "updateMask": {}, + } + + @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: gc_membership.UpdateMembershipRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gc_membership.Membership: + r"""Call the update membership method over HTTP. + + Args: + request (~.gc_membership.UpdateMembershipRequest): + The request object. Request message for updating a + membership. + 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: + ~.gc_membership.Membership: + Represents a membership relation in + Google Chat, such as whether a user or + Chat app is invited to, part of, or + absent from a space. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "patch", + "uri": "/v1/{membership.name=spaces/*/members/*}", + "body": "membership", + }, + ] + request, metadata = self._interceptor.pre_update_membership( + request, metadata + ) + pb_request = gc_membership.UpdateMembershipRequest.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 = gc_membership.Membership() + pb_resp = gc_membership.Membership.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_membership(resp) + return resp + class _UpdateMessage(ChatServiceRestStub): def __hash__(self): return hash("UpdateMessage") @@ -2883,6 +3015,14 @@ def set_up_space(self) -> Callable[[space_setup.SetUpSpaceRequest], space.Space] # In C++ this would require a dynamic_cast return self._SetUpSpace(self._session, self._host, self._interceptor) # type: ignore + @property + def update_membership( + self, + ) -> Callable[[gc_membership.UpdateMembershipRequest], gc_membership.Membership]: + # 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._UpdateMembership(self._session, self._host, self._interceptor) # type: ignore + @property def update_message( self, diff --git a/packages/google-apps-chat/google/apps/chat_v1/types/__init__.py b/packages/google-apps-chat/google/apps/chat_v1/types/__init__.py index a00cfed207f5..5e7ba9e0a543 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/types/__init__.py +++ b/packages/google-apps-chat/google/apps/chat_v1/types/__init__.py @@ -42,6 +42,7 @@ ListMembershipsRequest, ListMembershipsResponse, Membership, + UpdateMembershipRequest, ) from .message import ( AccessoryWidget, @@ -112,6 +113,7 @@ "ListMembershipsRequest", "ListMembershipsResponse", "Membership", + "UpdateMembershipRequest", "AccessoryWidget", "ActionResponse", "AttachedGif", diff --git a/packages/google-apps-chat/google/apps/chat_v1/types/membership.py b/packages/google-apps-chat/google/apps/chat_v1/types/membership.py index 89c236f227d6..44bd80d92a0c 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/types/membership.py +++ b/packages/google-apps-chat/google/apps/chat_v1/types/membership.py @@ -17,6 +17,7 @@ from typing import MutableMapping, MutableSequence +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore @@ -27,6 +28,7 @@ manifest={ "Membership", "CreateMembershipRequest", + "UpdateMembershipRequest", "ListMembershipsRequest", "ListMembershipsResponse", "GetMembershipRequest", @@ -58,8 +60,6 @@ class Membership(proto.Message): Optional. User's role within a Chat space, which determines their permitted actions in the space. - `Developer - Preview `__: This field can only be used as input in ``UpdateMembership``. member (google.apps.chat_v1.types.User): @@ -223,6 +223,34 @@ class CreateMembershipRequest(proto.Message): ) +class UpdateMembershipRequest(proto.Message): + r"""Request message for updating a membership. + + Attributes: + membership (google.apps.chat_v1.types.Membership): + Required. The membership to update. Only fields specified by + ``update_mask`` are updated. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. The field paths to update. Separate multiple + values with commas or use ``*`` to update all field paths. + + Currently supported field paths: + + - ``role`` + """ + + membership: "Membership" = proto.Field( + proto.MESSAGE, + number=1, + message="Membership", + ) + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + class ListMembershipsRequest(proto.Message): r"""Request message for listing memberships. diff --git a/packages/google-apps-chat/samples/generated_samples/chat_v1_generated_chat_service_update_membership_async.py b/packages/google-apps-chat/samples/generated_samples/chat_v1_generated_chat_service_update_membership_async.py new file mode 100644 index 000000000000..99143b9d193f --- /dev/null +++ b/packages/google-apps-chat/samples/generated_samples/chat_v1_generated_chat_service_update_membership_async.py @@ -0,0 +1,51 @@ +# -*- 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 UpdateMembership +# 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-apps-chat + + +# [START chat_v1_generated_ChatService_UpdateMembership_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.apps import chat_v1 + + +async def sample_update_membership(): + # Create a client + client = chat_v1.ChatServiceAsyncClient() + + # Initialize request argument(s) + request = chat_v1.UpdateMembershipRequest( + ) + + # Make the request + response = await client.update_membership(request=request) + + # Handle the response + print(response) + +# [END chat_v1_generated_ChatService_UpdateMembership_async] diff --git a/packages/google-apps-chat/samples/generated_samples/chat_v1_generated_chat_service_update_membership_sync.py b/packages/google-apps-chat/samples/generated_samples/chat_v1_generated_chat_service_update_membership_sync.py new file mode 100644 index 000000000000..fad015860782 --- /dev/null +++ b/packages/google-apps-chat/samples/generated_samples/chat_v1_generated_chat_service_update_membership_sync.py @@ -0,0 +1,51 @@ +# -*- 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 UpdateMembership +# 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-apps-chat + + +# [START chat_v1_generated_ChatService_UpdateMembership_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.apps import chat_v1 + + +def sample_update_membership(): + # Create a client + client = chat_v1.ChatServiceClient() + + # Initialize request argument(s) + request = chat_v1.UpdateMembershipRequest( + ) + + # Make the request + response = client.update_membership(request=request) + + # Handle the response + print(response) + +# [END chat_v1_generated_ChatService_UpdateMembership_sync] diff --git a/packages/google-apps-chat/samples/generated_samples/snippet_metadata_google.chat.v1.json b/packages/google-apps-chat/samples/generated_samples/snippet_metadata_google.chat.v1.json index 9b5535795ef2..b478a2730f82 100644 --- a/packages/google-apps-chat/samples/generated_samples/snippet_metadata_google.chat.v1.json +++ b/packages/google-apps-chat/samples/generated_samples/snippet_metadata_google.chat.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-apps-chat", - "version": "0.1.3" + "version": "0.1.0" }, "snippets": [ { @@ -3052,6 +3052,175 @@ ], "title": "chat_v1_generated_chat_service_set_up_space_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.apps.chat_v1.ChatServiceAsyncClient", + "shortName": "ChatServiceAsyncClient" + }, + "fullName": "google.apps.chat_v1.ChatServiceAsyncClient.update_membership", + "method": { + "fullName": "google.chat.v1.ChatService.UpdateMembership", + "service": { + "fullName": "google.chat.v1.ChatService", + "shortName": "ChatService" + }, + "shortName": "UpdateMembership" + }, + "parameters": [ + { + "name": "request", + "type": "google.apps.chat_v1.types.UpdateMembershipRequest" + }, + { + "name": "membership", + "type": "google.apps.chat_v1.types.Membership" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.apps.chat_v1.types.Membership", + "shortName": "update_membership" + }, + "description": "Sample for UpdateMembership", + "file": "chat_v1_generated_chat_service_update_membership_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "chat_v1_generated_ChatService_UpdateMembership_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "chat_v1_generated_chat_service_update_membership_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.apps.chat_v1.ChatServiceClient", + "shortName": "ChatServiceClient" + }, + "fullName": "google.apps.chat_v1.ChatServiceClient.update_membership", + "method": { + "fullName": "google.chat.v1.ChatService.UpdateMembership", + "service": { + "fullName": "google.chat.v1.ChatService", + "shortName": "ChatService" + }, + "shortName": "UpdateMembership" + }, + "parameters": [ + { + "name": "request", + "type": "google.apps.chat_v1.types.UpdateMembershipRequest" + }, + { + "name": "membership", + "type": "google.apps.chat_v1.types.Membership" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.apps.chat_v1.types.Membership", + "shortName": "update_membership" + }, + "description": "Sample for UpdateMembership", + "file": "chat_v1_generated_chat_service_update_membership_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "chat_v1_generated_ChatService_UpdateMembership_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "chat_v1_generated_chat_service_update_membership_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/packages/google-apps-chat/scripts/fixup_chat_v1_keywords.py b/packages/google-apps-chat/scripts/fixup_chat_v1_keywords.py index 7963d0a2f846..473245802731 100644 --- a/packages/google-apps-chat/scripts/fixup_chat_v1_keywords.py +++ b/packages/google-apps-chat/scripts/fixup_chat_v1_keywords.py @@ -58,6 +58,7 @@ class chatCallTransformer(cst.CSTTransformer): 'list_reactions': ('parent', 'page_size', 'page_token', 'filter', ), 'list_spaces': ('page_size', 'page_token', 'filter', ), 'set_up_space': ('space', 'request_id', 'memberships', ), + 'update_membership': ('membership', 'update_mask', ), 'update_message': ('message', 'update_mask', 'allow_missing', ), 'update_space': ('space', 'update_mask', ), 'upload_attachment': ('parent', 'filename', ), diff --git a/packages/google-apps-chat/tests/unit/gapic/chat_v1/test_chat_service.py b/packages/google-apps-chat/tests/unit/gapic/chat_v1/test_chat_service.py index 14a4570e77cf..b5d99bfdb24d 100644 --- a/packages/google-apps-chat/tests/unit/gapic/chat_v1/test_chat_service.py +++ b/packages/google-apps-chat/tests/unit/gapic/chat_v1/test_chat_service.py @@ -6575,11 +6575,11 @@ async def test_create_membership_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - membership.DeleteMembershipRequest, + gc_membership.UpdateMembershipRequest, dict, ], ) -def test_delete_membership(request_type, transport: str = "grpc"): +def test_update_membership(request_type, transport: str = "grpc"): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -6591,30 +6591,30 @@ def test_delete_membership(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_membership), "__call__" + type(client.transport.update_membership), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = membership.Membership( + call.return_value = gc_membership.Membership( name="name_value", - state=membership.Membership.MembershipState.JOINED, - role=membership.Membership.MembershipRole.ROLE_MEMBER, + state=gc_membership.Membership.MembershipState.JOINED, + role=gc_membership.Membership.MembershipRole.ROLE_MEMBER, ) - response = client.delete_membership(request) + response = client.update_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = membership.DeleteMembershipRequest() + request = gc_membership.UpdateMembershipRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, membership.Membership) + assert isinstance(response, gc_membership.Membership) assert response.name == "name_value" - assert response.state == membership.Membership.MembershipState.JOINED - assert response.role == membership.Membership.MembershipRole.ROLE_MEMBER + assert response.state == gc_membership.Membership.MembershipState.JOINED + assert response.role == gc_membership.Membership.MembershipRole.ROLE_MEMBER -def test_delete_membership_empty_call(): +def test_update_membership_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 = ChatServiceClient( @@ -6624,15 +6624,15 @@ def test_delete_membership_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_membership), "__call__" + type(client.transport.update_membership), "__call__" ) as call: - client.delete_membership() + client.update_membership() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.DeleteMembershipRequest() + assert args[0] == gc_membership.UpdateMembershipRequest() -def test_delete_membership_non_empty_request_with_auto_populated_field(): +def test_update_membership_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 = ChatServiceClient( @@ -6643,24 +6643,20 @@ def test_delete_membership_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 = membership.DeleteMembershipRequest( - name="name_value", - ) + request = gc_membership.UpdateMembershipRequest() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_membership), "__call__" + type(client.transport.update_membership), "__call__" ) as call: - client.delete_membership(request=request) + client.update_membership(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.DeleteMembershipRequest( - name="name_value", - ) + assert args[0] == gc_membership.UpdateMembershipRequest() @pytest.mark.asyncio -async def test_delete_membership_empty_call_async(): +async def test_update_membership_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 = ChatServiceAsyncClient( @@ -6670,25 +6666,25 @@ async def test_delete_membership_empty_call_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_membership), "__call__" + type(client.transport.update_membership), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - membership.Membership( + gc_membership.Membership( name="name_value", - state=membership.Membership.MembershipState.JOINED, - role=membership.Membership.MembershipRole.ROLE_MEMBER, + state=gc_membership.Membership.MembershipState.JOINED, + role=gc_membership.Membership.MembershipRole.ROLE_MEMBER, ) ) - response = await client.delete_membership() + response = await client.update_membership() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == membership.DeleteMembershipRequest() + assert args[0] == gc_membership.UpdateMembershipRequest() @pytest.mark.asyncio -async def test_delete_membership_async( - transport: str = "grpc_asyncio", request_type=membership.DeleteMembershipRequest +async def test_update_membership_async( + transport: str = "grpc_asyncio", request_type=gc_membership.UpdateMembershipRequest ): client = ChatServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6701,53 +6697,53 @@ async def test_delete_membership_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_membership), "__call__" + type(client.transport.update_membership), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - membership.Membership( + gc_membership.Membership( name="name_value", - state=membership.Membership.MembershipState.JOINED, - role=membership.Membership.MembershipRole.ROLE_MEMBER, + state=gc_membership.Membership.MembershipState.JOINED, + role=gc_membership.Membership.MembershipRole.ROLE_MEMBER, ) ) - response = await client.delete_membership(request) + response = await client.update_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = membership.DeleteMembershipRequest() + request = gc_membership.UpdateMembershipRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, membership.Membership) + assert isinstance(response, gc_membership.Membership) assert response.name == "name_value" - assert response.state == membership.Membership.MembershipState.JOINED - assert response.role == membership.Membership.MembershipRole.ROLE_MEMBER + assert response.state == gc_membership.Membership.MembershipState.JOINED + assert response.role == gc_membership.Membership.MembershipRole.ROLE_MEMBER @pytest.mark.asyncio -async def test_delete_membership_async_from_dict(): - await test_delete_membership_async(request_type=dict) +async def test_update_membership_async_from_dict(): + await test_update_membership_async(request_type=dict) -def test_delete_membership_field_headers(): +def test_update_membership_field_headers(): client = ChatServiceClient( 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 = membership.DeleteMembershipRequest() + request = gc_membership.UpdateMembershipRequest() - request.name = "name_value" + request.membership.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_membership), "__call__" + type(client.transport.update_membership), "__call__" ) as call: - call.return_value = membership.Membership() - client.delete_membership(request) + call.return_value = gc_membership.Membership() + client.update_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -6758,30 +6754,30 @@ def test_delete_membership_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "membership.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_delete_membership_field_headers_async(): +async def test_update_membership_field_headers_async(): client = ChatServiceAsyncClient( 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 = membership.DeleteMembershipRequest() + request = gc_membership.UpdateMembershipRequest() - request.name = "name_value" + request.membership.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_membership), "__call__" + type(client.transport.update_membership), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - membership.Membership() + gc_membership.Membership() ) - await client.delete_membership(request) + await client.update_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6792,37 +6788,41 @@ async def test_delete_membership_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "membership.name=name_value", ) in kw["metadata"] -def test_delete_membership_flattened(): +def test_update_membership_flattened(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_membership), "__call__" + type(client.transport.update_membership), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = membership.Membership() + call.return_value = gc_membership.Membership() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_membership( - name="name_value", + client.update_membership( + membership=gc_membership.Membership(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].membership + mock_val = gc_membership.Membership(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_membership_flattened_error(): +def test_update_membership_flattened_error(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6830,45 +6830,50 @@ def test_delete_membership_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_membership( - membership.DeleteMembershipRequest(), - name="name_value", + client.update_membership( + gc_membership.UpdateMembershipRequest(), + membership=gc_membership.Membership(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_delete_membership_flattened_async(): +async def test_update_membership_flattened_async(): client = ChatServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_membership), "__call__" + type(client.transport.update_membership), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = membership.Membership() + call.return_value = gc_membership.Membership() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - membership.Membership() + gc_membership.Membership() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_membership( - name="name_value", + response = await client.update_membership( + membership=gc_membership.Membership(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].membership + mock_val = gc_membership.Membership(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_membership_flattened_error_async(): +async def test_update_membership_flattened_error_async(): client = ChatServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6876,20 +6881,21 @@ async def test_delete_membership_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_membership( - membership.DeleteMembershipRequest(), - name="name_value", + await client.update_membership( + gc_membership.UpdateMembershipRequest(), + membership=gc_membership.Membership(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.parametrize( "request_type", [ - gc_reaction.CreateReactionRequest, + membership.DeleteMembershipRequest, dict, ], ) -def test_create_reaction(request_type, transport: str = "grpc"): +def test_delete_membership(request_type, transport: str = "grpc"): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -6900,25 +6906,31 @@ def test_create_reaction(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_reaction), "__call__") as call: + with mock.patch.object( + type(client.transport.delete_membership), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gc_reaction.Reaction( + call.return_value = membership.Membership( name="name_value", + state=membership.Membership.MembershipState.JOINED, + role=membership.Membership.MembershipRole.ROLE_MEMBER, ) - response = client.create_reaction(request) + response = client.delete_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = gc_reaction.CreateReactionRequest() + request = membership.DeleteMembershipRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, gc_reaction.Reaction) + assert isinstance(response, membership.Membership) assert response.name == "name_value" + assert response.state == membership.Membership.MembershipState.JOINED + assert response.role == membership.Membership.MembershipRole.ROLE_MEMBER -def test_create_reaction_empty_call(): +def test_delete_membership_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 = ChatServiceClient( @@ -6927,14 +6939,16 @@ def test_create_reaction_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: - client.create_reaction() + with mock.patch.object( + type(client.transport.delete_membership), "__call__" + ) as call: + client.delete_membership() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == gc_reaction.CreateReactionRequest() + assert args[0] == membership.DeleteMembershipRequest() -def test_create_reaction_non_empty_request_with_auto_populated_field(): +def test_delete_membership_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 = ChatServiceClient( @@ -6945,22 +6959,24 @@ def test_create_reaction_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 = gc_reaction.CreateReactionRequest( - parent="parent_value", + request = membership.DeleteMembershipRequest( + name="name_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: - client.create_reaction(request=request) + with mock.patch.object( + type(client.transport.delete_membership), "__call__" + ) as call: + client.delete_membership(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == gc_reaction.CreateReactionRequest( - parent="parent_value", + assert args[0] == membership.DeleteMembershipRequest( + name="name_value", ) @pytest.mark.asyncio -async def test_create_reaction_empty_call_async(): +async def test_delete_membership_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 = ChatServiceAsyncClient( @@ -6969,22 +6985,26 @@ async def test_create_reaction_empty_call_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: + with mock.patch.object( + type(client.transport.delete_membership), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gc_reaction.Reaction( + membership.Membership( name="name_value", + state=membership.Membership.MembershipState.JOINED, + role=membership.Membership.MembershipRole.ROLE_MEMBER, ) ) - response = await client.create_reaction() + response = await client.delete_membership() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == gc_reaction.CreateReactionRequest() + assert args[0] == membership.DeleteMembershipRequest() @pytest.mark.asyncio -async def test_create_reaction_async( - transport: str = "grpc_asyncio", request_type=gc_reaction.CreateReactionRequest +async def test_delete_membership_async( + transport: str = "grpc_asyncio", request_type=membership.DeleteMembershipRequest ): client = ChatServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6996,46 +7016,54 @@ async def test_create_reaction_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: + with mock.patch.object( + type(client.transport.delete_membership), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gc_reaction.Reaction( + membership.Membership( name="name_value", + state=membership.Membership.MembershipState.JOINED, + role=membership.Membership.MembershipRole.ROLE_MEMBER, ) ) - response = await client.create_reaction(request) + response = await client.delete_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = gc_reaction.CreateReactionRequest() + request = membership.DeleteMembershipRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, gc_reaction.Reaction) + assert isinstance(response, membership.Membership) assert response.name == "name_value" + assert response.state == membership.Membership.MembershipState.JOINED + assert response.role == membership.Membership.MembershipRole.ROLE_MEMBER @pytest.mark.asyncio -async def test_create_reaction_async_from_dict(): - await test_create_reaction_async(request_type=dict) +async def test_delete_membership_async_from_dict(): + await test_delete_membership_async(request_type=dict) -def test_create_reaction_field_headers(): +def test_delete_membership_field_headers(): client = ChatServiceClient( 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 = gc_reaction.CreateReactionRequest() + request = membership.DeleteMembershipRequest() - 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_reaction), "__call__") as call: - call.return_value = gc_reaction.Reaction() - client.create_reaction(request) + with mock.patch.object( + type(client.transport.delete_membership), "__call__" + ) as call: + call.return_value = membership.Membership() + client.delete_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -7046,28 +7074,30 @@ def test_create_reaction_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_reaction_field_headers_async(): +async def test_delete_membership_field_headers_async(): client = ChatServiceAsyncClient( 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 = gc_reaction.CreateReactionRequest() + request = membership.DeleteMembershipRequest() - 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_reaction), "__call__") as call: + with mock.patch.object( + type(client.transport.delete_membership), "__call__" + ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gc_reaction.Reaction() + membership.Membership() ) - await client.create_reaction(request) + await client.delete_membership(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -7078,39 +7108,37 @@ async def test_create_reaction_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_reaction_flattened(): +def test_delete_membership_flattened(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: + with mock.patch.object( + type(client.transport.delete_membership), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gc_reaction.Reaction() + call.return_value = membership.Membership() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.create_reaction( - parent="parent_value", - reaction=gc_reaction.Reaction(name="name_value"), + client.delete_membership( + 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].reaction - mock_val = gc_reaction.Reaction(name="name_value") + arg = args[0].name + mock_val = "name_value" assert arg == mock_val -def test_create_reaction_flattened_error(): +def test_delete_membership_flattened_error(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7118,48 +7146,45 @@ def test_create_reaction_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_reaction( - gc_reaction.CreateReactionRequest(), - parent="parent_value", - reaction=gc_reaction.Reaction(name="name_value"), + client.delete_membership( + membership.DeleteMembershipRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_create_reaction_flattened_async(): +async def test_delete_membership_flattened_async(): client = ChatServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: + with mock.patch.object( + type(client.transport.delete_membership), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gc_reaction.Reaction() + call.return_value = membership.Membership() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gc_reaction.Reaction() + membership.Membership() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.create_reaction( - parent="parent_value", - reaction=gc_reaction.Reaction(name="name_value"), + response = await client.delete_membership( + 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].reaction - mock_val = gc_reaction.Reaction(name="name_value") + arg = args[0].name + mock_val = "name_value" assert arg == mock_val @pytest.mark.asyncio -async def test_create_reaction_flattened_error_async(): +async def test_delete_membership_flattened_error_async(): client = ChatServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7167,21 +7192,20 @@ async def test_create_reaction_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_reaction( - gc_reaction.CreateReactionRequest(), - parent="parent_value", - reaction=gc_reaction.Reaction(name="name_value"), + await client.delete_membership( + membership.DeleteMembershipRequest(), + name="name_value", ) @pytest.mark.parametrize( "request_type", [ - reaction.ListReactionsRequest, + gc_reaction.CreateReactionRequest, dict, ], ) -def test_list_reactions(request_type, transport: str = "grpc"): +def test_create_reaction(request_type, transport: str = "grpc"): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -7192,25 +7216,25 @@ def test_list_reactions(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.list_reactions), "__call__") as call: + with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = reaction.ListReactionsResponse( - next_page_token="next_page_token_value", + call.return_value = gc_reaction.Reaction( + name="name_value", ) - response = client.list_reactions(request) + response = client.create_reaction(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = reaction.ListReactionsRequest() + request = gc_reaction.CreateReactionRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListReactionsPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, gc_reaction.Reaction) + assert response.name == "name_value" -def test_list_reactions_empty_call(): +def test_create_reaction_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 = ChatServiceClient( @@ -7219,14 +7243,14 @@ def test_list_reactions_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: - client.list_reactions() + with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: + client.create_reaction() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == reaction.ListReactionsRequest() + assert args[0] == gc_reaction.CreateReactionRequest() -def test_list_reactions_non_empty_request_with_auto_populated_field(): +def test_create_reaction_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 = ChatServiceClient( @@ -7237,26 +7261,22 @@ def test_list_reactions_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 = reaction.ListReactionsRequest( + request = gc_reaction.CreateReactionRequest( parent="parent_value", - page_token="page_token_value", - filter="filter_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: - client.list_reactions(request=request) + with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: + client.create_reaction(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == reaction.ListReactionsRequest( + assert args[0] == gc_reaction.CreateReactionRequest( parent="parent_value", - page_token="page_token_value", - filter="filter_value", ) @pytest.mark.asyncio -async def test_list_reactions_empty_call_async(): +async def test_create_reaction_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 = ChatServiceAsyncClient( @@ -7265,22 +7285,22 @@ async def test_list_reactions_empty_call_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - reaction.ListReactionsResponse( - next_page_token="next_page_token_value", + gc_reaction.Reaction( + name="name_value", ) ) - response = await client.list_reactions() + response = await client.create_reaction() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == reaction.ListReactionsRequest() + assert args[0] == gc_reaction.CreateReactionRequest() @pytest.mark.asyncio -async def test_list_reactions_async( - transport: str = "grpc_asyncio", request_type=reaction.ListReactionsRequest +async def test_create_reaction_async( + transport: str = "grpc_asyncio", request_type=gc_reaction.CreateReactionRequest ): client = ChatServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7292,46 +7312,46 @@ async def test_list_reactions_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - reaction.ListReactionsResponse( - next_page_token="next_page_token_value", + gc_reaction.Reaction( + name="name_value", ) ) - response = await client.list_reactions(request) + response = await client.create_reaction(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = reaction.ListReactionsRequest() + request = gc_reaction.CreateReactionRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListReactionsAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, gc_reaction.Reaction) + assert response.name == "name_value" @pytest.mark.asyncio -async def test_list_reactions_async_from_dict(): - await test_list_reactions_async(request_type=dict) +async def test_create_reaction_async_from_dict(): + await test_create_reaction_async(request_type=dict) -def test_list_reactions_field_headers(): +def test_create_reaction_field_headers(): client = ChatServiceClient( 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 = reaction.ListReactionsRequest() + request = gc_reaction.CreateReactionRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: - call.return_value = reaction.ListReactionsResponse() - client.list_reactions(request) + with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: + call.return_value = gc_reaction.Reaction() + client.create_reaction(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -7347,23 +7367,23 @@ def test_list_reactions_field_headers(): @pytest.mark.asyncio -async def test_list_reactions_field_headers_async(): +async def test_create_reaction_field_headers_async(): client = ChatServiceAsyncClient( 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 = reaction.ListReactionsRequest() + request = gc_reaction.CreateReactionRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - reaction.ListReactionsResponse() + gc_reaction.Reaction() ) - await client.list_reactions(request) + await client.create_reaction(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -7378,19 +7398,20 @@ async def test_list_reactions_field_headers_async(): ) in kw["metadata"] -def test_list_reactions_flattened(): +def test_create_reaction_flattened(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = reaction.ListReactionsResponse() + call.return_value = gc_reaction.Reaction() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_reactions( + client.create_reaction( parent="parent_value", + reaction=gc_reaction.Reaction(name="name_value"), ) # Establish that the underlying call was made with the expected @@ -7400,9 +7421,12 @@ def test_list_reactions_flattened(): arg = args[0].parent mock_val = "parent_value" assert arg == mock_val + arg = args[0].reaction + mock_val = gc_reaction.Reaction(name="name_value") + assert arg == mock_val -def test_list_reactions_flattened_error(): +def test_create_reaction_flattened_error(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7410,30 +7434,32 @@ def test_list_reactions_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_reactions( - reaction.ListReactionsRequest(), + client.create_reaction( + gc_reaction.CreateReactionRequest(), parent="parent_value", + reaction=gc_reaction.Reaction(name="name_value"), ) @pytest.mark.asyncio -async def test_list_reactions_flattened_async(): +async def test_create_reaction_flattened_async(): client = ChatServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + with mock.patch.object(type(client.transport.create_reaction), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = reaction.ListReactionsResponse() + call.return_value = gc_reaction.Reaction() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - reaction.ListReactionsResponse() + gc_reaction.Reaction() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_reactions( + response = await client.create_reaction( parent="parent_value", + reaction=gc_reaction.Reaction(name="name_value"), ) # Establish that the underlying call was made with the expected @@ -7443,10 +7469,13 @@ async def test_list_reactions_flattened_async(): arg = args[0].parent mock_val = "parent_value" assert arg == mock_val + arg = args[0].reaction + mock_val = gc_reaction.Reaction(name="name_value") + assert arg == mock_val @pytest.mark.asyncio -async def test_list_reactions_flattened_error_async(): +async def test_create_reaction_flattened_error_async(): client = ChatServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7454,83 +7483,370 @@ async def test_list_reactions_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_reactions( - reaction.ListReactionsRequest(), + await client.create_reaction( + gc_reaction.CreateReactionRequest(), parent="parent_value", + reaction=gc_reaction.Reaction(name="name_value"), ) -def test_list_reactions_pager(transport_name: str = "grpc"): +@pytest.mark.parametrize( + "request_type", + [ + reaction.ListReactionsRequest, + dict, + ], +) +def test_list_reactions(request_type, transport: str = "grpc"): client = ChatServiceClient( 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_reactions), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - reaction.ListReactionsResponse( - reactions=[ - reaction.Reaction(), - reaction.Reaction(), - reaction.Reaction(), - ], - next_page_token="abc", - ), - reaction.ListReactionsResponse( - reactions=[], - next_page_token="def", - ), - reaction.ListReactionsResponse( - reactions=[ - reaction.Reaction(), - ], - next_page_token="ghi", - ), - reaction.ListReactionsResponse( - reactions=[ - reaction.Reaction(), - reaction.Reaction(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Designate an appropriate return value for the call. + call.return_value = reaction.ListReactionsResponse( + next_page_token="next_page_token_value", ) - pager = client.list_reactions(request={}) + response = client.list_reactions(request) - assert pager._metadata == metadata + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = reaction.ListReactionsRequest() + assert args[0] == request - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, reaction.Reaction) for i in results) + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReactionsPager) + assert response.next_page_token == "next_page_token_value" -def test_list_reactions_pages(transport_name: str = "grpc"): +def test_list_reactions_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 = ChatServiceClient( 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_reactions), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - reaction.ListReactionsResponse( - reactions=[ - reaction.Reaction(), - reaction.Reaction(), - reaction.Reaction(), - ], - next_page_token="abc", - ), - reaction.ListReactionsResponse( - reactions=[], - next_page_token="def", + client.list_reactions() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == reaction.ListReactionsRequest() + + +def test_list_reactions_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 = ChatServiceClient( + 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 = reaction.ListReactionsRequest( + parent="parent_value", + page_token="page_token_value", + filter="filter_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + client.list_reactions(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == reaction.ListReactionsRequest( + parent="parent_value", + page_token="page_token_value", + filter="filter_value", + ) + + +@pytest.mark.asyncio +async def test_list_reactions_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 = ChatServiceAsyncClient( + 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_reactions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + reaction.ListReactionsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_reactions() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == reaction.ListReactionsRequest() + + +@pytest.mark.asyncio +async def test_list_reactions_async( + transport: str = "grpc_asyncio", request_type=reaction.ListReactionsRequest +): + client = ChatServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + reaction.ListReactionsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_reactions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = reaction.ListReactionsRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReactionsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_reactions_async_from_dict(): + await test_list_reactions_async(request_type=dict) + + +def test_list_reactions_field_headers(): + client = ChatServiceClient( + 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 = reaction.ListReactionsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + call.return_value = reaction.ListReactionsResponse() + client.list_reactions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_reactions_field_headers_async(): + client = ChatServiceAsyncClient( + 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 = reaction.ListReactionsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + reaction.ListReactionsResponse() + ) + await client.list_reactions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_reactions_flattened(): + client = ChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = reaction.ListReactionsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_reactions( + 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].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_reactions_flattened_error(): + client = ChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_reactions( + reaction.ListReactionsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_reactions_flattened_async(): + client = ChatServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_reactions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = reaction.ListReactionsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + reaction.ListReactionsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_reactions( + 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].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_reactions_flattened_error_async(): + client = ChatServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_reactions( + reaction.ListReactionsRequest(), + parent="parent_value", + ) + + +def test_list_reactions_pager(transport_name: str = "grpc"): + client = ChatServiceClient( + 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_reactions), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + reaction.ListReactionsResponse( + reactions=[ + reaction.Reaction(), + reaction.Reaction(), + reaction.Reaction(), + ], + next_page_token="abc", + ), + reaction.ListReactionsResponse( + reactions=[], + next_page_token="def", + ), + reaction.ListReactionsResponse( + reactions=[ + reaction.Reaction(), + ], + next_page_token="ghi", + ), + reaction.ListReactionsResponse( + reactions=[ + reaction.Reaction(), + reaction.Reaction(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_reactions(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, reaction.Reaction) for i in results) + + +def test_list_reactions_pages(transport_name: str = "grpc"): + client = ChatServiceClient( + 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_reactions), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + reaction.ListReactionsResponse( + reactions=[ + reaction.Reaction(), + reaction.Reaction(), + reaction.Reaction(), + ], + next_page_token="abc", + ), + reaction.ListReactionsResponse( + reactions=[], + next_page_token="def", ), reaction.ListReactionsResponse( reactions=[ @@ -12826,29 +13142,280 @@ def test_delete_space_rest_required_fields(request_type=space.DeleteSpaceRequest response_value = Response() response_value.status_code = 200 - json_return_value = "" + json_return_value = "" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.delete_space(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_delete_space_rest_unset_required_fields(): + transport = transports.ChatServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_space._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_space_rest_interceptors(null_interceptor): + transport = transports.ChatServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.ChatServiceRestInterceptor(), + ) + client = ChatServiceClient(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.ChatServiceRestInterceptor, "pre_delete_space" + ) as pre: + pre.assert_not_called() + pb_message = space.DeleteSpaceRequest.pb(space.DeleteSpaceRequest()) + 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() + + request = space.DeleteSpaceRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.delete_space( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + + +def test_delete_space_rest_bad_request( + transport: str = "rest", request_type=space.DeleteSpaceRequest +): + client = ChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"name": "spaces/sample1"} + 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.delete_space(request) + + +def test_delete_space_rest_flattened(): + client = ChatServiceClient( + 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 = None + + # get arguments that satisfy an http rule for this method + sample_request = {"name": "spaces/sample1"} + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.delete_space(**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/v1/{name=spaces/*}" % client.transport._host, args[1] + ) + + +def test_delete_space_rest_flattened_error(transport: str = "rest"): + client = ChatServiceClient( + 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.delete_space( + space.DeleteSpaceRequest(), + name="name_value", + ) + + +def test_delete_space_rest_error(): + client = ChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + space.CompleteImportSpaceRequest, + dict, + ], +) +def test_complete_import_space_rest(request_type): + client = ChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"name": "spaces/sample1"} + 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 = space.CompleteImportSpaceResponse() + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = space.CompleteImportSpaceResponse.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.complete_import_space(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, space.CompleteImportSpaceResponse) + + +def test_complete_import_space_rest_required_fields( + request_type=space.CompleteImportSpaceRequest, +): + transport_class = transports.ChatServiceRestTransport + + request_init = {} + request_init["name"] = "" + 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() + ).complete_import_space._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() + ).complete_import_space._get_unset_required_fields(jsonified_request) + 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 = ChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = space.CompleteImportSpaceResponse() + # 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": "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 = space.CompleteImportSpaceResponse.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_space(request) + response = client.complete_import_space(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_delete_space_rest_unset_required_fields(): +def test_complete_import_space_rest_unset_required_fields(): transport = transports.ChatServiceRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_space._get_unset_required_fields({}) + unset_fields = transport.complete_import_space._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_space_rest_interceptors(null_interceptor): +def test_complete_import_space_rest_interceptors(null_interceptor): transport = transports.ChatServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -12861,10 +13428,15 @@ def test_delete_space_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_delete_space" + transports.ChatServiceRestInterceptor, "post_complete_import_space" + ) as post, mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_complete_import_space" ) as pre: pre.assert_not_called() - pb_message = space.DeleteSpaceRequest.pb(space.DeleteSpaceRequest()) + post.assert_not_called() + pb_message = space.CompleteImportSpaceRequest.pb( + space.CompleteImportSpaceRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -12875,15 +13447,19 @@ def test_delete_space_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() + req.return_value._content = space.CompleteImportSpaceResponse.to_json( + space.CompleteImportSpaceResponse() + ) - request = space.DeleteSpaceRequest() + request = space.CompleteImportSpaceRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata + post.return_value = space.CompleteImportSpaceResponse() - client.delete_space( + client.complete_import_space( request, metadata=[ ("key", "val"), @@ -12892,10 +13468,11 @@ def test_delete_space_rest_interceptors(null_interceptor): ) pre.assert_called_once() + post.assert_called_once() -def test_delete_space_rest_bad_request( - transport: str = "rest", request_type=space.DeleteSpaceRequest +def test_complete_import_space_rest_bad_request( + transport: str = "rest", request_type=space.CompleteImportSpaceRequest ): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12915,63 +13492,10 @@ def test_delete_space_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.delete_space(request) - - -def test_delete_space_rest_flattened(): - client = ChatServiceClient( - 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 = None - - # get arguments that satisfy an http rule for this method - sample_request = {"name": "spaces/sample1"} - - # get truthy value for each flattened field - mock_args = dict( - name="name_value", - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = "" - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - - client.delete_space(**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/v1/{name=spaces/*}" % client.transport._host, args[1] - ) - - -def test_delete_space_rest_flattened_error(transport: str = "rest"): - client = ChatServiceClient( - 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.delete_space( - space.DeleteSpaceRequest(), - name="name_value", - ) + client.complete_import_space(request) -def test_delete_space_rest_error(): +def test_complete_import_space_rest_error(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -12980,42 +13504,68 @@ def test_delete_space_rest_error(): @pytest.mark.parametrize( "request_type", [ - space.CompleteImportSpaceRequest, + space.FindDirectMessageRequest, dict, ], ) -def test_complete_import_space_rest(request_type): +def test_find_direct_message_rest(request_type): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "spaces/sample1"} + request_init = {} 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 = space.CompleteImportSpaceResponse() + return_value = space.Space( + name="name_value", + type_=space.Space.Type.ROOM, + space_type=space.Space.SpaceType.SPACE, + single_user_bot_dm=True, + threaded=True, + display_name="display_name_value", + external_user_allowed=True, + space_threading_state=space.Space.SpaceThreadingState.THREADED_MESSAGES, + space_history_state=history_state.HistoryState.HISTORY_OFF, + import_mode=True, + admin_installed=True, + ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = space.CompleteImportSpaceResponse.pb(return_value) + return_value = space.Space.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.complete_import_space(request) + response = client.find_direct_message(request) # Establish that the response is the type that we expect. - assert isinstance(response, space.CompleteImportSpaceResponse) + assert isinstance(response, space.Space) + assert response.name == "name_value" + assert response.type_ == space.Space.Type.ROOM + assert response.space_type == space.Space.SpaceType.SPACE + assert response.single_user_bot_dm is True + assert response.threaded is True + assert response.display_name == "display_name_value" + assert response.external_user_allowed is True + assert ( + response.space_threading_state + == space.Space.SpaceThreadingState.THREADED_MESSAGES + ) + assert response.space_history_state == history_state.HistoryState.HISTORY_OFF + assert response.import_mode is True + assert response.admin_installed is True -def test_complete_import_space_rest_required_fields( - request_type=space.CompleteImportSpaceRequest, +def test_find_direct_message_rest_required_fields( + request_type=space.FindDirectMessageRequest, ): transport_class = transports.ChatServiceRestTransport @@ -13028,19 +13578,24 @@ def test_complete_import_space_rest_required_fields( ) # verify fields with default values are dropped + assert "name" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).complete_import_space._get_unset_required_fields(jsonified_request) + ).find_direct_message._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + assert "name" in jsonified_request + assert jsonified_request["name"] == request_init["name"] jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).complete_import_space._get_unset_required_fields(jsonified_request) + ).find_direct_message._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("name",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -13054,7 +13609,7 @@ def test_complete_import_space_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = space.CompleteImportSpaceResponse() + return_value = space.Space() # 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 @@ -13066,40 +13621,45 @@ def test_complete_import_space_rest_required_fields( 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 = space.CompleteImportSpaceResponse.pb(return_value) + return_value = space.Space.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.complete_import_space(request) + response = client.find_direct_message(request) - expected_params = [("$alt", "json;enum-encoding=int")] + expected_params = [ + ( + "name", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_complete_import_space_rest_unset_required_fields(): +def test_find_direct_message_rest_unset_required_fields(): transport = transports.ChatServiceRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.complete_import_space._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.find_direct_message._get_unset_required_fields({}) + assert set(unset_fields) == (set(("name",)) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_complete_import_space_rest_interceptors(null_interceptor): +def test_find_direct_message_rest_interceptors(null_interceptor): transport = transports.ChatServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -13112,15 +13672,13 @@ def test_complete_import_space_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_complete_import_space" + transports.ChatServiceRestInterceptor, "post_find_direct_message" ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_complete_import_space" + transports.ChatServiceRestInterceptor, "pre_find_direct_message" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = space.CompleteImportSpaceRequest.pb( - space.CompleteImportSpaceRequest() - ) + pb_message = space.FindDirectMessageRequest.pb(space.FindDirectMessageRequest()) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -13131,19 +13689,17 @@ def test_complete_import_space_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = space.CompleteImportSpaceResponse.to_json( - space.CompleteImportSpaceResponse() - ) + req.return_value._content = space.Space.to_json(space.Space()) - request = space.CompleteImportSpaceRequest() + request = space.FindDirectMessageRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = space.CompleteImportSpaceResponse() + post.return_value = space.Space() - client.complete_import_space( + client.find_direct_message( request, metadata=[ ("key", "val"), @@ -13155,8 +13711,8 @@ def test_complete_import_space_rest_interceptors(null_interceptor): post.assert_called_once() -def test_complete_import_space_rest_bad_request( - transport: str = "rest", request_type=space.CompleteImportSpaceRequest +def test_find_direct_message_rest_bad_request( + transport: str = "rest", request_type=space.FindDirectMessageRequest ): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13164,7 +13720,7 @@ def test_complete_import_space_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "spaces/sample1"} + request_init = {} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -13176,10 +13732,10 @@ def test_complete_import_space_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.complete_import_space(request) + client.find_direct_message(request) -def test_complete_import_space_rest_error(): +def test_find_direct_message_rest_error(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -13188,73 +13744,136 @@ def test_complete_import_space_rest_error(): @pytest.mark.parametrize( "request_type", [ - space.FindDirectMessageRequest, + gc_membership.CreateMembershipRequest, dict, ], ) -def test_find_direct_message_rest(request_type): +def test_create_membership_rest(request_type): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) - # send a request that will satisfy transcoding - request_init = {} + # send a request that will satisfy transcoding + request_init = {"parent": "spaces/sample1"} + request_init["membership"] = { + "name": "name_value", + "state": 1, + "role": 1, + "member": { + "name": "name_value", + "display_name": "display_name_value", + "domain_id": "domain_id_value", + "type_": 1, + "is_anonymous": True, + }, + "group_member": {"name": "name_value"}, + "create_time": {"seconds": 751, "nanos": 543}, + "delete_time": {}, + } + # 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 = gc_membership.CreateMembershipRequest.meta.fields["membership"] + + 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["membership"].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["membership"][field])): + del request_init["membership"][field][i][subfield] + else: + del request_init["membership"][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 = space.Space( + return_value = gc_membership.Membership( name="name_value", - type_=space.Space.Type.ROOM, - space_type=space.Space.SpaceType.SPACE, - single_user_bot_dm=True, - threaded=True, - display_name="display_name_value", - external_user_allowed=True, - space_threading_state=space.Space.SpaceThreadingState.THREADED_MESSAGES, - space_history_state=history_state.HistoryState.HISTORY_OFF, - import_mode=True, - admin_installed=True, + state=gc_membership.Membership.MembershipState.JOINED, + role=gc_membership.Membership.MembershipRole.ROLE_MEMBER, ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = space.Space.pb(return_value) + return_value = gc_membership.Membership.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.find_direct_message(request) + response = client.create_membership(request) # Establish that the response is the type that we expect. - assert isinstance(response, space.Space) + assert isinstance(response, gc_membership.Membership) assert response.name == "name_value" - assert response.type_ == space.Space.Type.ROOM - assert response.space_type == space.Space.SpaceType.SPACE - assert response.single_user_bot_dm is True - assert response.threaded is True - assert response.display_name == "display_name_value" - assert response.external_user_allowed is True - assert ( - response.space_threading_state - == space.Space.SpaceThreadingState.THREADED_MESSAGES - ) - assert response.space_history_state == history_state.HistoryState.HISTORY_OFF - assert response.import_mode is True - assert response.admin_installed is True + assert response.state == gc_membership.Membership.MembershipState.JOINED + assert response.role == gc_membership.Membership.MembershipRole.ROLE_MEMBER -def test_find_direct_message_rest_required_fields( - request_type=space.FindDirectMessageRequest, +def test_create_membership_rest_required_fields( + request_type=gc_membership.CreateMembershipRequest, ): transport_class = transports.ChatServiceRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -13262,29 +13881,24 @@ def test_find_direct_message_rest_required_fields( ) # verify fields with default values are dropped - assert "name" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).find_direct_message._get_unset_required_fields(jsonified_request) + ).create_membership._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "name" in jsonified_request - assert jsonified_request["name"] == request_init["name"] - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).find_direct_message._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("name",)) + ).create_membership._get_unset_required_fields(jsonified_request) 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 = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13293,7 +13907,7 @@ def test_find_direct_message_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = space.Space() + return_value = gc_membership.Membership() # 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 @@ -13305,45 +13919,48 @@ def test_find_direct_message_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 = space.Space.pb(return_value) + return_value = gc_membership.Membership.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.find_direct_message(request) + response = client.create_membership(request) - expected_params = [ - ( - "name", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_find_direct_message_rest_unset_required_fields(): +def test_create_membership_rest_unset_required_fields(): transport = transports.ChatServiceRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.find_direct_message._get_unset_required_fields({}) - assert set(unset_fields) == (set(("name",)) & set(("name",))) + unset_fields = transport.create_membership._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "membership", + ) + ) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_find_direct_message_rest_interceptors(null_interceptor): +def test_create_membership_rest_interceptors(null_interceptor): transport = transports.ChatServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -13356,13 +13973,15 @@ def test_find_direct_message_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_find_direct_message" + transports.ChatServiceRestInterceptor, "post_create_membership" ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_find_direct_message" + transports.ChatServiceRestInterceptor, "pre_create_membership" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = space.FindDirectMessageRequest.pb(space.FindDirectMessageRequest()) + pb_message = gc_membership.CreateMembershipRequest.pb( + gc_membership.CreateMembershipRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -13373,17 +13992,19 @@ def test_find_direct_message_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = space.Space.to_json(space.Space()) + req.return_value._content = gc_membership.Membership.to_json( + gc_membership.Membership() + ) - request = space.FindDirectMessageRequest() + request = gc_membership.CreateMembershipRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = space.Space() + post.return_value = gc_membership.Membership() - client.find_direct_message( + client.create_membership( request, metadata=[ ("key", "val"), @@ -13395,8 +14016,8 @@ def test_find_direct_message_rest_interceptors(null_interceptor): post.assert_called_once() -def test_find_direct_message_rest_bad_request( - transport: str = "rest", request_type=space.FindDirectMessageRequest +def test_create_membership_rest_bad_request( + transport: str = "rest", request_type=gc_membership.CreateMembershipRequest ): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13404,7 +14025,7 @@ def test_find_direct_message_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {} + request_init = {"parent": "spaces/sample1"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -13416,10 +14037,67 @@ def test_find_direct_message_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.find_direct_message(request) + client.create_membership(request) -def test_find_direct_message_rest_error(): +def test_create_membership_rest_flattened(): + client = ChatServiceClient( + 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 = gc_membership.Membership() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "spaces/sample1"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + membership=gc_membership.Membership(name="name_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 = gc_membership.Membership.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_membership(**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/v1/{parent=spaces/*}/members" % client.transport._host, args[1] + ) + + +def test_create_membership_rest_flattened_error(transport: str = "rest"): + client = ChatServiceClient( + 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_membership( + gc_membership.CreateMembershipRequest(), + parent="parent_value", + membership=gc_membership.Membership(name="name_value"), + ) + + +def test_create_membership_rest_error(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -13428,20 +14106,20 @@ def test_find_direct_message_rest_error(): @pytest.mark.parametrize( "request_type", [ - gc_membership.CreateMembershipRequest, + gc_membership.UpdateMembershipRequest, dict, ], ) -def test_create_membership_rest(request_type): +def test_update_membership_rest(request_type): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "spaces/sample1"} + request_init = {"membership": {"name": "spaces/sample1/members/sample2"}} request_init["membership"] = { - "name": "name_value", + "name": "spaces/sample1/members/sample2", "state": 1, "role": 1, "member": { @@ -13460,7 +14138,7 @@ def test_create_membership_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 = gc_membership.CreateMembershipRequest.meta.fields["membership"] + test_field = gc_membership.UpdateMembershipRequest.meta.fields["membership"] def get_message_fields(field): # Given a field which is a message (composite type), return a list with @@ -13542,7 +14220,7 @@ def get_message_fields(field): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_membership(request) + response = client.update_membership(request) # Establish that the response is the type that we expect. assert isinstance(response, gc_membership.Membership) @@ -13551,13 +14229,12 @@ def get_message_fields(field): assert response.role == gc_membership.Membership.MembershipRole.ROLE_MEMBER -def test_create_membership_rest_required_fields( - request_type=gc_membership.CreateMembershipRequest, +def test_update_membership_rest_required_fields( + request_type=gc_membership.UpdateMembershipRequest, ): transport_class = transports.ChatServiceRestTransport request_init = {} - request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -13568,21 +14245,19 @@ def test_create_membership_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_membership._get_unset_required_fields(jsonified_request) + ).update_membership._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_membership._get_unset_required_fields(jsonified_request) + ).update_membership._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("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 = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13603,7 +14278,7 @@ def test_create_membership_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 @@ -13619,32 +14294,32 @@ def test_create_membership_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_membership(request) + response = client.update_membership(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_membership_rest_unset_required_fields(): +def test_update_membership_rest_unset_required_fields(): transport = transports.ChatServiceRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_membership._get_unset_required_fields({}) + unset_fields = transport.update_membership._get_unset_required_fields({}) assert set(unset_fields) == ( - set(()) + set(("updateMask",)) & set( ( - "parent", "membership", + "updateMask", ) ) ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_membership_rest_interceptors(null_interceptor): +def test_update_membership_rest_interceptors(null_interceptor): transport = transports.ChatServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -13657,14 +14332,14 @@ def test_create_membership_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_membership" + transports.ChatServiceRestInterceptor, "post_update_membership" ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_create_membership" + transports.ChatServiceRestInterceptor, "pre_update_membership" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = gc_membership.CreateMembershipRequest.pb( - gc_membership.CreateMembershipRequest() + pb_message = gc_membership.UpdateMembershipRequest.pb( + gc_membership.UpdateMembershipRequest() ) transcode.return_value = { "method": "post", @@ -13680,7 +14355,7 @@ def test_create_membership_rest_interceptors(null_interceptor): gc_membership.Membership() ) - request = gc_membership.CreateMembershipRequest() + request = gc_membership.UpdateMembershipRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -13688,7 +14363,7 @@ def test_create_membership_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = gc_membership.Membership() - client.create_membership( + client.update_membership( request, metadata=[ ("key", "val"), @@ -13700,8 +14375,8 @@ def test_create_membership_rest_interceptors(null_interceptor): post.assert_called_once() -def test_create_membership_rest_bad_request( - transport: str = "rest", request_type=gc_membership.CreateMembershipRequest +def test_update_membership_rest_bad_request( + transport: str = "rest", request_type=gc_membership.UpdateMembershipRequest ): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13709,7 +14384,7 @@ def test_create_membership_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "spaces/sample1"} + request_init = {"membership": {"name": "spaces/sample1/members/sample2"}} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -13721,10 +14396,10 @@ def test_create_membership_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.create_membership(request) + client.update_membership(request) -def test_create_membership_rest_flattened(): +def test_update_membership_rest_flattened(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -13736,12 +14411,12 @@ def test_create_membership_rest_flattened(): return_value = gc_membership.Membership() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "spaces/sample1"} + sample_request = {"membership": {"name": "spaces/sample1/members/sample2"}} # get truthy value for each flattened field mock_args = dict( - parent="parent_value", membership=gc_membership.Membership(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) @@ -13754,18 +14429,19 @@ def test_create_membership_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.create_membership(**mock_args) + client.update_membership(**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/v1/{parent=spaces/*}/members" % client.transport._host, args[1] + "%s/v1/{membership.name=spaces/*/members/*}" % client.transport._host, + args[1], ) -def test_create_membership_rest_flattened_error(transport: str = "rest"): +def test_update_membership_rest_flattened_error(transport: str = "rest"): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -13774,14 +14450,14 @@ def test_create_membership_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_membership( - gc_membership.CreateMembershipRequest(), - parent="parent_value", + client.update_membership( + gc_membership.UpdateMembershipRequest(), membership=gc_membership.Membership(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_create_membership_rest_error(): +def test_update_membership_rest_error(): client = ChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -15148,6 +15824,7 @@ def test_chat_service_base_transport(): "complete_import_space", "find_direct_message", "create_membership", + "update_membership", "delete_membership", "create_reaction", "list_reactions", @@ -15523,6 +16200,9 @@ def test_chat_service_client_transport_session_collision(transport_name): session1 = client1.transport.create_membership._session session2 = client2.transport.create_membership._session assert session1 != session2 + session1 = client1.transport.update_membership._session + session2 = client2.transport.update_membership._session + assert session1 != session2 session1 = client1.transport.delete_membership._session session2 = client2.transport.delete_membership._session assert session1 != session2