diff --git a/google/cloud/tasks_v2/services/cloud_tasks/async_client.py b/google/cloud/tasks_v2/services/cloud_tasks/async_client.py index 11bc924e..310f75a7 100644 --- a/google/cloud/tasks_v2/services/cloud_tasks/async_client.py +++ b/google/cloud/tasks_v2/services/cloud_tasks/async_client.py @@ -84,8 +84,36 @@ class CloudTasksAsyncClient: CloudTasksClient.parse_common_location_path ) - from_service_account_info = CloudTasksClient.from_service_account_info - from_service_account_file = CloudTasksClient.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudTasksAsyncClient: The constructed client. + """ + return CloudTasksClient.from_service_account_info.__func__(CloudTasksAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudTasksAsyncClient: The constructed client. + """ + return CloudTasksClient.from_service_account_file.__func__(CloudTasksAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -217,6 +245,7 @@ async def list_queues( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=DEFAULT_CLIENT_INFO, @@ -308,6 +337,7 @@ async def get_queue( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=DEFAULT_CLIENT_INFO, @@ -610,6 +640,7 @@ async def delete_queue( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=DEFAULT_CLIENT_INFO, @@ -1010,6 +1041,7 @@ async def get_iam_policy( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=DEFAULT_CLIENT_INFO, @@ -1251,6 +1283,7 @@ async def test_iam_permissions( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=DEFAULT_CLIENT_INFO, @@ -1345,6 +1378,7 @@ async def list_tasks( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=DEFAULT_CLIENT_INFO, @@ -1431,6 +1465,7 @@ async def get_task( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=DEFAULT_CLIENT_INFO, @@ -1637,6 +1672,7 @@ async def delete_task( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/google/cloud/tasks_v2/services/cloud_tasks/client.py b/google/cloud/tasks_v2/services/cloud_tasks/client.py index 7015960a..27eaec4f 100644 --- a/google/cloud/tasks_v2/services/cloud_tasks/client.py +++ b/google/cloud/tasks_v2/services/cloud_tasks/client.py @@ -1195,13 +1195,13 @@ def get_iam_policy( "the individual field arguments should be set." ) - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. request = iam_policy.GetIamPolicyRequest(**request) - elif not request: - request = iam_policy.GetIamPolicyRequest(resource=resource,) + # Null request, just make one. + request = iam_policy.GetIamPolicyRequest() if resource is not None: request.resource = resource @@ -1334,13 +1334,13 @@ def set_iam_policy( "the individual field arguments should be set." ) - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. request = iam_policy.SetIamPolicyRequest(**request) - elif not request: - request = iam_policy.SetIamPolicyRequest(resource=resource,) + # Null request, just make one. + request = iam_policy.SetIamPolicyRequest() if resource is not None: request.resource = resource @@ -1424,19 +1424,20 @@ def test_iam_permissions( "the individual field arguments should be set." ) - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. request = iam_policy.TestIamPermissionsRequest(**request) - elif not request: - request = iam_policy.TestIamPermissionsRequest( - resource=resource, permissions=permissions, - ) + # Null request, just make one. + request = iam_policy.TestIamPermissionsRequest() if resource is not None: request.resource = resource + if permissions: + request.permissions.extend(permissions) + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] diff --git a/google/cloud/tasks_v2/services/cloud_tasks/transports/base.py b/google/cloud/tasks_v2/services/cloud_tasks/transports/base.py index 6ba5f065..3eebbca7 100644 --- a/google/cloud/tasks_v2/services/cloud_tasks/transports/base.py +++ b/google/cloud/tasks_v2/services/cloud_tasks/transports/base.py @@ -74,10 +74,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. 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. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -85,6 +85,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -94,20 +97,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -120,6 +120,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=client_info, @@ -133,6 +134,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=client_info, @@ -152,6 +154,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=client_info, @@ -174,6 +177,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=client_info, @@ -190,6 +194,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=client_info, @@ -203,6 +208,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=client_info, @@ -216,6 +222,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=client_info, @@ -232,6 +239,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=10.0, ), default_timeout=10.0, client_info=client_info, diff --git a/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py b/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py index c6fa24ef..dd6b2f98 100644 --- a/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py +++ b/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py @@ -114,7 +114,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -122,70 +124,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -193,17 +175,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -217,7 +190,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py b/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py index aab98e3a..8a61e1c8 100644 --- a/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py +++ b/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -147,10 +147,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` 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: @@ -159,7 +159,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -167,70 +169,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -238,17 +220,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/tasks_v2/types/__init__.py b/google/cloud/tasks_v2/types/__init__.py index dabf6553..c8b98c98 100644 --- a/google/cloud/tasks_v2/types/__init__.py +++ b/google/cloud/tasks_v2/types/__init__.py @@ -15,13 +15,22 @@ # limitations under the License. # -from .target import ( - HttpRequest, - AppEngineHttpRequest, - AppEngineRouting, - OAuthToken, - OidcToken, - HttpMethod, +from .cloudtasks import ( + CreateQueueRequest, + CreateTaskRequest, + DeleteQueueRequest, + DeleteTaskRequest, + GetQueueRequest, + GetTaskRequest, + ListQueuesRequest, + ListQueuesResponse, + ListTasksRequest, + ListTasksResponse, + PauseQueueRequest, + PurgeQueueRequest, + ResumeQueueRequest, + RunTaskRequest, + UpdateQueueRequest, ) from .queue import ( Queue, @@ -29,54 +38,45 @@ RetryConfig, StackdriverLoggingConfig, ) +from .target import ( + AppEngineHttpRequest, + AppEngineRouting, + HttpRequest, + OAuthToken, + OidcToken, + HttpMethod, +) from .task import ( - Task, Attempt, -) -from .cloudtasks import ( - ListQueuesRequest, - ListQueuesResponse, - GetQueueRequest, - CreateQueueRequest, - UpdateQueueRequest, - DeleteQueueRequest, - PurgeQueueRequest, - PauseQueueRequest, - ResumeQueueRequest, - ListTasksRequest, - ListTasksResponse, - GetTaskRequest, - CreateTaskRequest, - DeleteTaskRequest, - RunTaskRequest, + Task, ) __all__ = ( - "HttpRequest", + "CreateQueueRequest", + "CreateTaskRequest", + "DeleteQueueRequest", + "DeleteTaskRequest", + "GetQueueRequest", + "GetTaskRequest", + "ListQueuesRequest", + "ListQueuesResponse", + "ListTasksRequest", + "ListTasksResponse", + "PauseQueueRequest", + "PurgeQueueRequest", + "ResumeQueueRequest", + "RunTaskRequest", + "UpdateQueueRequest", + "Queue", + "RateLimits", + "RetryConfig", + "StackdriverLoggingConfig", "AppEngineHttpRequest", "AppEngineRouting", + "HttpRequest", "OAuthToken", "OidcToken", "HttpMethod", - "Queue", - "RateLimits", - "RetryConfig", - "StackdriverLoggingConfig", - "Task", "Attempt", - "ListQueuesRequest", - "ListQueuesResponse", - "GetQueueRequest", - "CreateQueueRequest", - "UpdateQueueRequest", - "DeleteQueueRequest", - "PurgeQueueRequest", - "PauseQueueRequest", - "ResumeQueueRequest", - "ListTasksRequest", - "ListTasksResponse", - "GetTaskRequest", - "CreateTaskRequest", - "DeleteTaskRequest", - "RunTaskRequest", + "Task", ) diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/async_client.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/async_client.py index dfd2f03e..1210af20 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/async_client.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/async_client.py @@ -84,8 +84,36 @@ class CloudTasksAsyncClient: CloudTasksClient.parse_common_location_path ) - from_service_account_info = CloudTasksClient.from_service_account_info - from_service_account_file = CloudTasksClient.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudTasksAsyncClient: The constructed client. + """ + return CloudTasksClient.from_service_account_info.__func__(CloudTasksAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudTasksAsyncClient: The constructed client. + """ + return CloudTasksClient.from_service_account_file.__func__(CloudTasksAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -217,6 +245,7 @@ async def list_queues( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -308,6 +337,7 @@ async def get_queue( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -611,6 +641,7 @@ async def delete_queue( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -1011,6 +1042,7 @@ async def get_iam_policy( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -1252,6 +1284,7 @@ async def test_iam_permissions( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -1346,6 +1379,7 @@ async def list_tasks( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -1432,6 +1466,7 @@ async def get_task( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -1642,6 +1677,7 @@ async def delete_task( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/client.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/client.py index 47a1a809..38bf6e13 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/client.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/client.py @@ -1196,13 +1196,13 @@ def get_iam_policy( "the individual field arguments should be set." ) - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. request = iam_policy.GetIamPolicyRequest(**request) - elif not request: - request = iam_policy.GetIamPolicyRequest(resource=resource,) + # Null request, just make one. + request = iam_policy.GetIamPolicyRequest() if resource is not None: request.resource = resource @@ -1335,13 +1335,13 @@ def set_iam_policy( "the individual field arguments should be set." ) - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. request = iam_policy.SetIamPolicyRequest(**request) - elif not request: - request = iam_policy.SetIamPolicyRequest(resource=resource,) + # Null request, just make one. + request = iam_policy.SetIamPolicyRequest() if resource is not None: request.resource = resource @@ -1425,19 +1425,20 @@ def test_iam_permissions( "the individual field arguments should be set." ) - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. request = iam_policy.TestIamPermissionsRequest(**request) - elif not request: - request = iam_policy.TestIamPermissionsRequest( - resource=resource, permissions=permissions, - ) + # Null request, just make one. + request = iam_policy.TestIamPermissionsRequest() if resource is not None: request.resource = resource + if permissions: + request.permissions.extend(permissions) + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/base.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/base.py index eecfe295..ac530ed8 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/base.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/base.py @@ -74,10 +74,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. 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. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -85,6 +85,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -94,20 +97,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -120,6 +120,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -133,6 +134,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -152,6 +154,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -174,6 +177,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -190,6 +194,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -203,6 +208,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -216,6 +222,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -232,6 +239,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc.py index 5534bead..85663fa6 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc.py @@ -114,7 +114,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -122,70 +124,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -193,17 +175,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -217,7 +190,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc_asyncio.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc_asyncio.py index 3fe7a075..85a00e7c 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc_asyncio.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -147,10 +147,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` 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: @@ -159,7 +159,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -167,70 +169,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -238,17 +220,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/tasks_v2beta2/types/__init__.py b/google/cloud/tasks_v2beta2/types/__init__.py index 7407d142..5389b7fc 100644 --- a/google/cloud/tasks_v2beta2/types/__init__.py +++ b/google/cloud/tasks_v2beta2/types/__init__.py @@ -15,80 +15,80 @@ # limitations under the License. # -from .target import ( - PullTarget, - PullMessage, - AppEngineHttpTarget, - AppEngineHttpRequest, - AppEngineRouting, - HttpMethod, +from .cloudtasks import ( + AcknowledgeTaskRequest, + CancelLeaseRequest, + CreateQueueRequest, + CreateTaskRequest, + DeleteQueueRequest, + DeleteTaskRequest, + GetQueueRequest, + GetTaskRequest, + LeaseTasksRequest, + LeaseTasksResponse, + ListQueuesRequest, + ListQueuesResponse, + ListTasksRequest, + ListTasksResponse, + PauseQueueRequest, + PurgeQueueRequest, + RenewLeaseRequest, + ResumeQueueRequest, + RunTaskRequest, + UpdateQueueRequest, ) from .queue import ( Queue, + QueueStats, RateLimits, RetryConfig, - QueueStats, +) +from .target import ( + AppEngineHttpRequest, + AppEngineHttpTarget, + AppEngineRouting, + PullMessage, + PullTarget, + HttpMethod, ) from .task import ( + AttemptStatus, Task, TaskStatus, - AttemptStatus, -) -from .cloudtasks import ( - ListQueuesRequest, - ListQueuesResponse, - GetQueueRequest, - CreateQueueRequest, - UpdateQueueRequest, - DeleteQueueRequest, - PurgeQueueRequest, - PauseQueueRequest, - ResumeQueueRequest, - ListTasksRequest, - ListTasksResponse, - GetTaskRequest, - CreateTaskRequest, - DeleteTaskRequest, - LeaseTasksRequest, - LeaseTasksResponse, - AcknowledgeTaskRequest, - RenewLeaseRequest, - CancelLeaseRequest, - RunTaskRequest, ) __all__ = ( - "PullTarget", - "PullMessage", - "AppEngineHttpTarget", - "AppEngineHttpRequest", - "AppEngineRouting", - "HttpMethod", - "Queue", - "RateLimits", - "RetryConfig", - "QueueStats", - "Task", - "TaskStatus", - "AttemptStatus", - "ListQueuesRequest", - "ListQueuesResponse", - "GetQueueRequest", + "AcknowledgeTaskRequest", + "CancelLeaseRequest", "CreateQueueRequest", - "UpdateQueueRequest", - "DeleteQueueRequest", - "PurgeQueueRequest", - "PauseQueueRequest", - "ResumeQueueRequest", - "ListTasksRequest", - "ListTasksResponse", - "GetTaskRequest", "CreateTaskRequest", + "DeleteQueueRequest", "DeleteTaskRequest", + "GetQueueRequest", + "GetTaskRequest", "LeaseTasksRequest", "LeaseTasksResponse", - "AcknowledgeTaskRequest", + "ListQueuesRequest", + "ListQueuesResponse", + "ListTasksRequest", + "ListTasksResponse", + "PauseQueueRequest", + "PurgeQueueRequest", "RenewLeaseRequest", - "CancelLeaseRequest", + "ResumeQueueRequest", "RunTaskRequest", + "UpdateQueueRequest", + "Queue", + "QueueStats", + "RateLimits", + "RetryConfig", + "AppEngineHttpRequest", + "AppEngineHttpTarget", + "AppEngineRouting", + "PullMessage", + "PullTarget", + "HttpMethod", + "AttemptStatus", + "Task", + "TaskStatus", ) diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/async_client.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/async_client.py index 2107df3f..10eb3d9c 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/async_client.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/async_client.py @@ -84,8 +84,36 @@ class CloudTasksAsyncClient: CloudTasksClient.parse_common_location_path ) - from_service_account_info = CloudTasksClient.from_service_account_info - from_service_account_file = CloudTasksClient.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudTasksAsyncClient: The constructed client. + """ + return CloudTasksClient.from_service_account_info.__func__(CloudTasksAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudTasksAsyncClient: The constructed client. + """ + return CloudTasksClient.from_service_account_file.__func__(CloudTasksAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -217,6 +245,7 @@ async def list_queues( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -308,6 +337,7 @@ async def get_queue( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -611,6 +641,7 @@ async def delete_queue( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -1011,6 +1042,7 @@ async def get_iam_policy( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -1252,6 +1284,7 @@ async def test_iam_permissions( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -1346,6 +1379,7 @@ async def list_tasks( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -1432,6 +1466,7 @@ async def get_task( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, @@ -1638,6 +1673,7 @@ async def delete_task( predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/client.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/client.py index 0dd8eacd..47133372 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/client.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/client.py @@ -1196,13 +1196,13 @@ def get_iam_policy( "the individual field arguments should be set." ) - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. request = iam_policy.GetIamPolicyRequest(**request) - elif not request: - request = iam_policy.GetIamPolicyRequest(resource=resource,) + # Null request, just make one. + request = iam_policy.GetIamPolicyRequest() if resource is not None: request.resource = resource @@ -1335,13 +1335,13 @@ def set_iam_policy( "the individual field arguments should be set." ) - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. request = iam_policy.SetIamPolicyRequest(**request) - elif not request: - request = iam_policy.SetIamPolicyRequest(resource=resource,) + # Null request, just make one. + request = iam_policy.SetIamPolicyRequest() if resource is not None: request.resource = resource @@ -1425,19 +1425,20 @@ def test_iam_permissions( "the individual field arguments should be set." ) - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. request = iam_policy.TestIamPermissionsRequest(**request) - elif not request: - request = iam_policy.TestIamPermissionsRequest( - resource=resource, permissions=permissions, - ) + # Null request, just make one. + request = iam_policy.TestIamPermissionsRequest() if resource is not None: request.resource = resource + if permissions: + request.permissions.extend(permissions) + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/base.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/base.py index d5c25b51..8741faa1 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/base.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/base.py @@ -74,10 +74,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. 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. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -85,6 +85,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -94,20 +97,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -120,6 +120,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -133,6 +134,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -152,6 +154,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -174,6 +177,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -190,6 +194,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -203,6 +208,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -216,6 +222,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, @@ -232,6 +239,7 @@ def _prep_wrapped_messages(self, client_info): predicate=retries.if_exception_type( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), + deadline=20.0, ), default_timeout=20.0, client_info=client_info, diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc.py index fe4b8a2b..5af1d958 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc.py @@ -114,7 +114,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -122,70 +124,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -193,17 +175,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -217,7 +190,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc_asyncio.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc_asyncio.py index 8b5c85db..fb93d3fb 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc_asyncio.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -147,10 +147,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` 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: @@ -159,7 +159,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -167,70 +169,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -238,17 +220,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/tasks_v2beta3/types/__init__.py b/google/cloud/tasks_v2beta3/types/__init__.py index 1e26bdf8..a7d2e191 100644 --- a/google/cloud/tasks_v2beta3/types/__init__.py +++ b/google/cloud/tasks_v2beta3/types/__init__.py @@ -15,74 +15,74 @@ # limitations under the License. # +from .cloudtasks import ( + CreateQueueRequest, + CreateTaskRequest, + DeleteQueueRequest, + DeleteTaskRequest, + GetQueueRequest, + GetTaskRequest, + ListQueuesRequest, + ListQueuesResponse, + ListTasksRequest, + ListTasksResponse, + PauseQueueRequest, + PurgeQueueRequest, + ResumeQueueRequest, + RunTaskRequest, + UpdateQueueRequest, +) +from .queue import ( + Queue, + QueueStats, + RateLimits, + RetryConfig, + StackdriverLoggingConfig, +) from .target import ( - PullMessage, - HttpRequest, AppEngineHttpQueue, AppEngineHttpRequest, AppEngineRouting, + HttpRequest, OAuthToken, OidcToken, + PullMessage, HttpMethod, ) -from .queue import ( - Queue, - RateLimits, - RetryConfig, - StackdriverLoggingConfig, - QueueStats, -) from .task import ( - Task, Attempt, -) -from .cloudtasks import ( - ListQueuesRequest, - ListQueuesResponse, - GetQueueRequest, - CreateQueueRequest, - UpdateQueueRequest, - DeleteQueueRequest, - PurgeQueueRequest, - PauseQueueRequest, - ResumeQueueRequest, - ListTasksRequest, - ListTasksResponse, - GetTaskRequest, - CreateTaskRequest, - DeleteTaskRequest, - RunTaskRequest, + Task, ) __all__ = ( - "PullMessage", - "HttpRequest", + "CreateQueueRequest", + "CreateTaskRequest", + "DeleteQueueRequest", + "DeleteTaskRequest", + "GetQueueRequest", + "GetTaskRequest", + "ListQueuesRequest", + "ListQueuesResponse", + "ListTasksRequest", + "ListTasksResponse", + "PauseQueueRequest", + "PurgeQueueRequest", + "ResumeQueueRequest", + "RunTaskRequest", + "UpdateQueueRequest", + "Queue", + "QueueStats", + "RateLimits", + "RetryConfig", + "StackdriverLoggingConfig", "AppEngineHttpQueue", "AppEngineHttpRequest", "AppEngineRouting", + "HttpRequest", "OAuthToken", "OidcToken", + "PullMessage", "HttpMethod", - "Queue", - "RateLimits", - "RetryConfig", - "StackdriverLoggingConfig", - "QueueStats", - "Task", "Attempt", - "ListQueuesRequest", - "ListQueuesResponse", - "GetQueueRequest", - "CreateQueueRequest", - "UpdateQueueRequest", - "DeleteQueueRequest", - "PurgeQueueRequest", - "PauseQueueRequest", - "ResumeQueueRequest", - "ListTasksRequest", - "ListTasksResponse", - "GetTaskRequest", - "CreateTaskRequest", - "DeleteTaskRequest", - "RunTaskRequest", + "Task", ) diff --git a/synth.metadata b/synth.metadata index cf3a65c1..935e01c0 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-tasks.git", - "sha": "e4865024dd3acf6a8f7e64712f19f5369ee30202" + "sha": "c653f489f453b562c7076816981d8541ba84a029" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "eabec5a21219401bad79e1cc7d900c1658aee5fd", - "internalRef": "359130387" + "sha": "149a3a84c29c9b8189576c7442ccb6dcf6a8f95b", + "internalRef": "364411656" } }, { diff --git a/tests/unit/gapic/tasks_v2/__init__.py b/tests/unit/gapic/tasks_v2/__init__.py index 8b137891..42ffdf2b 100644 --- a/tests/unit/gapic/tasks_v2/__init__.py +++ b/tests/unit/gapic/tasks_v2/__init__.py @@ -1 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/tasks_v2/test_cloud_tasks.py b/tests/unit/gapic/tasks_v2/test_cloud_tasks.py index 573bfa7b..539f3042 100644 --- a/tests/unit/gapic/tasks_v2/test_cloud_tasks.py +++ b/tests/unit/gapic/tasks_v2/test_cloud_tasks.py @@ -95,15 +95,17 @@ def test__get_default_mtls_endpoint(): assert CloudTasksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -def test_cloud_tasks_client_from_service_account_info(): +@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient,]) +def test_cloud_tasks_client_from_service_account_info(client_class): creds = credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = CloudTasksClient.from_service_account_info(info) + client = client_class.from_service_account_info(info) assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "cloudtasks.googleapis.com:443" @@ -117,9 +119,11 @@ def test_cloud_tasks_client_from_service_account_file(client_class): factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "cloudtasks.googleapis.com:443" @@ -476,6 +480,22 @@ def test_list_queues_from_dict(): test_list_queues(request_type=dict) +def test_list_queues_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_queues), "__call__") as call: + client.list_queues() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.ListQueuesRequest() + + @pytest.mark.asyncio async def test_list_queues_async( transport: str = "grpc_asyncio", request_type=cloudtasks.ListQueuesRequest @@ -783,6 +803,22 @@ def test_get_queue_from_dict(): test_get_queue(request_type=dict) +def test_get_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_queue), "__call__") as call: + client.get_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.GetQueueRequest() + + @pytest.mark.asyncio async def test_get_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.GetQueueRequest @@ -976,6 +1012,22 @@ def test_create_queue_from_dict(): test_create_queue(request_type=dict) +def test_create_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_queue), "__call__") as call: + client.create_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.CreateQueueRequest() + + @pytest.mark.asyncio async def test_create_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.CreateQueueRequest @@ -1181,6 +1233,22 @@ def test_update_queue_from_dict(): test_update_queue(request_type=dict) +def test_update_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_queue), "__call__") as call: + client.update_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.UpdateQueueRequest() + + @pytest.mark.asyncio async def test_update_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.UpdateQueueRequest @@ -1381,6 +1449,22 @@ def test_delete_queue_from_dict(): test_delete_queue(request_type=dict) +def test_delete_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_queue), "__call__") as call: + client.delete_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.DeleteQueueRequest() + + @pytest.mark.asyncio async def test_delete_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.DeleteQueueRequest @@ -1568,6 +1652,22 @@ def test_purge_queue_from_dict(): test_purge_queue(request_type=dict) +def test_purge_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_queue), "__call__") as call: + client.purge_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.PurgeQueueRequest() + + @pytest.mark.asyncio async def test_purge_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.PurgeQueueRequest @@ -1761,6 +1861,22 @@ def test_pause_queue_from_dict(): test_pause_queue(request_type=dict) +def test_pause_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.pause_queue), "__call__") as call: + client.pause_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.PauseQueueRequest() + + @pytest.mark.asyncio async def test_pause_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.PauseQueueRequest @@ -1954,6 +2070,22 @@ def test_resume_queue_from_dict(): test_resume_queue(request_type=dict) +def test_resume_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.resume_queue), "__call__") as call: + client.resume_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.ResumeQueueRequest() + + @pytest.mark.asyncio async def test_resume_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.ResumeQueueRequest @@ -2145,6 +2277,22 @@ def test_get_iam_policy_from_dict(): test_get_iam_policy(request_type=dict) +def test_get_iam_policy_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # 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: + client.get_iam_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == iam_policy.GetIamPolicyRequest() + + @pytest.mark.asyncio async def test_get_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy.GetIamPolicyRequest @@ -2352,6 +2500,22 @@ def test_set_iam_policy_from_dict(): test_set_iam_policy(request_type=dict) +def test_set_iam_policy_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # 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: + client.set_iam_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == iam_policy.SetIamPolicyRequest() + + @pytest.mark.asyncio async def test_set_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy.SetIamPolicyRequest @@ -2561,6 +2725,24 @@ def test_test_iam_permissions_from_dict(): test_test_iam_permissions(request_type=dict) +def test_test_iam_permissions_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # 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: + client.test_iam_permissions() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == iam_policy.TestIamPermissionsRequest() + + @pytest.mark.asyncio async def test_test_iam_permissions_async( transport: str = "grpc_asyncio", request_type=iam_policy.TestIamPermissionsRequest @@ -2792,6 +2974,22 @@ def test_list_tasks_from_dict(): test_list_tasks(request_type=dict) +def test_list_tasks_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_tasks), "__call__") as call: + client.list_tasks() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.ListTasksRequest() + + @pytest.mark.asyncio async def test_list_tasks_async( transport: str = "grpc_asyncio", request_type=cloudtasks.ListTasksRequest @@ -3097,6 +3295,22 @@ def test_get_task_from_dict(): test_get_task(request_type=dict) +def test_get_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_task), "__call__") as call: + client.get_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.GetTaskRequest() + + @pytest.mark.asyncio async def test_get_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.GetTaskRequest @@ -3309,6 +3523,22 @@ def test_create_task_from_dict(): test_create_task(request_type=dict) +def test_create_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_task), "__call__") as call: + client.create_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.CreateTaskRequest() + + @pytest.mark.asyncio async def test_create_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.CreateTaskRequest @@ -3516,6 +3746,22 @@ def test_delete_task_from_dict(): test_delete_task(request_type=dict) +def test_delete_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_task), "__call__") as call: + client.delete_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.DeleteTaskRequest() + + @pytest.mark.asyncio async def test_delete_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.DeleteTaskRequest @@ -3711,6 +3957,22 @@ def test_run_task_from_dict(): test_run_task(request_type=dict) +def test_run_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.run_task), "__call__") as call: + client.run_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.RunTaskRequest() + + @pytest.mark.asyncio async def test_run_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.RunTaskRequest diff --git a/tests/unit/gapic/tasks_v2beta2/__init__.py b/tests/unit/gapic/tasks_v2beta2/__init__.py index 8b137891..42ffdf2b 100644 --- a/tests/unit/gapic/tasks_v2beta2/__init__.py +++ b/tests/unit/gapic/tasks_v2beta2/__init__.py @@ -1 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/tasks_v2beta2/test_cloud_tasks.py b/tests/unit/gapic/tasks_v2beta2/test_cloud_tasks.py index 555e14aa..3224beb5 100644 --- a/tests/unit/gapic/tasks_v2beta2/test_cloud_tasks.py +++ b/tests/unit/gapic/tasks_v2beta2/test_cloud_tasks.py @@ -95,15 +95,17 @@ def test__get_default_mtls_endpoint(): assert CloudTasksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -def test_cloud_tasks_client_from_service_account_info(): +@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient,]) +def test_cloud_tasks_client_from_service_account_info(client_class): creds = credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = CloudTasksClient.from_service_account_info(info) + client = client_class.from_service_account_info(info) assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "cloudtasks.googleapis.com:443" @@ -117,9 +119,11 @@ def test_cloud_tasks_client_from_service_account_file(client_class): factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "cloudtasks.googleapis.com:443" @@ -476,6 +480,22 @@ def test_list_queues_from_dict(): test_list_queues(request_type=dict) +def test_list_queues_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_queues), "__call__") as call: + client.list_queues() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.ListQueuesRequest() + + @pytest.mark.asyncio async def test_list_queues_async( transport: str = "grpc_asyncio", request_type=cloudtasks.ListQueuesRequest @@ -789,6 +809,22 @@ def test_get_queue_from_dict(): test_get_queue(request_type=dict) +def test_get_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_queue), "__call__") as call: + client.get_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.GetQueueRequest() + + @pytest.mark.asyncio async def test_get_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.GetQueueRequest @@ -988,6 +1024,22 @@ def test_create_queue_from_dict(): test_create_queue(request_type=dict) +def test_create_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_queue), "__call__") as call: + client.create_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.CreateQueueRequest() + + @pytest.mark.asyncio async def test_create_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.CreateQueueRequest @@ -1199,6 +1251,22 @@ def test_update_queue_from_dict(): test_update_queue(request_type=dict) +def test_update_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_queue), "__call__") as call: + client.update_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.UpdateQueueRequest() + + @pytest.mark.asyncio async def test_update_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.UpdateQueueRequest @@ -1399,6 +1467,22 @@ def test_delete_queue_from_dict(): test_delete_queue(request_type=dict) +def test_delete_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_queue), "__call__") as call: + client.delete_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.DeleteQueueRequest() + + @pytest.mark.asyncio async def test_delete_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.DeleteQueueRequest @@ -1592,6 +1676,22 @@ def test_purge_queue_from_dict(): test_purge_queue(request_type=dict) +def test_purge_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_queue), "__call__") as call: + client.purge_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.PurgeQueueRequest() + + @pytest.mark.asyncio async def test_purge_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.PurgeQueueRequest @@ -1791,6 +1891,22 @@ def test_pause_queue_from_dict(): test_pause_queue(request_type=dict) +def test_pause_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.pause_queue), "__call__") as call: + client.pause_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.PauseQueueRequest() + + @pytest.mark.asyncio async def test_pause_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.PauseQueueRequest @@ -1990,6 +2106,22 @@ def test_resume_queue_from_dict(): test_resume_queue(request_type=dict) +def test_resume_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.resume_queue), "__call__") as call: + client.resume_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.ResumeQueueRequest() + + @pytest.mark.asyncio async def test_resume_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.ResumeQueueRequest @@ -2181,6 +2313,22 @@ def test_get_iam_policy_from_dict(): test_get_iam_policy(request_type=dict) +def test_get_iam_policy_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # 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: + client.get_iam_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == iam_policy.GetIamPolicyRequest() + + @pytest.mark.asyncio async def test_get_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy.GetIamPolicyRequest @@ -2388,6 +2536,22 @@ def test_set_iam_policy_from_dict(): test_set_iam_policy(request_type=dict) +def test_set_iam_policy_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # 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: + client.set_iam_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == iam_policy.SetIamPolicyRequest() + + @pytest.mark.asyncio async def test_set_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy.SetIamPolicyRequest @@ -2597,6 +2761,24 @@ def test_test_iam_permissions_from_dict(): test_test_iam_permissions(request_type=dict) +def test_test_iam_permissions_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # 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: + client.test_iam_permissions() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == iam_policy.TestIamPermissionsRequest() + + @pytest.mark.asyncio async def test_test_iam_permissions_async( transport: str = "grpc_asyncio", request_type=iam_policy.TestIamPermissionsRequest @@ -2828,6 +3010,22 @@ def test_list_tasks_from_dict(): test_list_tasks(request_type=dict) +def test_list_tasks_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_tasks), "__call__") as call: + client.list_tasks() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.ListTasksRequest() + + @pytest.mark.asyncio async def test_list_tasks_async( transport: str = "grpc_asyncio", request_type=cloudtasks.ListTasksRequest @@ -3127,6 +3325,22 @@ def test_get_task_from_dict(): test_get_task(request_type=dict) +def test_get_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_task), "__call__") as call: + client.get_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.GetTaskRequest() + + @pytest.mark.asyncio async def test_get_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.GetTaskRequest @@ -3324,6 +3538,22 @@ def test_create_task_from_dict(): test_create_task(request_type=dict) +def test_create_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_task), "__call__") as call: + client.create_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.CreateTaskRequest() + + @pytest.mark.asyncio async def test_create_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.CreateTaskRequest @@ -3522,6 +3752,22 @@ def test_delete_task_from_dict(): test_delete_task(request_type=dict) +def test_delete_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_task), "__call__") as call: + client.delete_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.DeleteTaskRequest() + + @pytest.mark.asyncio async def test_delete_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.DeleteTaskRequest @@ -3703,6 +3949,22 @@ def test_lease_tasks_from_dict(): test_lease_tasks(request_type=dict) +def test_lease_tasks_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lease_tasks), "__call__") as call: + client.lease_tasks() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.LeaseTasksRequest() + + @pytest.mark.asyncio async def test_lease_tasks_async( transport: str = "grpc_asyncio", request_type=cloudtasks.LeaseTasksRequest @@ -3905,6 +4167,22 @@ def test_acknowledge_task_from_dict(): test_acknowledge_task(request_type=dict) +def test_acknowledge_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.acknowledge_task), "__call__") as call: + client.acknowledge_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.AcknowledgeTaskRequest() + + @pytest.mark.asyncio async def test_acknowledge_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.AcknowledgeTaskRequest @@ -4112,6 +4390,22 @@ def test_renew_lease_from_dict(): test_renew_lease(request_type=dict) +def test_renew_lease_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.renew_lease), "__call__") as call: + client.renew_lease() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.RenewLeaseRequest() + + @pytest.mark.asyncio async def test_renew_lease_async( transport: str = "grpc_asyncio", request_type=cloudtasks.RenewLeaseRequest @@ -4339,6 +4633,22 @@ def test_cancel_lease_from_dict(): test_cancel_lease(request_type=dict) +def test_cancel_lease_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_lease), "__call__") as call: + client.cancel_lease() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.CancelLeaseRequest() + + @pytest.mark.asyncio async def test_cancel_lease_async( transport: str = "grpc_asyncio", request_type=cloudtasks.CancelLeaseRequest @@ -4550,6 +4860,22 @@ def test_run_task_from_dict(): test_run_task(request_type=dict) +def test_run_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.run_task), "__call__") as call: + client.run_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.RunTaskRequest() + + @pytest.mark.asyncio async def test_run_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.RunTaskRequest diff --git a/tests/unit/gapic/tasks_v2beta3/__init__.py b/tests/unit/gapic/tasks_v2beta3/__init__.py index 8b137891..42ffdf2b 100644 --- a/tests/unit/gapic/tasks_v2beta3/__init__.py +++ b/tests/unit/gapic/tasks_v2beta3/__init__.py @@ -1 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/tasks_v2beta3/test_cloud_tasks.py b/tests/unit/gapic/tasks_v2beta3/test_cloud_tasks.py index 99157ca3..2bdb34e0 100644 --- a/tests/unit/gapic/tasks_v2beta3/test_cloud_tasks.py +++ b/tests/unit/gapic/tasks_v2beta3/test_cloud_tasks.py @@ -95,15 +95,17 @@ def test__get_default_mtls_endpoint(): assert CloudTasksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -def test_cloud_tasks_client_from_service_account_info(): +@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient,]) +def test_cloud_tasks_client_from_service_account_info(client_class): creds = credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = CloudTasksClient.from_service_account_info(info) + client = client_class.from_service_account_info(info) assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "cloudtasks.googleapis.com:443" @@ -117,9 +119,11 @@ def test_cloud_tasks_client_from_service_account_file(client_class): factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "cloudtasks.googleapis.com:443" @@ -476,6 +480,22 @@ def test_list_queues_from_dict(): test_list_queues(request_type=dict) +def test_list_queues_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_queues), "__call__") as call: + client.list_queues() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.ListQueuesRequest() + + @pytest.mark.asyncio async def test_list_queues_async( transport: str = "grpc_asyncio", request_type=cloudtasks.ListQueuesRequest @@ -792,6 +812,22 @@ def test_get_queue_from_dict(): test_get_queue(request_type=dict) +def test_get_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_queue), "__call__") as call: + client.get_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.GetQueueRequest() + + @pytest.mark.asyncio async def test_get_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.GetQueueRequest @@ -1000,6 +1036,22 @@ def test_create_queue_from_dict(): test_create_queue(request_type=dict) +def test_create_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_queue), "__call__") as call: + client.create_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.CreateQueueRequest() + + @pytest.mark.asyncio async def test_create_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.CreateQueueRequest @@ -1220,6 +1272,22 @@ def test_update_queue_from_dict(): test_update_queue(request_type=dict) +def test_update_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_queue), "__call__") as call: + client.update_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.UpdateQueueRequest() + + @pytest.mark.asyncio async def test_update_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.UpdateQueueRequest @@ -1426,6 +1494,22 @@ def test_delete_queue_from_dict(): test_delete_queue(request_type=dict) +def test_delete_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_queue), "__call__") as call: + client.delete_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.DeleteQueueRequest() + + @pytest.mark.asyncio async def test_delete_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.DeleteQueueRequest @@ -1622,6 +1706,22 @@ def test_purge_queue_from_dict(): test_purge_queue(request_type=dict) +def test_purge_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_queue), "__call__") as call: + client.purge_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.PurgeQueueRequest() + + @pytest.mark.asyncio async def test_purge_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.PurgeQueueRequest @@ -1830,6 +1930,22 @@ def test_pause_queue_from_dict(): test_pause_queue(request_type=dict) +def test_pause_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.pause_queue), "__call__") as call: + client.pause_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.PauseQueueRequest() + + @pytest.mark.asyncio async def test_pause_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.PauseQueueRequest @@ -2038,6 +2154,22 @@ def test_resume_queue_from_dict(): test_resume_queue(request_type=dict) +def test_resume_queue_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.resume_queue), "__call__") as call: + client.resume_queue() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.ResumeQueueRequest() + + @pytest.mark.asyncio async def test_resume_queue_async( transport: str = "grpc_asyncio", request_type=cloudtasks.ResumeQueueRequest @@ -2235,6 +2367,22 @@ def test_get_iam_policy_from_dict(): test_get_iam_policy(request_type=dict) +def test_get_iam_policy_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # 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: + client.get_iam_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == iam_policy.GetIamPolicyRequest() + + @pytest.mark.asyncio async def test_get_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy.GetIamPolicyRequest @@ -2442,6 +2590,22 @@ def test_set_iam_policy_from_dict(): test_set_iam_policy(request_type=dict) +def test_set_iam_policy_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # 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: + client.set_iam_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == iam_policy.SetIamPolicyRequest() + + @pytest.mark.asyncio async def test_set_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy.SetIamPolicyRequest @@ -2651,6 +2815,24 @@ def test_test_iam_permissions_from_dict(): test_test_iam_permissions(request_type=dict) +def test_test_iam_permissions_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # 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: + client.test_iam_permissions() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == iam_policy.TestIamPermissionsRequest() + + @pytest.mark.asyncio async def test_test_iam_permissions_async( transport: str = "grpc_asyncio", request_type=iam_policy.TestIamPermissionsRequest @@ -2882,6 +3064,22 @@ def test_list_tasks_from_dict(): test_list_tasks(request_type=dict) +def test_list_tasks_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_tasks), "__call__") as call: + client.list_tasks() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.ListTasksRequest() + + @pytest.mark.asyncio async def test_list_tasks_async( transport: str = "grpc_asyncio", request_type=cloudtasks.ListTasksRequest @@ -3187,6 +3385,22 @@ def test_get_task_from_dict(): test_get_task(request_type=dict) +def test_get_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_task), "__call__") as call: + client.get_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.GetTaskRequest() + + @pytest.mark.asyncio async def test_get_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.GetTaskRequest @@ -3399,6 +3613,22 @@ def test_create_task_from_dict(): test_create_task(request_type=dict) +def test_create_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_task), "__call__") as call: + client.create_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.CreateTaskRequest() + + @pytest.mark.asyncio async def test_create_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.CreateTaskRequest @@ -3606,6 +3836,22 @@ def test_delete_task_from_dict(): test_delete_task(request_type=dict) +def test_delete_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_task), "__call__") as call: + client.delete_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.DeleteTaskRequest() + + @pytest.mark.asyncio async def test_delete_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.DeleteTaskRequest @@ -3801,6 +4047,22 @@ def test_run_task_from_dict(): test_run_task(request_type=dict) +def test_run_task_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudTasksClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.run_task), "__call__") as call: + client.run_task() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == cloudtasks.RunTaskRequest() + + @pytest.mark.asyncio async def test_run_task_async( transport: str = "grpc_asyncio", request_type=cloudtasks.RunTaskRequest