From ec8f5f257d06a9d0e48d3d63508650e1d8b2c8b1 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Wed, 21 Oct 2020 09:45:12 -0700 Subject: [PATCH] chore: re-run synthtool (#225) --- .../services/publisher/async_client.py | 70 +- google/pubsub_v1/services/publisher/client.py | 114 ++- .../services/publisher/transports/base.py | 10 +- .../services/publisher/transports/grpc.py | 18 +- .../publisher/transports/grpc_asyncio.py | 4 + .../services/subscriber/async_client.py | 113 ++- .../pubsub_v1/services/subscriber/client.py | 125 +++- .../services/subscriber/transports/base.py | 16 +- .../services/subscriber/transports/grpc.py | 18 +- .../subscriber/transports/grpc_asyncio.py | 4 + google/pubsub_v1/types/pubsub.py | 24 +- synth.metadata | 8 +- tests/unit/gapic/pubsub_v1/test_publisher.py | 523 +++++++++---- tests/unit/gapic/pubsub_v1/test_subscriber.py | 696 ++++++++++++------ 14 files changed, 1239 insertions(+), 504 deletions(-) diff --git a/google/pubsub_v1/services/publisher/async_client.py b/google/pubsub_v1/services/publisher/async_client.py index 601fc09d2..fdf3aeb37 100644 --- a/google/pubsub_v1/services/publisher/async_client.py +++ b/google/pubsub_v1/services/publisher/async_client.py @@ -48,12 +48,46 @@ class PublisherAsyncClient: DEFAULT_ENDPOINT = PublisherClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = PublisherClient.DEFAULT_MTLS_ENDPOINT + subscription_path = staticmethod(PublisherClient.subscription_path) + parse_subscription_path = staticmethod(PublisherClient.parse_subscription_path) topic_path = staticmethod(PublisherClient.topic_path) parse_topic_path = staticmethod(PublisherClient.parse_topic_path) + common_billing_account_path = staticmethod( + PublisherClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + PublisherClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(PublisherClient.common_folder_path) + parse_common_folder_path = staticmethod(PublisherClient.parse_common_folder_path) + + common_organization_path = staticmethod(PublisherClient.common_organization_path) + parse_common_organization_path = staticmethod( + PublisherClient.parse_common_organization_path + ) + + common_project_path = staticmethod(PublisherClient.common_project_path) + parse_common_project_path = staticmethod(PublisherClient.parse_common_project_path) + + common_location_path = staticmethod(PublisherClient.common_location_path) + parse_common_location_path = staticmethod( + PublisherClient.parse_common_location_path + ) + from_service_account_file = PublisherClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> PublisherTransport: + """Return the transport used by the client instance. + + Returns: + PublisherTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(PublisherClient).get_transport_class, type(PublisherClient) ) @@ -148,7 +182,8 @@ async def create_topic( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -287,7 +322,8 @@ async def publish( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([topic, messages]): + has_flattened_params = any([topic, messages]) + 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." @@ -300,8 +336,9 @@ async def publish( if topic is not None: request.topic = topic - if messages is not None: - request.messages = messages + + if messages: + request.messages.extend(messages) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -312,13 +349,13 @@ async def publish( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.Aborted, exceptions.Cancelled, exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ResourceExhausted, exceptions.ServiceUnavailable, exceptions.Unknown, - exceptions.Aborted, ), ), default_timeout=60.0, @@ -371,7 +408,8 @@ async def get_topic( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([topic]): + has_flattened_params = any([topic]) + 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." @@ -395,8 +433,8 @@ async def get_topic( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -453,7 +491,8 @@ async def list_topics( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([project]): + has_flattened_params = any([project]) + 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." @@ -477,8 +516,8 @@ async def list_topics( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -544,7 +583,8 @@ async def list_topic_subscriptions( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([topic]): + has_flattened_params = any([topic]) + 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." @@ -568,8 +608,8 @@ async def list_topic_subscriptions( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -639,7 +679,8 @@ async def list_topic_snapshots( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([topic]): + has_flattened_params = any([topic]) + 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." @@ -663,8 +704,8 @@ async def list_topic_snapshots( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -725,7 +766,8 @@ async def delete_topic( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([topic]): + has_flattened_params = any([topic]) + 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." diff --git a/google/pubsub_v1/services/publisher/client.py b/google/pubsub_v1/services/publisher/client.py index 2df57b0ca..188b3dccb 100644 --- a/google/pubsub_v1/services/publisher/client.py +++ b/google/pubsub_v1/services/publisher/client.py @@ -19,10 +19,10 @@ from distutils import util import os import re -from typing import Callable, Dict, Sequence, Tuple, Type, Union +from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core import client_options as client_options_lib # type: ignore from google.api_core import exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore @@ -145,6 +145,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> PublisherTransport: + """Return the transport used by the client instance. + + Returns: + PublisherTransport: The transport used by the client instance. + """ + return self._transport + + @staticmethod + def subscription_path(project: str, subscription: str,) -> str: + """Return a fully-qualified subscription string.""" + return "projects/{project}/subscriptions/{subscription}".format( + project=project, subscription=subscription, + ) + + @staticmethod + def parse_subscription_path(path: str) -> Dict[str, str]: + """Parse a subscription path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/subscriptions/(?P.+?)$", path + ) + return m.groupdict() if m else {} + @staticmethod def topic_path(project: str, topic: str,) -> str: """Return a fully-qualified topic string.""" @@ -156,12 +180,71 @@ def parse_topic_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/topics/(?P.+?)$", path) return m.groupdict() if m else {} + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, - credentials: credentials.Credentials = None, - transport: Union[str, PublisherTransport] = None, - client_options: ClientOptions = None, + credentials: Optional[credentials.Credentials] = None, + transport: Union[str, PublisherTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the publisher client. @@ -176,8 +259,8 @@ def __init__( transport (Union[str, ~.PublisherTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. + client_options (client_options_lib.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: @@ -192,10 +275,10 @@ def __init__( not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -203,9 +286,9 @@ def __init__( creation failed for any reason. """ if isinstance(client_options, dict): - client_options = ClientOptions.from_dict(client_options) + client_options = client_options_lib.from_dict(client_options) if client_options is None: - client_options = ClientOptions.ClientOptions() + client_options = client_options_lib.ClientOptions() # Create SSL credentials for mutual TLS if needed. use_client_cert = bool( @@ -468,8 +551,9 @@ def publish( if topic is not None: request.topic = topic - if messages is not None: - request.messages = messages + + if messages: + request.messages.extend(messages) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/pubsub_v1/services/publisher/transports/base.py b/google/pubsub_v1/services/publisher/transports/base.py index fcb3b99a8..fe84ac415 100644 --- a/google/pubsub_v1/services/publisher/transports/base.py +++ b/google/pubsub_v1/services/publisher/transports/base.py @@ -139,13 +139,13 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.Aborted, exceptions.Cancelled, exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ResourceExhausted, exceptions.ServiceUnavailable, exceptions.Unknown, - exceptions.Aborted, ), ), default_timeout=60.0, @@ -159,8 +159,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -174,8 +174,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -189,8 +189,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -204,8 +204,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, diff --git a/google/pubsub_v1/services/publisher/transports/grpc.py b/google/pubsub_v1/services/publisher/transports/grpc.py index d3d015f6b..15de8f87d 100644 --- a/google/pubsub_v1/services/publisher/transports/grpc.py +++ b/google/pubsub_v1/services/publisher/transports/grpc.py @@ -93,10 +93,10 @@ def __init__( for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -105,6 +105,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -112,6 +114,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -148,6 +151,7 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -225,12 +229,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property diff --git a/google/pubsub_v1/services/publisher/transports/grpc_asyncio.py b/google/pubsub_v1/services/publisher/transports/grpc_asyncio.py index 6d30b31fd..31ad368f8 100644 --- a/google/pubsub_v1/services/publisher/transports/grpc_asyncio.py +++ b/google/pubsub_v1/services/publisher/transports/grpc_asyncio.py @@ -150,6 +150,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -157,6 +159,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -193,6 +196,7 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" diff --git a/google/pubsub_v1/services/subscriber/async_client.py b/google/pubsub_v1/services/subscriber/async_client.py index bcf3649f9..61d79ce8b 100644 --- a/google/pubsub_v1/services/subscriber/async_client.py +++ b/google/pubsub_v1/services/subscriber/async_client.py @@ -18,7 +18,16 @@ from collections import OrderedDict import functools import re -from typing import Dict, AsyncIterable, AsyncIterator, Sequence, Tuple, Type, Union +from typing import ( + Dict, + AsyncIterable, + Awaitable, + AsyncIterator, + Sequence, + Tuple, + Type, + Union, +) import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore @@ -56,10 +65,44 @@ class SubscriberAsyncClient: parse_snapshot_path = staticmethod(SubscriberClient.parse_snapshot_path) subscription_path = staticmethod(SubscriberClient.subscription_path) parse_subscription_path = staticmethod(SubscriberClient.parse_subscription_path) + topic_path = staticmethod(SubscriberClient.topic_path) + parse_topic_path = staticmethod(SubscriberClient.parse_topic_path) + + common_billing_account_path = staticmethod( + SubscriberClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + SubscriberClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(SubscriberClient.common_folder_path) + parse_common_folder_path = staticmethod(SubscriberClient.parse_common_folder_path) + + common_organization_path = staticmethod(SubscriberClient.common_organization_path) + parse_common_organization_path = staticmethod( + SubscriberClient.parse_common_organization_path + ) + + common_project_path = staticmethod(SubscriberClient.common_project_path) + parse_common_project_path = staticmethod(SubscriberClient.parse_common_project_path) + + common_location_path = staticmethod(SubscriberClient.common_location_path) + parse_common_location_path = staticmethod( + SubscriberClient.parse_common_location_path + ) from_service_account_file = SubscriberClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> SubscriberTransport: + """Return the transport used by the client instance. + + Returns: + SubscriberTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(SubscriberClient).get_transport_class, type(SubscriberClient) ) @@ -213,9 +256,8 @@ async def create_subscription( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any( - [name, topic, push_config, ack_deadline_seconds] - ): + has_flattened_params = any([name, topic, push_config, ack_deadline_seconds]) + 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." @@ -245,8 +287,8 @@ async def create_subscription( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -300,7 +342,8 @@ async def get_subscription( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([subscription]): + has_flattened_params = any([subscription]) + 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." @@ -324,8 +367,8 @@ async def get_subscription( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -444,7 +487,8 @@ async def list_subscriptions( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([project]): + has_flattened_params = any([project]) + 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." @@ -468,8 +512,8 @@ async def list_subscriptions( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -530,7 +574,8 @@ async def delete_subscription( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([subscription]): + has_flattened_params = any([subscription]) + 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." @@ -629,7 +674,8 @@ async def modify_ack_deadline( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([subscription, ack_ids, ack_deadline_seconds]): + has_flattened_params = any([subscription, ack_ids, ack_deadline_seconds]) + 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." @@ -642,11 +688,12 @@ async def modify_ack_deadline( if subscription is not None: request.subscription = subscription - if ack_ids is not None: - request.ack_ids = ack_ids if ack_deadline_seconds is not None: request.ack_deadline_seconds = ack_deadline_seconds + if ack_ids: + request.ack_ids.extend(ack_ids) + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( @@ -720,7 +767,8 @@ async def acknowledge( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([subscription, ack_ids]): + has_flattened_params = any([subscription, ack_ids]) + 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." @@ -733,8 +781,9 @@ async def acknowledge( if subscription is not None: request.subscription = subscription - if ack_ids is not None: - request.ack_ids = ack_ids + + if ack_ids: + request.ack_ids.extend(ack_ids) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -824,9 +873,8 @@ async def pull( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any( - [subscription, return_immediately, max_messages] - ): + has_flattened_params = any([subscription, return_immediately, max_messages]) + 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." @@ -854,8 +902,8 @@ async def pull( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -883,7 +931,7 @@ def streaming_pull( retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> AsyncIterable[pubsub.StreamingPullResponse]: + ) -> Awaitable[AsyncIterable[pubsub.StreamingPullResponse]]: r"""Establishes a stream with the server, which sends messages down to the client. The client streams acknowledgements and ack deadline modifications back to the server. The server will close @@ -923,11 +971,11 @@ def streaming_pull( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.Aborted, exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ResourceExhausted, exceptions.ServiceUnavailable, - exceptions.Aborted, ), ), default_timeout=900.0, @@ -989,7 +1037,8 @@ async def modify_push_config( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([subscription, push_config]): + has_flattened_params = any([subscription, push_config]) + 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." @@ -1078,7 +1127,8 @@ async def get_snapshot( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([snapshot]): + has_flattened_params = any([snapshot]) + 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." @@ -1102,8 +1152,8 @@ async def get_snapshot( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -1165,7 +1215,8 @@ async def list_snapshots( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([project]): + has_flattened_params = any([project]) + 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." @@ -1189,8 +1240,8 @@ async def list_snapshots( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -1294,7 +1345,8 @@ async def create_snapshot( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name, subscription]): + has_flattened_params = any([name, subscription]) + 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." @@ -1445,7 +1497,8 @@ async def delete_snapshot( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([snapshot]): + has_flattened_params = any([snapshot]) + 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." @@ -1532,8 +1585,8 @@ async def seek( multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, diff --git a/google/pubsub_v1/services/subscriber/client.py b/google/pubsub_v1/services/subscriber/client.py index 1193044c4..60d44b579 100644 --- a/google/pubsub_v1/services/subscriber/client.py +++ b/google/pubsub_v1/services/subscriber/client.py @@ -19,10 +19,20 @@ from distutils import util import os import re -from typing import Callable, Dict, Iterable, Iterator, Sequence, Tuple, Type, Union +from typing import ( + Callable, + Dict, + Optional, + Iterable, + Iterator, + Sequence, + Tuple, + Type, + Union, +) import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core import client_options as client_options_lib # type: ignore from google.api_core import exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore @@ -149,6 +159,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> SubscriberTransport: + """Return the transport used by the client instance. + + Returns: + SubscriberTransport: The transport used by the client instance. + """ + return self._transport + @staticmethod def snapshot_path(project: str, snapshot: str,) -> str: """Return a fully-qualified snapshot string.""" @@ -177,12 +196,82 @@ def parse_subscription_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def topic_path(project: str, topic: str,) -> str: + """Return a fully-qualified topic string.""" + return "projects/{project}/topics/{topic}".format(project=project, topic=topic,) + + @staticmethod + def parse_topic_path(path: str) -> Dict[str, str]: + """Parse a topic path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/topics/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, - credentials: credentials.Credentials = None, - transport: Union[str, SubscriberTransport] = None, - client_options: ClientOptions = None, + credentials: Optional[credentials.Credentials] = None, + transport: Union[str, SubscriberTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the subscriber client. @@ -197,8 +286,8 @@ def __init__( transport (Union[str, ~.SubscriberTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. + client_options (client_options_lib.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: @@ -213,10 +302,10 @@ def __init__( not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -224,9 +313,9 @@ def __init__( creation failed for any reason. """ if isinstance(client_options, dict): - client_options = ClientOptions.from_dict(client_options) + client_options = client_options_lib.from_dict(client_options) if client_options is None: - client_options = ClientOptions.ClientOptions() + client_options = client_options_lib.ClientOptions() # Create SSL credentials for mutual TLS if needed. use_client_cert = bool( @@ -802,11 +891,12 @@ def modify_ack_deadline( if subscription is not None: request.subscription = subscription - if ack_ids is not None: - request.ack_ids = ack_ids if ack_deadline_seconds is not None: request.ack_deadline_seconds = ack_deadline_seconds + if ack_ids: + request.ack_ids.extend(ack_ids) + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.modify_ack_deadline] @@ -890,8 +980,9 @@ def acknowledge( if subscription is not None: request.subscription = subscription - if ack_ids is not None: - request.ack_ids = ack_ids + + if ack_ids: + request.ack_ids.extend(ack_ids) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/pubsub_v1/services/subscriber/transports/base.py b/google/pubsub_v1/services/subscriber/transports/base.py index 600369d83..8442fc0fe 100644 --- a/google/pubsub_v1/services/subscriber/transports/base.py +++ b/google/pubsub_v1/services/subscriber/transports/base.py @@ -118,8 +118,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -133,8 +133,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -159,8 +159,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -207,8 +207,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -221,11 +221,11 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.Aborted, exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ResourceExhausted, exceptions.ServiceUnavailable, - exceptions.Aborted, ), ), default_timeout=900.0, @@ -250,8 +250,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -265,8 +265,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, @@ -313,8 +313,8 @@ def _prep_wrapped_messages(self, client_info): multiplier=1.3, predicate=retries.if_exception_type( exceptions.Aborted, - exceptions.Unknown, exceptions.ServiceUnavailable, + exceptions.Unknown, ), ), default_timeout=60.0, diff --git a/google/pubsub_v1/services/subscriber/transports/grpc.py b/google/pubsub_v1/services/subscriber/transports/grpc.py index e2f20b1c9..5b39bb1d6 100644 --- a/google/pubsub_v1/services/subscriber/transports/grpc.py +++ b/google/pubsub_v1/services/subscriber/transports/grpc.py @@ -95,10 +95,10 @@ def __init__( for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -107,6 +107,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -114,6 +116,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -150,6 +153,7 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -227,12 +231,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property diff --git a/google/pubsub_v1/services/subscriber/transports/grpc_asyncio.py b/google/pubsub_v1/services/subscriber/transports/grpc_asyncio.py index cc2f3a240..f64f1a18e 100644 --- a/google/pubsub_v1/services/subscriber/transports/grpc_asyncio.py +++ b/google/pubsub_v1/services/subscriber/transports/grpc_asyncio.py @@ -152,6 +152,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -159,6 +161,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -195,6 +198,7 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" diff --git a/google/pubsub_v1/types/pubsub.py b/google/pubsub_v1/types/pubsub.py index 61bb089f5..c34cf422d 100644 --- a/google/pubsub_v1/types/pubsub.py +++ b/google/pubsub_v1/types/pubsub.py @@ -126,7 +126,7 @@ class Topic(proto.Message): labels = proto.MapField(proto.STRING, proto.STRING, number=2) message_storage_policy = proto.Field( - proto.MESSAGE, number=3, message=MessageStoragePolicy, + proto.MESSAGE, number=3, message="MessageStoragePolicy", ) kms_key_name = proto.Field(proto.STRING, number=5) @@ -213,7 +213,7 @@ class UpdateTopicRequest(proto.Message): policy configured at the project or organization level. """ - topic = proto.Field(proto.MESSAGE, number=1, message=Topic,) + topic = proto.Field(proto.MESSAGE, number=1, message="Topic",) update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) @@ -231,7 +231,7 @@ class PublishRequest(proto.Message): topic = proto.Field(proto.STRING, number=1) - messages = proto.RepeatedField(proto.MESSAGE, number=2, message=PubsubMessage,) + messages = proto.RepeatedField(proto.MESSAGE, number=2, message="PubsubMessage",) class PublishResponse(proto.Message): @@ -287,7 +287,7 @@ class ListTopicsResponse(proto.Message): def raw_page(self): return self - topics = proto.RepeatedField(proto.MESSAGE, number=1, message=Topic,) + topics = proto.RepeatedField(proto.MESSAGE, number=1, message="Topic",) next_page_token = proto.Field(proto.STRING, number=2) @@ -772,7 +772,7 @@ class ReceivedMessage(proto.Message): ack_id = proto.Field(proto.STRING, number=1) - message = proto.Field(proto.MESSAGE, number=2, message=PubsubMessage,) + message = proto.Field(proto.MESSAGE, number=2, message="PubsubMessage",) delivery_attempt = proto.Field(proto.INT32, number=3) @@ -801,7 +801,7 @@ class UpdateSubscriptionRequest(proto.Message): specified and non-empty. """ - subscription = proto.Field(proto.MESSAGE, number=1, message=Subscription,) + subscription = proto.Field(proto.MESSAGE, number=1, message="Subscription",) update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) @@ -845,7 +845,9 @@ class ListSubscriptionsResponse(proto.Message): def raw_page(self): return self - subscriptions = proto.RepeatedField(proto.MESSAGE, number=1, message=Subscription,) + subscriptions = proto.RepeatedField( + proto.MESSAGE, number=1, message="Subscription", + ) next_page_token = proto.Field(proto.STRING, number=2) @@ -881,7 +883,7 @@ class ModifyPushConfigRequest(proto.Message): subscription = proto.Field(proto.STRING, number=1) - push_config = proto.Field(proto.MESSAGE, number=2, message=PushConfig,) + push_config = proto.Field(proto.MESSAGE, number=2, message="PushConfig",) class PullRequest(proto.Message): @@ -928,7 +930,7 @@ class PullResponse(proto.Message): """ received_messages = proto.RepeatedField( - proto.MESSAGE, number=1, message=ReceivedMessage, + proto.MESSAGE, number=1, message="ReceivedMessage", ) @@ -1092,7 +1094,7 @@ class StreamingPullResponse(proto.Message): """ received_messages = proto.RepeatedField( - proto.MESSAGE, number=1, message=ReceivedMessage, + proto.MESSAGE, number=1, message="ReceivedMessage", ) @@ -1240,7 +1242,7 @@ class ListSnapshotsResponse(proto.Message): def raw_page(self): return self - snapshots = proto.RepeatedField(proto.MESSAGE, number=1, message=Snapshot,) + snapshots = proto.RepeatedField(proto.MESSAGE, number=1, message="Snapshot",) next_page_token = proto.Field(proto.STRING, number=2) diff --git a/synth.metadata b/synth.metadata index a29820d3d..148d44682 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,28 +4,28 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-pubsub.git", - "sha": "89c671aeb4de2c47f45ca1e438b91c440bead958" + "sha": "c957047c84c5586e4a782e9ae297094be6cdba2e" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "dba48bb9bc6959c232bec9150ac6313b608fe7bd" + "sha": "6abb59097be84599a1d6091fe534a49e5c5cf948" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "dba48bb9bc6959c232bec9150ac6313b608fe7bd" + "sha": "6abb59097be84599a1d6091fe534a49e5c5cf948" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "dba48bb9bc6959c232bec9150ac6313b608fe7bd" + "sha": "6abb59097be84599a1d6091fe534a49e5c5cf948" } } ], diff --git a/tests/unit/gapic/pubsub_v1/test_publisher.py b/tests/unit/gapic/pubsub_v1/test_publisher.py index b7d99542c..e955e5b82 100644 --- a/tests/unit/gapic/pubsub_v1/test_publisher.py +++ b/tests/unit/gapic/pubsub_v1/test_publisher.py @@ -92,12 +92,12 @@ def test_publisher_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "pubsub.googleapis.com:443" + assert client.transport._host == "pubsub.googleapis.com:443" def test_publisher_client_get_transport_class(): @@ -437,7 +437,7 @@ def test_create_topic(transport: str = "grpc", request_type=pubsub.Topic): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_topic), "__call__") as call: + with mock.patch.object(type(client.transport.create_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Topic( name="name_value", kms_key_name="kms_key_name_value", @@ -452,6 +452,7 @@ def test_create_topic(transport: str = "grpc", request_type=pubsub.Topic): assert args[0] == pubsub.Topic() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.Topic) assert response.name == "name_value" @@ -464,19 +465,19 @@ def test_create_topic_from_dict(): @pytest.mark.asyncio -async def test_create_topic_async(transport: str = "grpc_asyncio"): +async def test_create_topic_async( + transport: str = "grpc_asyncio", request_type=pubsub.Topic +): client = PublisherAsyncClient( credentials=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 = pubsub.Topic() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.Topic(name="name_value", kms_key_name="kms_key_name_value",) @@ -488,7 +489,7 @@ async def test_create_topic_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.Topic() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.Topic) @@ -498,6 +499,11 @@ async def test_create_topic_async(transport: str = "grpc_asyncio"): assert response.kms_key_name == "kms_key_name_value" +@pytest.mark.asyncio +async def test_create_topic_async_from_dict(): + await test_create_topic_async(request_type=dict) + + def test_create_topic_field_headers(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) @@ -507,7 +513,7 @@ def test_create_topic_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_topic), "__call__") as call: + with mock.patch.object(type(client.transport.create_topic), "__call__") as call: call.return_value = pubsub.Topic() client.create_topic(request) @@ -532,9 +538,7 @@ async def test_create_topic_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_topic), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.Topic()) await client.create_topic(request) @@ -553,7 +557,7 @@ def test_create_topic_flattened(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_topic), "__call__") as call: + with mock.patch.object(type(client.transport.create_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Topic() @@ -585,9 +589,7 @@ async def test_create_topic_flattened_async(): client = PublisherAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Topic() @@ -626,7 +628,7 @@ def test_update_topic(transport: str = "grpc", request_type=pubsub.UpdateTopicRe request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_topic), "__call__") as call: + with mock.patch.object(type(client.transport.update_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Topic( name="name_value", kms_key_name="kms_key_name_value", @@ -641,6 +643,7 @@ def test_update_topic(transport: str = "grpc", request_type=pubsub.UpdateTopicRe assert args[0] == pubsub.UpdateTopicRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.Topic) assert response.name == "name_value" @@ -653,19 +656,19 @@ def test_update_topic_from_dict(): @pytest.mark.asyncio -async def test_update_topic_async(transport: str = "grpc_asyncio"): +async def test_update_topic_async( + transport: str = "grpc_asyncio", request_type=pubsub.UpdateTopicRequest +): client = PublisherAsyncClient( credentials=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 = pubsub.UpdateTopicRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.Topic(name="name_value", kms_key_name="kms_key_name_value",) @@ -677,7 +680,7 @@ async def test_update_topic_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.UpdateTopicRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.Topic) @@ -687,6 +690,11 @@ async def test_update_topic_async(transport: str = "grpc_asyncio"): assert response.kms_key_name == "kms_key_name_value" +@pytest.mark.asyncio +async def test_update_topic_async_from_dict(): + await test_update_topic_async(request_type=dict) + + def test_update_topic_field_headers(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) @@ -696,7 +704,7 @@ def test_update_topic_field_headers(): request.topic.name = "topic.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_topic), "__call__") as call: + with mock.patch.object(type(client.transport.update_topic), "__call__") as call: call.return_value = pubsub.Topic() client.update_topic(request) @@ -721,9 +729,7 @@ async def test_update_topic_field_headers_async(): request.topic.name = "topic.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_topic), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.Topic()) await client.update_topic(request) @@ -748,7 +754,7 @@ def test_publish(transport: str = "grpc", request_type=pubsub.PublishRequest): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.publish), "__call__") as call: + with mock.patch.object(type(client.transport.publish), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.PublishResponse(message_ids=["message_ids_value"],) @@ -761,6 +767,7 @@ def test_publish(transport: str = "grpc", request_type=pubsub.PublishRequest): assert args[0] == pubsub.PublishRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.PublishResponse) assert response.message_ids == ["message_ids_value"] @@ -771,17 +778,19 @@ def test_publish_from_dict(): @pytest.mark.asyncio -async def test_publish_async(transport: str = "grpc_asyncio"): +async def test_publish_async( + transport: str = "grpc_asyncio", request_type=pubsub.PublishRequest +): client = PublisherAsyncClient( credentials=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 = pubsub.PublishRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.publish), "__call__") as call: + with mock.patch.object(type(client.transport.publish), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.PublishResponse(message_ids=["message_ids_value"],) @@ -793,7 +802,7 @@ async def test_publish_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.PublishRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.PublishResponse) @@ -801,6 +810,11 @@ async def test_publish_async(transport: str = "grpc_asyncio"): assert response.message_ids == ["message_ids_value"] +@pytest.mark.asyncio +async def test_publish_async_from_dict(): + await test_publish_async(request_type=dict) + + def test_publish_field_headers(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) @@ -810,7 +824,7 @@ def test_publish_field_headers(): request.topic = "topic/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.publish), "__call__") as call: + with mock.patch.object(type(client.transport.publish), "__call__") as call: call.return_value = pubsub.PublishResponse() client.publish(request) @@ -835,7 +849,7 @@ async def test_publish_field_headers_async(): request.topic = "topic/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.publish), "__call__") as call: + with mock.patch.object(type(client.transport.publish), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.PublishResponse() ) @@ -856,7 +870,7 @@ def test_publish_flattened(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.publish), "__call__") as call: + with mock.patch.object(type(client.transport.publish), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.PublishResponse() @@ -894,7 +908,7 @@ async def test_publish_flattened_async(): client = PublisherAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.publish), "__call__") as call: + with mock.patch.object(type(client.transport.publish), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.PublishResponse() @@ -941,7 +955,7 @@ def test_get_topic(transport: str = "grpc", request_type=pubsub.GetTopicRequest) request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_topic), "__call__") as call: + with mock.patch.object(type(client.transport.get_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Topic( name="name_value", kms_key_name="kms_key_name_value", @@ -956,6 +970,7 @@ def test_get_topic(transport: str = "grpc", request_type=pubsub.GetTopicRequest) assert args[0] == pubsub.GetTopicRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.Topic) assert response.name == "name_value" @@ -968,19 +983,19 @@ def test_get_topic_from_dict(): @pytest.mark.asyncio -async def test_get_topic_async(transport: str = "grpc_asyncio"): +async def test_get_topic_async( + transport: str = "grpc_asyncio", request_type=pubsub.GetTopicRequest +): client = PublisherAsyncClient( credentials=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 = pubsub.GetTopicRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.Topic(name="name_value", kms_key_name="kms_key_name_value",) @@ -992,7 +1007,7 @@ async def test_get_topic_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.GetTopicRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.Topic) @@ -1002,6 +1017,11 @@ async def test_get_topic_async(transport: str = "grpc_asyncio"): assert response.kms_key_name == "kms_key_name_value" +@pytest.mark.asyncio +async def test_get_topic_async_from_dict(): + await test_get_topic_async(request_type=dict) + + def test_get_topic_field_headers(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) @@ -1011,7 +1031,7 @@ def test_get_topic_field_headers(): request.topic = "topic/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_topic), "__call__") as call: + with mock.patch.object(type(client.transport.get_topic), "__call__") as call: call.return_value = pubsub.Topic() client.get_topic(request) @@ -1036,9 +1056,7 @@ async def test_get_topic_field_headers_async(): request.topic = "topic/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_topic), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.Topic()) await client.get_topic(request) @@ -1057,7 +1075,7 @@ def test_get_topic_flattened(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_topic), "__call__") as call: + with mock.patch.object(type(client.transport.get_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Topic() @@ -1089,9 +1107,7 @@ async def test_get_topic_flattened_async(): client = PublisherAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Topic() @@ -1130,7 +1146,7 @@ def test_list_topics(transport: str = "grpc", request_type=pubsub.ListTopicsRequ request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_topics), "__call__") as call: + with mock.patch.object(type(client.transport.list_topics), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListTopicsResponse( next_page_token="next_page_token_value", @@ -1145,6 +1161,7 @@ def test_list_topics(transport: str = "grpc", request_type=pubsub.ListTopicsRequ assert args[0] == pubsub.ListTopicsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTopicsPager) assert response.next_page_token == "next_page_token_value" @@ -1155,19 +1172,19 @@ def test_list_topics_from_dict(): @pytest.mark.asyncio -async def test_list_topics_async(transport: str = "grpc_asyncio"): +async def test_list_topics_async( + transport: str = "grpc_asyncio", request_type=pubsub.ListTopicsRequest +): client = PublisherAsyncClient( credentials=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 = pubsub.ListTopicsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_topics), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_topics), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.ListTopicsResponse(next_page_token="next_page_token_value",) @@ -1179,7 +1196,7 @@ async def test_list_topics_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.ListTopicsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListTopicsAsyncPager) @@ -1187,6 +1204,11 @@ async def test_list_topics_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_topics_async_from_dict(): + await test_list_topics_async(request_type=dict) + + def test_list_topics_field_headers(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) @@ -1196,7 +1218,7 @@ def test_list_topics_field_headers(): request.project = "project/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_topics), "__call__") as call: + with mock.patch.object(type(client.transport.list_topics), "__call__") as call: call.return_value = pubsub.ListTopicsResponse() client.list_topics(request) @@ -1221,9 +1243,7 @@ async def test_list_topics_field_headers_async(): request.project = "project/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_topics), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_topics), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.ListTopicsResponse() ) @@ -1244,7 +1264,7 @@ def test_list_topics_flattened(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_topics), "__call__") as call: + with mock.patch.object(type(client.transport.list_topics), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListTopicsResponse() @@ -1276,9 +1296,7 @@ async def test_list_topics_flattened_async(): client = PublisherAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_topics), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_topics), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListTopicsResponse() @@ -1313,7 +1331,7 @@ def test_list_topics_pager(): client = PublisherClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_topics), "__call__") as call: + with mock.patch.object(type(client.transport.list_topics), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( pubsub.ListTopicsResponse( @@ -1343,7 +1361,7 @@ def test_list_topics_pages(): client = PublisherClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_topics), "__call__") as call: + with mock.patch.object(type(client.transport.list_topics), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( pubsub.ListTopicsResponse( @@ -1366,9 +1384,7 @@ async def test_list_topics_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topics), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_topics), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1397,9 +1413,7 @@ async def test_list_topics_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topics), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_topics), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1432,7 +1446,7 @@ def test_list_topic_subscriptions( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_topic_subscriptions), "__call__" + type(client.transport.list_topic_subscriptions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListTopicSubscriptionsResponse( @@ -1449,6 +1463,7 @@ def test_list_topic_subscriptions( assert args[0] == pubsub.ListTopicSubscriptionsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTopicSubscriptionsPager) assert response.subscriptions == ["subscriptions_value"] @@ -1461,18 +1476,20 @@ def test_list_topic_subscriptions_from_dict(): @pytest.mark.asyncio -async def test_list_topic_subscriptions_async(transport: str = "grpc_asyncio"): +async def test_list_topic_subscriptions_async( + transport: str = "grpc_asyncio", request_type=pubsub.ListTopicSubscriptionsRequest +): client = PublisherAsyncClient( credentials=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 = pubsub.ListTopicSubscriptionsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topic_subscriptions), "__call__" + type(client.transport.list_topic_subscriptions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1488,7 +1505,7 @@ async def test_list_topic_subscriptions_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.ListTopicSubscriptionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListTopicSubscriptionsAsyncPager) @@ -1498,6 +1515,11 @@ async def test_list_topic_subscriptions_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_topic_subscriptions_async_from_dict(): + await test_list_topic_subscriptions_async(request_type=dict) + + def test_list_topic_subscriptions_field_headers(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) @@ -1508,7 +1530,7 @@ def test_list_topic_subscriptions_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_topic_subscriptions), "__call__" + type(client.transport.list_topic_subscriptions), "__call__" ) as call: call.return_value = pubsub.ListTopicSubscriptionsResponse() @@ -1535,7 +1557,7 @@ async def test_list_topic_subscriptions_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topic_subscriptions), "__call__" + type(client.transport.list_topic_subscriptions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.ListTopicSubscriptionsResponse() @@ -1558,7 +1580,7 @@ def test_list_topic_subscriptions_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_topic_subscriptions), "__call__" + type(client.transport.list_topic_subscriptions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListTopicSubscriptionsResponse() @@ -1592,7 +1614,7 @@ async def test_list_topic_subscriptions_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topic_subscriptions), "__call__" + type(client.transport.list_topic_subscriptions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListTopicSubscriptionsResponse() @@ -1629,7 +1651,7 @@ def test_list_topic_subscriptions_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_topic_subscriptions), "__call__" + type(client.transport.list_topic_subscriptions), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1664,7 +1686,7 @@ def test_list_topic_subscriptions_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_topic_subscriptions), "__call__" + type(client.transport.list_topic_subscriptions), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1691,7 +1713,7 @@ async def test_list_topic_subscriptions_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topic_subscriptions), + type(client.transport.list_topic_subscriptions), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1725,7 +1747,7 @@ async def test_list_topic_subscriptions_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topic_subscriptions), + type(client.transport.list_topic_subscriptions), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1763,7 +1785,7 @@ def test_list_topic_snapshots( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_topic_snapshots), "__call__" + type(client.transport.list_topic_snapshots), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListTopicSnapshotsResponse( @@ -1779,6 +1801,7 @@ def test_list_topic_snapshots( assert args[0] == pubsub.ListTopicSnapshotsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTopicSnapshotsPager) assert response.snapshots == ["snapshots_value"] @@ -1791,18 +1814,20 @@ def test_list_topic_snapshots_from_dict(): @pytest.mark.asyncio -async def test_list_topic_snapshots_async(transport: str = "grpc_asyncio"): +async def test_list_topic_snapshots_async( + transport: str = "grpc_asyncio", request_type=pubsub.ListTopicSnapshotsRequest +): client = PublisherAsyncClient( credentials=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 = pubsub.ListTopicSnapshotsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topic_snapshots), "__call__" + type(client.transport.list_topic_snapshots), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1817,7 +1842,7 @@ async def test_list_topic_snapshots_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.ListTopicSnapshotsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListTopicSnapshotsAsyncPager) @@ -1827,6 +1852,11 @@ async def test_list_topic_snapshots_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_topic_snapshots_async_from_dict(): + await test_list_topic_snapshots_async(request_type=dict) + + def test_list_topic_snapshots_field_headers(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) @@ -1837,7 +1867,7 @@ def test_list_topic_snapshots_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_topic_snapshots), "__call__" + type(client.transport.list_topic_snapshots), "__call__" ) as call: call.return_value = pubsub.ListTopicSnapshotsResponse() @@ -1864,7 +1894,7 @@ async def test_list_topic_snapshots_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topic_snapshots), "__call__" + type(client.transport.list_topic_snapshots), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.ListTopicSnapshotsResponse() @@ -1887,7 +1917,7 @@ def test_list_topic_snapshots_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_topic_snapshots), "__call__" + type(client.transport.list_topic_snapshots), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListTopicSnapshotsResponse() @@ -1921,7 +1951,7 @@ async def test_list_topic_snapshots_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topic_snapshots), "__call__" + type(client.transport.list_topic_snapshots), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListTopicSnapshotsResponse() @@ -1958,7 +1988,7 @@ def test_list_topic_snapshots_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_topic_snapshots), "__call__" + type(client.transport.list_topic_snapshots), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1991,7 +2021,7 @@ def test_list_topic_snapshots_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_topic_snapshots), "__call__" + type(client.transport.list_topic_snapshots), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2016,7 +2046,7 @@ async def test_list_topic_snapshots_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topic_snapshots), + type(client.transport.list_topic_snapshots), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -2048,7 +2078,7 @@ async def test_list_topic_snapshots_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_topic_snapshots), + type(client.transport.list_topic_snapshots), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -2081,7 +2111,7 @@ def test_delete_topic(transport: str = "grpc", request_type=pubsub.DeleteTopicRe request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_topic), "__call__") as call: + with mock.patch.object(type(client.transport.delete_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2102,19 +2132,19 @@ def test_delete_topic_from_dict(): @pytest.mark.asyncio -async def test_delete_topic_async(transport: str = "grpc_asyncio"): +async def test_delete_topic_async( + transport: str = "grpc_asyncio", request_type=pubsub.DeleteTopicRequest +): client = PublisherAsyncClient( credentials=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 = pubsub.DeleteTopicRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2124,12 +2154,17 @@ async def test_delete_topic_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.DeleteTopicRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_topic_async_from_dict(): + await test_delete_topic_async(request_type=dict) + + def test_delete_topic_field_headers(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) @@ -2139,7 +2174,7 @@ def test_delete_topic_field_headers(): request.topic = "topic/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_topic), "__call__") as call: + with mock.patch.object(type(client.transport.delete_topic), "__call__") as call: call.return_value = None client.delete_topic(request) @@ -2164,9 +2199,7 @@ async def test_delete_topic_field_headers_async(): request.topic = "topic/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_topic), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_topic(request) @@ -2185,7 +2218,7 @@ def test_delete_topic_flattened(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_topic), "__call__") as call: + with mock.patch.object(type(client.transport.delete_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2217,9 +2250,7 @@ async def test_delete_topic_flattened_async(): client = PublisherAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_topic), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_topic), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2261,7 +2292,7 @@ def test_detach_subscription( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.detach_subscription), "__call__" + type(client.transport.detach_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.DetachSubscriptionResponse() @@ -2275,6 +2306,7 @@ def test_detach_subscription( assert args[0] == pubsub.DetachSubscriptionRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.DetachSubscriptionResponse) @@ -2283,18 +2315,20 @@ def test_detach_subscription_from_dict(): @pytest.mark.asyncio -async def test_detach_subscription_async(transport: str = "grpc_asyncio"): +async def test_detach_subscription_async( + transport: str = "grpc_asyncio", request_type=pubsub.DetachSubscriptionRequest +): client = PublisherAsyncClient( credentials=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 = pubsub.DetachSubscriptionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.detach_subscription), "__call__" + type(client.transport.detach_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2307,12 +2341,17 @@ async def test_detach_subscription_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.DetachSubscriptionRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.DetachSubscriptionResponse) +@pytest.mark.asyncio +async def test_detach_subscription_async_from_dict(): + await test_detach_subscription_async(request_type=dict) + + def test_detach_subscription_field_headers(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) @@ -2323,7 +2362,7 @@ def test_detach_subscription_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.detach_subscription), "__call__" + type(client.transport.detach_subscription), "__call__" ) as call: call.return_value = pubsub.DetachSubscriptionResponse() @@ -2352,7 +2391,7 @@ async def test_detach_subscription_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.detach_subscription), "__call__" + type(client.transport.detach_subscription), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.DetachSubscriptionResponse() @@ -2408,7 +2447,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = PublisherClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -2441,7 +2480,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = PublisherClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.PublisherGrpcTransport,) + assert isinstance(client.transport, transports.PublisherGrpcTransport,) def test_publisher_base_transport_error(): @@ -2555,7 +2594,7 @@ def test_publisher_host_no_port(): api_endpoint="pubsub.googleapis.com" ), ) - assert client._transport._host == "pubsub.googleapis.com:443" + assert client.transport._host == "pubsub.googleapis.com:443" def test_publisher_host_with_port(): @@ -2565,7 +2604,7 @@ def test_publisher_host_with_port(): api_endpoint="pubsub.googleapis.com:8000" ), ) - assert client._transport._host == "pubsub.googleapis.com:8000" + assert client.transport._host == "pubsub.googleapis.com:8000" def test_publisher_grpc_transport_channel(): @@ -2577,6 +2616,7 @@ def test_publisher_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_publisher_grpc_asyncio_transport_channel(): @@ -2588,6 +2628,7 @@ def test_publisher_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -2633,6 +2674,7 @@ def test_publisher_transport_channel_mtls_with_client_cert_source(transport_clas quota_project_id=None, ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -2675,9 +2717,32 @@ def test_publisher_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel -def test_topic_path(): +def test_subscription_path(): project = "squid" - topic = "clam" + subscription = "clam" + + expected = "projects/{project}/subscriptions/{subscription}".format( + project=project, subscription=subscription, + ) + actual = PublisherClient.subscription_path(project, subscription) + assert expected == actual + + +def test_parse_subscription_path(): + expected = { + "project": "whelk", + "subscription": "octopus", + } + path = PublisherClient.subscription_path(**expected) + + # Check that the path construction is reversible. + actual = PublisherClient.parse_subscription_path(path) + assert expected == actual + + +def test_topic_path(): + project = "oyster" + topic = "nudibranch" expected = "projects/{project}/topics/{topic}".format(project=project, topic=topic,) actual = PublisherClient.topic_path(project, topic) @@ -2686,8 +2751,8 @@ def test_topic_path(): def test_parse_topic_path(): expected = { - "project": "whelk", - "topic": "octopus", + "project": "cuttlefish", + "topic": "mussel", } path = PublisherClient.topic_path(**expected) @@ -2696,6 +2761,107 @@ def test_parse_topic_path(): assert expected == actual +def test_common_billing_account_path(): + billing_account = "winkle" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = PublisherClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = PublisherClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = PublisherClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "scallop" + + expected = "folders/{folder}".format(folder=folder,) + actual = PublisherClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = PublisherClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = PublisherClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "squid" + + expected = "organizations/{organization}".format(organization=organization,) + actual = PublisherClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = PublisherClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = PublisherClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "whelk" + + expected = "projects/{project}".format(project=project,) + actual = PublisherClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = PublisherClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = PublisherClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "oyster" + location = "nudibranch" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + actual = PublisherClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = PublisherClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = PublisherClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo() @@ -2727,7 +2893,7 @@ def test_set_iam_policy(transport: str = "grpc"): request = iam_policy.SetIamPolicyRequest() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy(version=774, etag=b"etag_blob",) @@ -2758,9 +2924,7 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): request = iam_policy.SetIamPolicyRequest() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( policy.Policy(version=774, etag=b"etag_blob",) @@ -2791,7 +2955,7 @@ def test_set_iam_policy_field_headers(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.set_iam_policy(request) @@ -2816,9 +2980,7 @@ async def test_set_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.set_iam_policy(request) @@ -2836,7 +2998,7 @@ async def test_set_iam_policy_field_headers_async(): def test_set_iam_policy_from_dict(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -2849,6 +3011,23 @@ def test_set_iam_policy_from_dict(): call.assert_called() +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = PublisherAsyncClient(credentials=credentials.AnonymousCredentials(),) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy.Policy(version=774), + } + ) + call.assert_called() + + def test_get_iam_policy(transport: str = "grpc"): client = PublisherClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -2859,7 +3038,7 @@ def test_get_iam_policy(transport: str = "grpc"): request = iam_policy.GetIamPolicyRequest() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy(version=774, etag=b"etag_blob",) @@ -2890,9 +3069,7 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): request = iam_policy.GetIamPolicyRequest() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( policy.Policy(version=774, etag=b"etag_blob",) @@ -2923,7 +3100,7 @@ def test_get_iam_policy_field_headers(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.get_iam_policy(request) @@ -2948,9 +3125,7 @@ async def test_get_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.get_iam_policy(request) @@ -2968,7 +3143,7 @@ async def test_get_iam_policy_field_headers_async(): def test_get_iam_policy_from_dict(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -2981,6 +3156,23 @@ def test_get_iam_policy_from_dict(): call.assert_called() +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = PublisherAsyncClient(credentials=credentials.AnonymousCredentials(),) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + def test_test_iam_permissions(transport: str = "grpc"): client = PublisherClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -2992,7 +3184,7 @@ def test_test_iam_permissions(transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse( @@ -3025,7 +3217,7 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -3056,7 +3248,7 @@ def test_test_iam_permissions_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = iam_policy.TestIamPermissionsResponse() @@ -3083,7 +3275,7 @@ async def test_test_iam_permissions_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( iam_policy.TestIamPermissionsResponse() @@ -3105,7 +3297,7 @@ def test_test_iam_permissions_from_dict(): client = PublisherClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -3117,3 +3309,24 @@ def test_test_iam_permissions_from_dict(): } ) call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = PublisherAsyncClient(credentials=credentials.AnonymousCredentials(),) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() diff --git a/tests/unit/gapic/pubsub_v1/test_subscriber.py b/tests/unit/gapic/pubsub_v1/test_subscriber.py index 89223117a..f837df651 100644 --- a/tests/unit/gapic/pubsub_v1/test_subscriber.py +++ b/tests/unit/gapic/pubsub_v1/test_subscriber.py @@ -95,12 +95,12 @@ def test_subscriber_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "pubsub.googleapis.com:443" + assert client.transport._host == "pubsub.googleapis.com:443" def test_subscriber_client_get_transport_class(): @@ -443,7 +443,7 @@ def test_create_subscription(transport: str = "grpc", request_type=pubsub.Subscr # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_subscription), "__call__" + type(client.transport.create_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Subscription( @@ -465,6 +465,7 @@ def test_create_subscription(transport: str = "grpc", request_type=pubsub.Subscr assert args[0] == pubsub.Subscription() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.Subscription) assert response.name == "name_value" @@ -487,18 +488,20 @@ def test_create_subscription_from_dict(): @pytest.mark.asyncio -async def test_create_subscription_async(transport: str = "grpc_asyncio"): +async def test_create_subscription_async( + transport: str = "grpc_asyncio", request_type=pubsub.Subscription +): client = SubscriberAsyncClient( credentials=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 = pubsub.Subscription() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_subscription), "__call__" + type(client.transport.create_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -519,7 +522,7 @@ async def test_create_subscription_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.Subscription() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.Subscription) @@ -539,6 +542,11 @@ async def test_create_subscription_async(transport: str = "grpc_asyncio"): assert response.detached is True +@pytest.mark.asyncio +async def test_create_subscription_async_from_dict(): + await test_create_subscription_async(request_type=dict) + + def test_create_subscription_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -549,7 +557,7 @@ def test_create_subscription_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_subscription), "__call__" + type(client.transport.create_subscription), "__call__" ) as call: call.return_value = pubsub.Subscription() @@ -576,7 +584,7 @@ async def test_create_subscription_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_subscription), "__call__" + type(client.transport.create_subscription), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.Subscription()) @@ -597,7 +605,7 @@ def test_create_subscription_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_subscription), "__call__" + type(client.transport.create_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Subscription() @@ -648,7 +656,7 @@ async def test_create_subscription_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_subscription), "__call__" + type(client.transport.create_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Subscription() @@ -707,9 +715,7 @@ def test_get_subscription( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.get_subscription), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_subscription), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Subscription( name="name_value", @@ -730,6 +736,7 @@ def test_get_subscription( assert args[0] == pubsub.GetSubscriptionRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.Subscription) assert response.name == "name_value" @@ -752,19 +759,19 @@ def test_get_subscription_from_dict(): @pytest.mark.asyncio -async def test_get_subscription_async(transport: str = "grpc_asyncio"): +async def test_get_subscription_async( + transport: str = "grpc_asyncio", request_type=pubsub.GetSubscriptionRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.GetSubscriptionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_subscription), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_subscription), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.Subscription( @@ -784,7 +791,7 @@ async def test_get_subscription_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.GetSubscriptionRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.Subscription) @@ -804,6 +811,11 @@ async def test_get_subscription_async(transport: str = "grpc_asyncio"): assert response.detached is True +@pytest.mark.asyncio +async def test_get_subscription_async_from_dict(): + await test_get_subscription_async(request_type=dict) + + def test_get_subscription_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -813,9 +825,7 @@ def test_get_subscription_field_headers(): request.subscription = "subscription/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.get_subscription), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_subscription), "__call__") as call: call.return_value = pubsub.Subscription() client.get_subscription(request) @@ -842,9 +852,7 @@ async def test_get_subscription_field_headers_async(): request.subscription = "subscription/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_subscription), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_subscription), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.Subscription()) await client.get_subscription(request) @@ -865,9 +873,7 @@ def test_get_subscription_flattened(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.get_subscription), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_subscription), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Subscription() @@ -899,9 +905,7 @@ async def test_get_subscription_flattened_async(): client = SubscriberAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_subscription), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_subscription), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Subscription() @@ -943,7 +947,7 @@ def test_update_subscription( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_subscription), "__call__" + type(client.transport.update_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Subscription( @@ -965,6 +969,7 @@ def test_update_subscription( assert args[0] == pubsub.UpdateSubscriptionRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.Subscription) assert response.name == "name_value" @@ -987,18 +992,20 @@ def test_update_subscription_from_dict(): @pytest.mark.asyncio -async def test_update_subscription_async(transport: str = "grpc_asyncio"): +async def test_update_subscription_async( + transport: str = "grpc_asyncio", request_type=pubsub.UpdateSubscriptionRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.UpdateSubscriptionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_subscription), "__call__" + type(client.transport.update_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1019,7 +1026,7 @@ async def test_update_subscription_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.UpdateSubscriptionRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.Subscription) @@ -1039,6 +1046,11 @@ async def test_update_subscription_async(transport: str = "grpc_asyncio"): assert response.detached is True +@pytest.mark.asyncio +async def test_update_subscription_async_from_dict(): + await test_update_subscription_async(request_type=dict) + + def test_update_subscription_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -1049,7 +1061,7 @@ def test_update_subscription_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_subscription), "__call__" + type(client.transport.update_subscription), "__call__" ) as call: call.return_value = pubsub.Subscription() @@ -1079,7 +1091,7 @@ async def test_update_subscription_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_subscription), "__call__" + type(client.transport.update_subscription), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.Subscription()) @@ -1111,7 +1123,7 @@ def test_list_subscriptions( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_subscriptions), "__call__" + type(client.transport.list_subscriptions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListSubscriptionsResponse( @@ -1127,6 +1139,7 @@ def test_list_subscriptions( assert args[0] == pubsub.ListSubscriptionsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSubscriptionsPager) assert response.next_page_token == "next_page_token_value" @@ -1137,18 +1150,20 @@ def test_list_subscriptions_from_dict(): @pytest.mark.asyncio -async def test_list_subscriptions_async(transport: str = "grpc_asyncio"): +async def test_list_subscriptions_async( + transport: str = "grpc_asyncio", request_type=pubsub.ListSubscriptionsRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.ListSubscriptionsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_subscriptions), "__call__" + type(client.transport.list_subscriptions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1161,7 +1176,7 @@ async def test_list_subscriptions_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.ListSubscriptionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListSubscriptionsAsyncPager) @@ -1169,6 +1184,11 @@ async def test_list_subscriptions_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_subscriptions_async_from_dict(): + await test_list_subscriptions_async(request_type=dict) + + def test_list_subscriptions_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -1179,7 +1199,7 @@ def test_list_subscriptions_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_subscriptions), "__call__" + type(client.transport.list_subscriptions), "__call__" ) as call: call.return_value = pubsub.ListSubscriptionsResponse() @@ -1206,7 +1226,7 @@ async def test_list_subscriptions_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_subscriptions), "__call__" + type(client.transport.list_subscriptions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.ListSubscriptionsResponse() @@ -1229,7 +1249,7 @@ def test_list_subscriptions_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_subscriptions), "__call__" + type(client.transport.list_subscriptions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListSubscriptionsResponse() @@ -1263,7 +1283,7 @@ async def test_list_subscriptions_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_subscriptions), "__call__" + type(client.transport.list_subscriptions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListSubscriptionsResponse() @@ -1300,7 +1320,7 @@ def test_list_subscriptions_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_subscriptions), "__call__" + type(client.transport.list_subscriptions), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1340,7 +1360,7 @@ def test_list_subscriptions_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_subscriptions), "__call__" + type(client.transport.list_subscriptions), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1372,7 +1392,7 @@ async def test_list_subscriptions_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_subscriptions), + type(client.transport.list_subscriptions), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1411,7 +1431,7 @@ async def test_list_subscriptions_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_subscriptions), + type(client.transport.list_subscriptions), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1454,7 +1474,7 @@ def test_delete_subscription( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_subscription), "__call__" + type(client.transport.delete_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1476,18 +1496,20 @@ def test_delete_subscription_from_dict(): @pytest.mark.asyncio -async def test_delete_subscription_async(transport: str = "grpc_asyncio"): +async def test_delete_subscription_async( + transport: str = "grpc_asyncio", request_type=pubsub.DeleteSubscriptionRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.DeleteSubscriptionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_subscription), "__call__" + type(client.transport.delete_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1498,12 +1520,17 @@ async def test_delete_subscription_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.DeleteSubscriptionRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_subscription_async_from_dict(): + await test_delete_subscription_async(request_type=dict) + + def test_delete_subscription_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -1514,7 +1541,7 @@ def test_delete_subscription_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_subscription), "__call__" + type(client.transport.delete_subscription), "__call__" ) as call: call.return_value = None @@ -1543,7 +1570,7 @@ async def test_delete_subscription_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_subscription), "__call__" + type(client.transport.delete_subscription), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1566,7 +1593,7 @@ def test_delete_subscription_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_subscription), "__call__" + type(client.transport.delete_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1600,7 +1627,7 @@ async def test_delete_subscription_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_subscription), "__call__" + type(client.transport.delete_subscription), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1643,7 +1670,7 @@ def test_modify_ack_deadline( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.modify_ack_deadline), "__call__" + type(client.transport.modify_ack_deadline), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1665,18 +1692,20 @@ def test_modify_ack_deadline_from_dict(): @pytest.mark.asyncio -async def test_modify_ack_deadline_async(transport: str = "grpc_asyncio"): +async def test_modify_ack_deadline_async( + transport: str = "grpc_asyncio", request_type=pubsub.ModifyAckDeadlineRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.ModifyAckDeadlineRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.modify_ack_deadline), "__call__" + type(client.transport.modify_ack_deadline), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1687,12 +1716,17 @@ async def test_modify_ack_deadline_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.ModifyAckDeadlineRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_modify_ack_deadline_async_from_dict(): + await test_modify_ack_deadline_async(request_type=dict) + + def test_modify_ack_deadline_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -1703,7 +1737,7 @@ def test_modify_ack_deadline_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.modify_ack_deadline), "__call__" + type(client.transport.modify_ack_deadline), "__call__" ) as call: call.return_value = None @@ -1732,7 +1766,7 @@ async def test_modify_ack_deadline_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.modify_ack_deadline), "__call__" + type(client.transport.modify_ack_deadline), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1755,7 +1789,7 @@ def test_modify_ack_deadline_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.modify_ack_deadline), "__call__" + type(client.transport.modify_ack_deadline), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1800,7 +1834,7 @@ async def test_modify_ack_deadline_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.modify_ack_deadline), "__call__" + type(client.transport.modify_ack_deadline), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1851,7 +1885,7 @@ def test_acknowledge(transport: str = "grpc", request_type=pubsub.AcknowledgeReq request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.acknowledge), "__call__") as call: + with mock.patch.object(type(client.transport.acknowledge), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1872,19 +1906,19 @@ def test_acknowledge_from_dict(): @pytest.mark.asyncio -async def test_acknowledge_async(transport: str = "grpc_asyncio"): +async def test_acknowledge_async( + transport: str = "grpc_asyncio", request_type=pubsub.AcknowledgeRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.AcknowledgeRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.acknowledge), "__call__" - ) as call: + with mock.patch.object(type(client.transport.acknowledge), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1894,12 +1928,17 @@ async def test_acknowledge_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.AcknowledgeRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_acknowledge_async_from_dict(): + await test_acknowledge_async(request_type=dict) + + def test_acknowledge_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -1909,7 +1948,7 @@ def test_acknowledge_field_headers(): request.subscription = "subscription/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.acknowledge), "__call__") as call: + with mock.patch.object(type(client.transport.acknowledge), "__call__") as call: call.return_value = None client.acknowledge(request) @@ -1936,9 +1975,7 @@ async def test_acknowledge_field_headers_async(): request.subscription = "subscription/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.acknowledge), "__call__" - ) as call: + with mock.patch.object(type(client.transport.acknowledge), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.acknowledge(request) @@ -1959,7 +1996,7 @@ def test_acknowledge_flattened(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.acknowledge), "__call__") as call: + with mock.patch.object(type(client.transport.acknowledge), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1997,9 +2034,7 @@ async def test_acknowledge_flattened_async(): client = SubscriberAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.acknowledge), "__call__" - ) as call: + with mock.patch.object(type(client.transport.acknowledge), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2044,7 +2079,7 @@ def test_pull(transport: str = "grpc", request_type=pubsub.PullRequest): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.pull), "__call__") as call: + with mock.patch.object(type(client.transport.pull), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.PullResponse() @@ -2057,6 +2092,7 @@ def test_pull(transport: str = "grpc", request_type=pubsub.PullRequest): assert args[0] == pubsub.PullRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.PullResponse) @@ -2065,17 +2101,19 @@ def test_pull_from_dict(): @pytest.mark.asyncio -async def test_pull_async(transport: str = "grpc_asyncio"): +async def test_pull_async( + transport: str = "grpc_asyncio", request_type=pubsub.PullRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.PullRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.pull), "__call__") as call: + with mock.patch.object(type(client.transport.pull), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.PullResponse()) @@ -2085,12 +2123,17 @@ async def test_pull_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.PullRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.PullResponse) +@pytest.mark.asyncio +async def test_pull_async_from_dict(): + await test_pull_async(request_type=dict) + + def test_pull_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -2100,7 +2143,7 @@ def test_pull_field_headers(): request.subscription = "subscription/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.pull), "__call__") as call: + with mock.patch.object(type(client.transport.pull), "__call__") as call: call.return_value = pubsub.PullResponse() client.pull(request) @@ -2127,7 +2170,7 @@ async def test_pull_field_headers_async(): request.subscription = "subscription/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.pull), "__call__") as call: + with mock.patch.object(type(client.transport.pull), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.PullResponse()) await client.pull(request) @@ -2148,7 +2191,7 @@ def test_pull_flattened(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.pull), "__call__") as call: + with mock.patch.object(type(client.transport.pull), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.PullResponse() @@ -2191,7 +2234,7 @@ async def test_pull_flattened_async(): client = SubscriberAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.pull), "__call__") as call: + with mock.patch.object(type(client.transport.pull), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.PullResponse() @@ -2245,7 +2288,7 @@ def test_streaming_pull( requests = [request] # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.streaming_pull), "__call__") as call: + with mock.patch.object(type(client.transport.streaming_pull), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = iter([pubsub.StreamingPullResponse()]) @@ -2267,21 +2310,21 @@ def test_streaming_pull_from_dict(): @pytest.mark.asyncio -async def test_streaming_pull_async(transport: str = "grpc_asyncio"): +async def test_streaming_pull_async( + transport: str = "grpc_asyncio", request_type=pubsub.StreamingPullRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.StreamingPullRequest() + request = request_type() requests = [request] # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.streaming_pull), "__call__" - ) as call: + with mock.patch.object(type(client.transport.streaming_pull), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = mock.Mock(aio.StreamStreamCall, autospec=True) call.return_value.read = mock.AsyncMock( @@ -2301,6 +2344,11 @@ async def test_streaming_pull_async(transport: str = "grpc_asyncio"): assert isinstance(message, pubsub.StreamingPullResponse) +@pytest.mark.asyncio +async def test_streaming_pull_async_from_dict(): + await test_streaming_pull_async(request_type=dict) + + def test_modify_push_config( transport: str = "grpc", request_type=pubsub.ModifyPushConfigRequest ): @@ -2314,7 +2362,7 @@ def test_modify_push_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.modify_push_config), "__call__" + type(client.transport.modify_push_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2336,18 +2384,20 @@ def test_modify_push_config_from_dict(): @pytest.mark.asyncio -async def test_modify_push_config_async(transport: str = "grpc_asyncio"): +async def test_modify_push_config_async( + transport: str = "grpc_asyncio", request_type=pubsub.ModifyPushConfigRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.ModifyPushConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.modify_push_config), "__call__" + type(client.transport.modify_push_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2358,12 +2408,17 @@ async def test_modify_push_config_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.ModifyPushConfigRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_modify_push_config_async_from_dict(): + await test_modify_push_config_async(request_type=dict) + + def test_modify_push_config_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -2374,7 +2429,7 @@ def test_modify_push_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.modify_push_config), "__call__" + type(client.transport.modify_push_config), "__call__" ) as call: call.return_value = None @@ -2403,7 +2458,7 @@ async def test_modify_push_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.modify_push_config), "__call__" + type(client.transport.modify_push_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2426,7 +2481,7 @@ def test_modify_push_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.modify_push_config), "__call__" + type(client.transport.modify_push_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2469,7 +2524,7 @@ async def test_modify_push_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.modify_push_config), "__call__" + type(client.transport.modify_push_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2518,7 +2573,7 @@ def test_get_snapshot(transport: str = "grpc", request_type=pubsub.GetSnapshotRe request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Snapshot(name="name_value", topic="topic_value",) @@ -2531,6 +2586,7 @@ def test_get_snapshot(transport: str = "grpc", request_type=pubsub.GetSnapshotRe assert args[0] == pubsub.GetSnapshotRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.Snapshot) assert response.name == "name_value" @@ -2543,19 +2599,19 @@ def test_get_snapshot_from_dict(): @pytest.mark.asyncio -async def test_get_snapshot_async(transport: str = "grpc_asyncio"): +async def test_get_snapshot_async( + transport: str = "grpc_asyncio", request_type=pubsub.GetSnapshotRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.GetSnapshotRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.Snapshot(name="name_value", topic="topic_value",) @@ -2567,7 +2623,7 @@ async def test_get_snapshot_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.GetSnapshotRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.Snapshot) @@ -2577,6 +2633,11 @@ async def test_get_snapshot_async(transport: str = "grpc_asyncio"): assert response.topic == "topic_value" +@pytest.mark.asyncio +async def test_get_snapshot_async_from_dict(): + await test_get_snapshot_async(request_type=dict) + + def test_get_snapshot_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -2586,7 +2647,7 @@ def test_get_snapshot_field_headers(): request.snapshot = "snapshot/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: call.return_value = pubsub.Snapshot() client.get_snapshot(request) @@ -2611,9 +2672,7 @@ async def test_get_snapshot_field_headers_async(): request.snapshot = "snapshot/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.Snapshot()) await client.get_snapshot(request) @@ -2632,7 +2691,7 @@ def test_get_snapshot_flattened(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Snapshot() @@ -2664,9 +2723,7 @@ async def test_get_snapshot_flattened_async(): client = SubscriberAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Snapshot() @@ -2707,7 +2764,7 @@ def test_list_snapshots( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_snapshots), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListSnapshotsResponse( next_page_token="next_page_token_value", @@ -2722,6 +2779,7 @@ def test_list_snapshots( assert args[0] == pubsub.ListSnapshotsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSnapshotsPager) assert response.next_page_token == "next_page_token_value" @@ -2732,19 +2790,19 @@ def test_list_snapshots_from_dict(): @pytest.mark.asyncio -async def test_list_snapshots_async(transport: str = "grpc_asyncio"): +async def test_list_snapshots_async( + transport: str = "grpc_asyncio", request_type=pubsub.ListSnapshotsRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.ListSnapshotsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_snapshots), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.ListSnapshotsResponse(next_page_token="next_page_token_value",) @@ -2756,7 +2814,7 @@ async def test_list_snapshots_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.ListSnapshotsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListSnapshotsAsyncPager) @@ -2764,6 +2822,11 @@ async def test_list_snapshots_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_snapshots_async_from_dict(): + await test_list_snapshots_async(request_type=dict) + + def test_list_snapshots_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -2773,7 +2836,7 @@ def test_list_snapshots_field_headers(): request.project = "project/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_snapshots), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: call.return_value = pubsub.ListSnapshotsResponse() client.list_snapshots(request) @@ -2798,9 +2861,7 @@ async def test_list_snapshots_field_headers_async(): request.project = "project/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_snapshots), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.ListSnapshotsResponse() ) @@ -2821,7 +2882,7 @@ def test_list_snapshots_flattened(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_snapshots), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListSnapshotsResponse() @@ -2853,9 +2914,7 @@ async def test_list_snapshots_flattened_async(): client = SubscriberAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_snapshots), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.ListSnapshotsResponse() @@ -2890,7 +2949,7 @@ def test_list_snapshots_pager(): client = SubscriberClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_snapshots), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( pubsub.ListSnapshotsResponse( @@ -2924,7 +2983,7 @@ def test_list_snapshots_pages(): client = SubscriberClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_snapshots), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( pubsub.ListSnapshotsResponse( @@ -2951,9 +3010,7 @@ async def test_list_snapshots_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_snapshots), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_snapshots), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2986,9 +3043,7 @@ async def test_list_snapshots_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_snapshots), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_snapshots), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3024,7 +3079,7 @@ def test_create_snapshot( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Snapshot(name="name_value", topic="topic_value",) @@ -3037,6 +3092,7 @@ def test_create_snapshot( assert args[0] == pubsub.CreateSnapshotRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.Snapshot) assert response.name == "name_value" @@ -3049,19 +3105,19 @@ def test_create_snapshot_from_dict(): @pytest.mark.asyncio -async def test_create_snapshot_async(transport: str = "grpc_asyncio"): +async def test_create_snapshot_async( + transport: str = "grpc_asyncio", request_type=pubsub.CreateSnapshotRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.CreateSnapshotRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.Snapshot(name="name_value", topic="topic_value",) @@ -3073,7 +3129,7 @@ async def test_create_snapshot_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.CreateSnapshotRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.Snapshot) @@ -3083,6 +3139,11 @@ async def test_create_snapshot_async(transport: str = "grpc_asyncio"): assert response.topic == "topic_value" +@pytest.mark.asyncio +async def test_create_snapshot_async_from_dict(): + await test_create_snapshot_async(request_type=dict) + + def test_create_snapshot_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -3092,7 +3153,7 @@ def test_create_snapshot_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: call.return_value = pubsub.Snapshot() client.create_snapshot(request) @@ -3117,9 +3178,7 @@ async def test_create_snapshot_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.Snapshot()) await client.create_snapshot(request) @@ -3138,7 +3197,7 @@ def test_create_snapshot_flattened(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Snapshot() @@ -3176,9 +3235,7 @@ async def test_create_snapshot_flattened_async(): client = SubscriberAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Snapshot() @@ -3225,7 +3282,7 @@ def test_update_snapshot( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.update_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.Snapshot(name="name_value", topic="topic_value",) @@ -3238,6 +3295,7 @@ def test_update_snapshot( assert args[0] == pubsub.UpdateSnapshotRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.Snapshot) assert response.name == "name_value" @@ -3250,19 +3308,19 @@ def test_update_snapshot_from_dict(): @pytest.mark.asyncio -async def test_update_snapshot_async(transport: str = "grpc_asyncio"): +async def test_update_snapshot_async( + transport: str = "grpc_asyncio", request_type=pubsub.UpdateSnapshotRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.UpdateSnapshotRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( pubsub.Snapshot(name="name_value", topic="topic_value",) @@ -3274,7 +3332,7 @@ async def test_update_snapshot_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.UpdateSnapshotRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.Snapshot) @@ -3284,6 +3342,11 @@ async def test_update_snapshot_async(transport: str = "grpc_asyncio"): assert response.topic == "topic_value" +@pytest.mark.asyncio +async def test_update_snapshot_async_from_dict(): + await test_update_snapshot_async(request_type=dict) + + def test_update_snapshot_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -3293,7 +3356,7 @@ def test_update_snapshot_field_headers(): request.snapshot.name = "snapshot.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.update_snapshot), "__call__") as call: call.return_value = pubsub.Snapshot() client.update_snapshot(request) @@ -3320,9 +3383,7 @@ async def test_update_snapshot_field_headers_async(): request.snapshot.name = "snapshot.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_snapshot), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.Snapshot()) await client.update_snapshot(request) @@ -3351,7 +3412,7 @@ def test_delete_snapshot( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -3372,19 +3433,19 @@ def test_delete_snapshot_from_dict(): @pytest.mark.asyncio -async def test_delete_snapshot_async(transport: str = "grpc_asyncio"): +async def test_delete_snapshot_async( + transport: str = "grpc_asyncio", request_type=pubsub.DeleteSnapshotRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.DeleteSnapshotRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -3394,12 +3455,17 @@ async def test_delete_snapshot_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.DeleteSnapshotRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_snapshot_async_from_dict(): + await test_delete_snapshot_async(request_type=dict) + + def test_delete_snapshot_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -3409,7 +3475,7 @@ def test_delete_snapshot_field_headers(): request.snapshot = "snapshot/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: call.return_value = None client.delete_snapshot(request) @@ -3434,9 +3500,7 @@ async def test_delete_snapshot_field_headers_async(): request.snapshot = "snapshot/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_snapshot(request) @@ -3455,7 +3519,7 @@ def test_delete_snapshot_flattened(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_snapshot), "__call__") as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -3487,9 +3551,7 @@ async def test_delete_snapshot_flattened_async(): client = SubscriberAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_snapshot), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -3528,7 +3590,7 @@ def test_seek(transport: str = "grpc", request_type=pubsub.SeekRequest): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.seek), "__call__") as call: + with mock.patch.object(type(client.transport.seek), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = pubsub.SeekResponse() @@ -3541,6 +3603,7 @@ def test_seek(transport: str = "grpc", request_type=pubsub.SeekRequest): assert args[0] == pubsub.SeekRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pubsub.SeekResponse) @@ -3549,17 +3612,19 @@ def test_seek_from_dict(): @pytest.mark.asyncio -async def test_seek_async(transport: str = "grpc_asyncio"): +async def test_seek_async( + transport: str = "grpc_asyncio", request_type=pubsub.SeekRequest +): client = SubscriberAsyncClient( credentials=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 = pubsub.SeekRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.seek), "__call__") as call: + with mock.patch.object(type(client.transport.seek), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.SeekResponse()) @@ -3569,12 +3634,17 @@ async def test_seek_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == pubsub.SeekRequest() # Establish that the response is the type that we expect. assert isinstance(response, pubsub.SeekResponse) +@pytest.mark.asyncio +async def test_seek_async_from_dict(): + await test_seek_async(request_type=dict) + + def test_seek_field_headers(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) @@ -3584,7 +3654,7 @@ def test_seek_field_headers(): request.subscription = "subscription/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.seek), "__call__") as call: + with mock.patch.object(type(client.transport.seek), "__call__") as call: call.return_value = pubsub.SeekResponse() client.seek(request) @@ -3611,7 +3681,7 @@ async def test_seek_field_headers_async(): request.subscription = "subscription/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.seek), "__call__") as call: + with mock.patch.object(type(client.transport.seek), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(pubsub.SeekResponse()) await client.seek(request) @@ -3664,7 +3734,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = SubscriberClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -3697,7 +3767,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.SubscriberGrpcTransport,) + assert isinstance(client.transport, transports.SubscriberGrpcTransport,) def test_subscriber_base_transport_error(): @@ -3818,7 +3888,7 @@ def test_subscriber_host_no_port(): api_endpoint="pubsub.googleapis.com" ), ) - assert client._transport._host == "pubsub.googleapis.com:443" + assert client.transport._host == "pubsub.googleapis.com:443" def test_subscriber_host_with_port(): @@ -3828,7 +3898,7 @@ def test_subscriber_host_with_port(): api_endpoint="pubsub.googleapis.com:8000" ), ) - assert client._transport._host == "pubsub.googleapis.com:8000" + assert client.transport._host == "pubsub.googleapis.com:8000" def test_subscriber_grpc_transport_channel(): @@ -3840,6 +3910,7 @@ def test_subscriber_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_subscriber_grpc_asyncio_transport_channel(): @@ -3851,6 +3922,7 @@ def test_subscriber_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -3896,6 +3968,7 @@ def test_subscriber_transport_channel_mtls_with_client_cert_source(transport_cla quota_project_id=None, ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -3962,8 +4035,8 @@ def test_parse_snapshot_path(): def test_subscription_path(): - project = "squid" - subscription = "clam" + project = "oyster" + subscription = "nudibranch" expected = "projects/{project}/subscriptions/{subscription}".format( project=project, subscription=subscription, @@ -3974,8 +4047,8 @@ def test_subscription_path(): def test_parse_subscription_path(): expected = { - "project": "whelk", - "subscription": "octopus", + "project": "cuttlefish", + "subscription": "mussel", } path = SubscriberClient.subscription_path(**expected) @@ -3984,6 +4057,128 @@ def test_parse_subscription_path(): assert expected == actual +def test_topic_path(): + project = "winkle" + topic = "nautilus" + + expected = "projects/{project}/topics/{topic}".format(project=project, topic=topic,) + actual = SubscriberClient.topic_path(project, topic) + assert expected == actual + + +def test_parse_topic_path(): + expected = { + "project": "scallop", + "topic": "abalone", + } + path = SubscriberClient.topic_path(**expected) + + # Check that the path construction is reversible. + actual = SubscriberClient.parse_topic_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "squid" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = SubscriberClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = SubscriberClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = SubscriberClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "whelk" + + expected = "folders/{folder}".format(folder=folder,) + actual = SubscriberClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = SubscriberClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = SubscriberClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "oyster" + + expected = "organizations/{organization}".format(organization=organization,) + actual = SubscriberClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = SubscriberClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = SubscriberClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "cuttlefish" + + expected = "projects/{project}".format(project=project,) + actual = SubscriberClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = SubscriberClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = SubscriberClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + actual = SubscriberClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = SubscriberClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = SubscriberClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo() @@ -4015,7 +4210,7 @@ def test_set_iam_policy(transport: str = "grpc"): request = iam_policy.SetIamPolicyRequest() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy(version=774, etag=b"etag_blob",) @@ -4046,9 +4241,7 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): request = iam_policy.SetIamPolicyRequest() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( policy.Policy(version=774, etag=b"etag_blob",) @@ -4079,7 +4272,7 @@ def test_set_iam_policy_field_headers(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.set_iam_policy(request) @@ -4104,9 +4297,7 @@ async def test_set_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.set_iam_policy(request) @@ -4124,7 +4315,7 @@ async def test_set_iam_policy_field_headers_async(): def test_set_iam_policy_from_dict(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -4137,6 +4328,23 @@ def test_set_iam_policy_from_dict(): call.assert_called() +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = SubscriberAsyncClient(credentials=credentials.AnonymousCredentials(),) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy.Policy(version=774), + } + ) + call.assert_called() + + def test_get_iam_policy(transport: str = "grpc"): client = SubscriberClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -4147,7 +4355,7 @@ def test_get_iam_policy(transport: str = "grpc"): request = iam_policy.GetIamPolicyRequest() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy(version=774, etag=b"etag_blob",) @@ -4178,9 +4386,7 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): request = iam_policy.GetIamPolicyRequest() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( policy.Policy(version=774, etag=b"etag_blob",) @@ -4211,7 +4417,7 @@ def test_get_iam_policy_field_headers(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.get_iam_policy(request) @@ -4236,9 +4442,7 @@ async def test_get_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.get_iam_policy(request) @@ -4256,7 +4460,7 @@ async def test_get_iam_policy_field_headers_async(): def test_get_iam_policy_from_dict(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -4269,6 +4473,23 @@ def test_get_iam_policy_from_dict(): call.assert_called() +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = SubscriberAsyncClient(credentials=credentials.AnonymousCredentials(),) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + def test_test_iam_permissions(transport: str = "grpc"): client = SubscriberClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -4280,7 +4501,7 @@ def test_test_iam_permissions(transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse( @@ -4313,7 +4534,7 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4344,7 +4565,7 @@ def test_test_iam_permissions_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = iam_policy.TestIamPermissionsResponse() @@ -4371,7 +4592,7 @@ async def test_test_iam_permissions_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( iam_policy.TestIamPermissionsResponse() @@ -4393,7 +4614,7 @@ def test_test_iam_permissions_from_dict(): client = SubscriberClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -4405,3 +4626,24 @@ def test_test_iam_permissions_from_dict(): } ) call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = SubscriberAsyncClient(credentials=credentials.AnonymousCredentials(),) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called()