From 6f2d5fe2640a5ee7ca38f1a1ddab936085293c12 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 14 May 2021 12:56:11 +0000 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.46.3 (#75) PiperOrigin-RevId: 373649163 Source-Link: https://github.com/googleapis/googleapis/commit/7e1b14e6c7a9ab96d2db7e4a131981f162446d34 Source-Link: https://github.com/googleapis/googleapis-gen/commit/0a3c7d272d697796db75857bac73905c68e498c3 --- docs/redis_v1/cloud_redis.rst | 1 - docs/redis_v1beta1/cloud_redis.rst | 1 - google/cloud/redis/__init__.py | 6 +- google/cloud/redis_v1/__init__.py | 7 +- google/cloud/redis_v1/gapic_metadata.json | 113 ++++ google/cloud/redis_v1/services/__init__.py | 1 - .../redis_v1/services/cloud_redis/__init__.py | 2 - .../services/cloud_redis/async_client.py | 52 +- .../redis_v1/services/cloud_redis/client.py | 98 +-- .../redis_v1/services/cloud_redis/pagers.py | 4 +- .../cloud_redis/transports/__init__.py | 2 - .../services/cloud_redis/transports/base.py | 138 ++-- .../services/cloud_redis/transports/grpc.py | 52 +- .../cloud_redis/transports/grpc_asyncio.py | 63 +- google/cloud/redis_v1/types/__init__.py | 2 - google/cloud/redis_v1/types/cloud_redis.py | 134 ++-- google/cloud/redis_v1beta1/__init__.py | 7 +- .../cloud/redis_v1beta1/gapic_metadata.json | 113 ++++ .../cloud/redis_v1beta1/services/__init__.py | 1 - .../services/cloud_redis/__init__.py | 2 - .../services/cloud_redis/async_client.py | 68 +- .../services/cloud_redis/client.py | 114 ++-- .../services/cloud_redis/pagers.py | 4 +- .../cloud_redis/transports/__init__.py | 2 - .../services/cloud_redis/transports/base.py | 138 ++-- .../services/cloud_redis/transports/grpc.py | 52 +- .../cloud_redis/transports/grpc_asyncio.py | 63 +- google/cloud/redis_v1beta1/types/__init__.py | 2 - .../cloud/redis_v1beta1/types/cloud_redis.py | 113 ++-- scripts/fixup_redis_v1_keywords.py | 23 +- scripts/fixup_redis_v1beta1_keywords.py | 23 +- tests/__init__.py | 15 + tests/unit/__init__.py | 15 + tests/unit/gapic/__init__.py | 15 + tests/unit/gapic/redis_v1/__init__.py | 1 - tests/unit/gapic/redis_v1/test_cloud_redis.py | 627 +++++++++-------- tests/unit/gapic/redis_v1beta1/__init__.py | 1 - .../gapic/redis_v1beta1/test_cloud_redis.py | 631 ++++++++++-------- 38 files changed, 1522 insertions(+), 1184 deletions(-) create mode 100644 google/cloud/redis_v1/gapic_metadata.json create mode 100644 google/cloud/redis_v1beta1/gapic_metadata.json create mode 100644 tests/__init__.py create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/gapic/__init__.py diff --git a/docs/redis_v1/cloud_redis.rst b/docs/redis_v1/cloud_redis.rst index 3234a55..0e3d7cf 100644 --- a/docs/redis_v1/cloud_redis.rst +++ b/docs/redis_v1/cloud_redis.rst @@ -5,7 +5,6 @@ CloudRedis :members: :inherited-members: - .. automodule:: google.cloud.redis_v1.services.cloud_redis.pagers :members: :inherited-members: diff --git a/docs/redis_v1beta1/cloud_redis.rst b/docs/redis_v1beta1/cloud_redis.rst index 685854a..bce033c 100644 --- a/docs/redis_v1beta1/cloud_redis.rst +++ b/docs/redis_v1beta1/cloud_redis.rst @@ -5,7 +5,6 @@ CloudRedis :members: :inherited-members: - .. automodule:: google.cloud.redis_v1beta1.services.cloud_redis.pagers :members: :inherited-members: diff --git a/google/cloud/redis/__init__.py b/google/cloud/redis/__init__.py index 3eeb22d..08024c0 100644 --- a/google/cloud/redis/__init__.py +++ b/google/cloud/redis/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,10 +14,11 @@ # limitations under the License. # +from google.cloud.redis_v1.services.cloud_redis.client import CloudRedisClient from google.cloud.redis_v1.services.cloud_redis.async_client import ( CloudRedisAsyncClient, ) -from google.cloud.redis_v1.services.cloud_redis.client import CloudRedisClient + from google.cloud.redis_v1.types.cloud_redis import CreateInstanceRequest from google.cloud.redis_v1.types.cloud_redis import DeleteInstanceRequest from google.cloud.redis_v1.types.cloud_redis import ExportInstanceRequest @@ -39,8 +39,8 @@ from google.cloud.redis_v1.types.cloud_redis import ZoneMetadata __all__ = ( - "CloudRedisAsyncClient", "CloudRedisClient", + "CloudRedisAsyncClient", "CreateInstanceRequest", "DeleteInstanceRequest", "ExportInstanceRequest", diff --git a/google/cloud/redis_v1/__init__.py b/google/cloud/redis_v1/__init__.py index aeda34f..ce7087f 100644 --- a/google/cloud/redis_v1/__init__.py +++ b/google/cloud/redis_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.cloud_redis import CloudRedisClient +from .services.cloud_redis import CloudRedisAsyncClient + from .types.cloud_redis import CreateInstanceRequest from .types.cloud_redis import DeleteInstanceRequest from .types.cloud_redis import ExportInstanceRequest @@ -35,8 +36,9 @@ from .types.cloud_redis import UpgradeInstanceRequest from .types.cloud_redis import ZoneMetadata - __all__ = ( + "CloudRedisAsyncClient", + "CloudRedisClient", "CreateInstanceRequest", "DeleteInstanceRequest", "ExportInstanceRequest", @@ -55,5 +57,4 @@ "UpdateInstanceRequest", "UpgradeInstanceRequest", "ZoneMetadata", - "CloudRedisClient", ) diff --git a/google/cloud/redis_v1/gapic_metadata.json b/google/cloud/redis_v1/gapic_metadata.json new file mode 100644 index 0000000..038bb99 --- /dev/null +++ b/google/cloud/redis_v1/gapic_metadata.json @@ -0,0 +1,113 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.redis_v1", + "protoPackage": "google.cloud.redis.v1", + "schema": "1.0", + "services": { + "CloudRedis": { + "clients": { + "grpc": { + "libraryClient": "CloudRedisClient", + "rpcs": { + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "ExportInstance": { + "methods": [ + "export_instance" + ] + }, + "FailoverInstance": { + "methods": [ + "failover_instance" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "ImportInstance": { + "methods": [ + "import_instance" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpgradeInstance": { + "methods": [ + "upgrade_instance" + ] + } + } + }, + "grpc-async": { + "libraryClient": "CloudRedisAsyncClient", + "rpcs": { + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "ExportInstance": { + "methods": [ + "export_instance" + ] + }, + "FailoverInstance": { + "methods": [ + "failover_instance" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "ImportInstance": { + "methods": [ + "import_instance" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpgradeInstance": { + "methods": [ + "upgrade_instance" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/redis_v1/services/__init__.py b/google/cloud/redis_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/redis_v1/services/__init__.py +++ b/google/cloud/redis_v1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/redis_v1/services/cloud_redis/__init__.py b/google/cloud/redis_v1/services/cloud_redis/__init__.py index e66c1aa..5a5662c 100644 --- a/google/cloud/redis_v1/services/cloud_redis/__init__.py +++ b/google/cloud/redis_v1/services/cloud_redis/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import CloudRedisClient from .async_client import CloudRedisAsyncClient diff --git a/google/cloud/redis_v1/services/cloud_redis/async_client.py b/google/cloud/redis_v1/services/cloud_redis/async_client.py index 5677201..28839c0 100644 --- a/google/cloud/redis_v1/services/cloud_redis/async_client.py +++ b/google/cloud/redis_v1/services/cloud_redis/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,20 +20,19 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.redis_v1.services.cloud_redis import pagers from google.cloud.redis_v1.types import cloud_redis -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import CloudRedisTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import CloudRedisGrpcAsyncIOTransport from .client import CloudRedisClient @@ -72,25 +69,20 @@ class CloudRedisAsyncClient: instance_path = staticmethod(CloudRedisClient.instance_path) parse_instance_path = staticmethod(CloudRedisClient.parse_instance_path) - common_billing_account_path = staticmethod( CloudRedisClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( CloudRedisClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(CloudRedisClient.common_folder_path) parse_common_folder_path = staticmethod(CloudRedisClient.parse_common_folder_path) - common_organization_path = staticmethod(CloudRedisClient.common_organization_path) parse_common_organization_path = staticmethod( CloudRedisClient.parse_common_organization_path ) - common_project_path = staticmethod(CloudRedisClient.common_project_path) parse_common_project_path = staticmethod(CloudRedisClient.parse_common_project_path) - common_location_path = staticmethod(CloudRedisClient.common_location_path) parse_common_location_path = staticmethod( CloudRedisClient.parse_common_location_path @@ -98,7 +90,8 @@ class CloudRedisAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -113,7 +106,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -130,7 +123,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> CloudRedisTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: CloudRedisTransport: The transport used by the client instance. @@ -144,12 +137,12 @@ def transport(self) -> CloudRedisTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, CloudRedisTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the cloud redis client. + """Instantiates the cloud redis client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -181,7 +174,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = CloudRedisClient( credentials=credentials, transport=transport, @@ -222,7 +214,6 @@ async def list_instances( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -252,7 +243,6 @@ async def list_instances( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -305,7 +295,6 @@ async def get_instance( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -330,7 +319,6 @@ async def get_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -412,7 +400,6 @@ async def create_instance( This corresponds to the ``instance`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -442,7 +429,6 @@ async def create_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if instance_id is not None: @@ -482,7 +468,7 @@ async def update_instance( self, request: cloud_redis.UpdateInstanceRequest = None, *, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, instance: cloud_redis.Instance = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -520,7 +506,6 @@ async def update_instance( This corresponds to the ``instance`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -550,7 +535,6 @@ async def update_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if update_mask is not None: request.update_mask = update_mask if instance is not None: @@ -618,7 +602,6 @@ async def upgrade_instance( This corresponds to the ``redis_version`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -648,7 +631,6 @@ async def upgrade_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if redis_version is not None: @@ -721,7 +703,6 @@ async def import_instance( This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -751,7 +732,6 @@ async def import_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: @@ -820,7 +800,6 @@ async def export_instance( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -850,7 +829,6 @@ async def export_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -918,7 +896,6 @@ async def failover_instance( This corresponds to the ``data_protection_mode`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -948,7 +925,6 @@ async def failover_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if data_protection_mode is not None: @@ -1006,7 +982,6 @@ async def delete_instance( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1046,7 +1021,6 @@ async def delete_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1071,7 +1045,7 @@ async def delete_instance( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=cloud_redis.OperationMetadata, ) diff --git a/google/cloud/redis_v1/services/cloud_redis/client.py b/google/cloud/redis_v1/services/cloud_redis/client.py index 2e5a28e..73b6bac 100644 --- a/google/cloud/redis_v1/services/cloud_redis/client.py +++ b/google/cloud/redis_v1/services/cloud_redis/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -36,10 +34,9 @@ from google.api_core import operation_async # type: ignore from google.cloud.redis_v1.services.cloud_redis import pagers from google.cloud.redis_v1.types import cloud_redis -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import CloudRedisTransport, DEFAULT_CLIENT_INFO from .transports.grpc import CloudRedisGrpcTransport from .transports.grpc_asyncio import CloudRedisGrpcAsyncIOTransport @@ -58,7 +55,7 @@ class CloudRedisClientMeta(type): _transport_registry["grpc_asyncio"] = CloudRedisGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[CloudRedisTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -102,7 +99,8 @@ class CloudRedisClient(metaclass=CloudRedisClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -136,7 +134,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -153,7 +152,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -172,23 +171,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> CloudRedisTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - CloudRedisTransport: The transport used by the client instance. + CloudRedisTransport: The transport used by the client + instance. """ return self._transport @staticmethod def instance_path(project: str, location: str, instance: str,) -> str: - """Return a fully-qualified instance string.""" + """Returns a fully-qualified instance string.""" return "projects/{project}/locations/{location}/instances/{instance}".format( project=project, location=location, instance=instance, ) @staticmethod def parse_instance_path(path: str) -> Dict[str, str]: - """Parse a instance path into its component segments.""" + """Parses a instance path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/instances/(?P.+?)$", path, @@ -197,7 +197,7 @@ def parse_instance_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -210,7 +210,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -221,7 +221,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -232,7 +232,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -243,7 +243,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -257,12 +257,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, CloudRedisTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the cloud redis client. + """Instantiates the cloud redis client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -317,9 +317,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -331,12 +332,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -351,8 +354,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -400,7 +403,6 @@ def list_instances( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -432,10 +434,8 @@ def list_instances( # there are no flattened fields. if not isinstance(request, cloud_redis.ListInstancesRequest): request = cloud_redis.ListInstancesRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -484,7 +484,6 @@ def get_instance( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -511,10 +510,8 @@ def get_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.GetInstanceRequest): request = cloud_redis.GetInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -592,7 +589,6 @@ def create_instance( This corresponds to the ``instance`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -624,10 +620,8 @@ def create_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.CreateInstanceRequest): request = cloud_redis.CreateInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if instance_id is not None: @@ -663,7 +657,7 @@ def update_instance( self, request: cloud_redis.UpdateInstanceRequest = None, *, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, instance: cloud_redis.Instance = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -701,7 +695,6 @@ def update_instance( This corresponds to the ``instance`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -733,10 +726,8 @@ def update_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.UpdateInstanceRequest): request = cloud_redis.UpdateInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if update_mask is not None: request.update_mask = update_mask if instance is not None: @@ -800,7 +791,6 @@ def upgrade_instance( This corresponds to the ``redis_version`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -832,10 +822,8 @@ def upgrade_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.UpgradeInstanceRequest): request = cloud_redis.UpgradeInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if redis_version is not None: @@ -904,7 +892,6 @@ def import_instance( This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -936,10 +923,8 @@ def import_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.ImportInstanceRequest): request = cloud_redis.ImportInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: @@ -1004,7 +989,6 @@ def export_instance( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1036,10 +1020,8 @@ def export_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.ExportInstanceRequest): request = cloud_redis.ExportInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -1103,7 +1085,6 @@ def failover_instance( This corresponds to the ``data_protection_mode`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1135,10 +1116,8 @@ def failover_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.FailoverInstanceRequest): request = cloud_redis.FailoverInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if data_protection_mode is not None: @@ -1192,7 +1171,6 @@ def delete_instance( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1234,10 +1212,8 @@ def delete_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.DeleteInstanceRequest): request = cloud_redis.DeleteInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1258,7 +1234,7 @@ def delete_instance( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=cloud_redis.OperationMetadata, ) diff --git a/google/cloud/redis_v1/services/cloud_redis/pagers.py b/google/cloud/redis_v1/services/cloud_redis/pagers.py index a784084..a3b4ce9 100644 --- a/google/cloud/redis_v1/services/cloud_redis/pagers.py +++ b/google/cloud/redis_v1/services/cloud_redis/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -117,7 +115,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/redis_v1/services/cloud_redis/transports/__init__.py b/google/cloud/redis_v1/services/cloud_redis/transports/__init__.py index 7959435..bf730b1 100644 --- a/google/cloud/redis_v1/services/cloud_redis/transports/__init__.py +++ b/google/cloud/redis_v1/services/cloud_redis/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/redis_v1/services/cloud_redis/transports/base.py b/google/cloud/redis_v1/services/cloud_redis/transports/base.py index 83c64f3..c72e2bd 100644 --- a/google/cloud/redis_v1/services/cloud_redis/transports/base.py +++ b/google/cloud/redis_v1/services/cloud_redis/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.redis_v1.types import cloud_redis -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -37,27 +36,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class CloudRedisTransport(abc.ABC): """Abstract transport class for CloudRedis.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "redis.googleapis.com" + def __init__( self, *, - host: str = "redis.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -66,7 +79,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (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): @@ -80,29 +93,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # 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: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -143,11 +203,11 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_instances( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.ListInstancesRequest], - typing.Union[ + Union[ cloud_redis.ListInstancesResponse, - typing.Awaitable[cloud_redis.ListInstancesResponse], + Awaitable[cloud_redis.ListInstancesResponse], ], ]: raise NotImplementedError() @@ -155,72 +215,72 @@ def list_instances( @property def get_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.GetInstanceRequest], - typing.Union[cloud_redis.Instance, typing.Awaitable[cloud_redis.Instance]], + Union[cloud_redis.Instance, Awaitable[cloud_redis.Instance]], ]: raise NotImplementedError() @property def create_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.CreateInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.UpdateInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def upgrade_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.UpgradeInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def import_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.ImportInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def export_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.ExportInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def failover_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.FailoverInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.DeleteInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py b/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py index 8bfb753..e06f851 100644 --- a/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py +++ b/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.redis_v1.types import cloud_redis -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import CloudRedisTransport, DEFAULT_CLIENT_INFO @@ -72,7 +69,7 @@ def __init__( self, *, host: str = "redis.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -86,7 +83,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -197,7 +195,7 @@ def __init__( def create_channel( cls, host: str = "redis.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -228,13 +226,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -324,7 +324,7 @@ def get_instance( @property def create_instance( self, - ) -> Callable[[cloud_redis.CreateInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.CreateInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the create instance method over gRPC. Creates a Redis instance based on the specified tier and memory @@ -356,14 +356,14 @@ def create_instance( self._stubs["create_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/CreateInstance", request_serializer=cloud_redis.CreateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_instance"] @property def update_instance( self, - ) -> Callable[[cloud_redis.UpdateInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.UpdateInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the update instance method over gRPC. Updates the metadata and configuration of a specific @@ -387,14 +387,14 @@ def update_instance( self._stubs["update_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/UpdateInstance", request_serializer=cloud_redis.UpdateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_instance"] @property def upgrade_instance( self, - ) -> Callable[[cloud_redis.UpgradeInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.UpgradeInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the upgrade instance method over gRPC. Upgrades Redis instance to the newer Redis version @@ -414,14 +414,14 @@ def upgrade_instance( self._stubs["upgrade_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/UpgradeInstance", request_serializer=cloud_redis.UpgradeInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["upgrade_instance"] @property def import_instance( self, - ) -> Callable[[cloud_redis.ImportInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.ImportInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the import instance method over gRPC. Import a Redis RDB snapshot file from Cloud Storage @@ -448,14 +448,14 @@ def import_instance( self._stubs["import_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/ImportInstance", request_serializer=cloud_redis.ImportInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["import_instance"] @property def export_instance( self, - ) -> Callable[[cloud_redis.ExportInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.ExportInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the export instance method over gRPC. Export Redis instance data into a Redis RDB format @@ -478,14 +478,14 @@ def export_instance( self._stubs["export_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/ExportInstance", request_serializer=cloud_redis.ExportInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_instance"] @property def failover_instance( self, - ) -> Callable[[cloud_redis.FailoverInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.FailoverInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the failover instance method over gRPC. Initiates a failover of the master node to current @@ -506,14 +506,14 @@ def failover_instance( self._stubs["failover_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/FailoverInstance", request_serializer=cloud_redis.FailoverInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["failover_instance"] @property def delete_instance( self, - ) -> Callable[[cloud_redis.DeleteInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.DeleteInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the delete instance method over gRPC. Deletes a specific Redis instance. Instance stops @@ -533,7 +533,7 @@ def delete_instance( self._stubs["delete_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/DeleteInstance", request_serializer=cloud_redis.DeleteInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_instance"] diff --git a/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py b/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py index d2568d3..4ce602a 100644 --- a/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py +++ b/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.redis_v1.types import cloud_redis -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import CloudRedisTransport, DEFAULT_CLIENT_INFO from .grpc import CloudRedisGrpcTransport @@ -75,7 +72,7 @@ class CloudRedisGrpcAsyncIOTransport(CloudRedisTransport): def create_channel( cls, host: str = "redis.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -102,13 +99,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -116,7 +115,7 @@ def __init__( self, *, host: str = "redis.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -130,7 +129,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -189,7 +189,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -330,7 +329,9 @@ def get_instance( @property def create_instance( self, - ) -> Callable[[cloud_redis.CreateInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [cloud_redis.CreateInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the create instance method over gRPC. Creates a Redis instance based on the specified tier and memory @@ -362,14 +363,16 @@ def create_instance( self._stubs["create_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/CreateInstance", request_serializer=cloud_redis.CreateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_instance"] @property def update_instance( self, - ) -> Callable[[cloud_redis.UpdateInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [cloud_redis.UpdateInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the update instance method over gRPC. Updates the metadata and configuration of a specific @@ -393,7 +396,7 @@ def update_instance( self._stubs["update_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/UpdateInstance", request_serializer=cloud_redis.UpdateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_instance"] @@ -401,7 +404,7 @@ def update_instance( def upgrade_instance( self, ) -> Callable[ - [cloud_redis.UpgradeInstanceRequest], Awaitable[operations.Operation] + [cloud_redis.UpgradeInstanceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the upgrade instance method over gRPC. @@ -422,14 +425,16 @@ def upgrade_instance( self._stubs["upgrade_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/UpgradeInstance", request_serializer=cloud_redis.UpgradeInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["upgrade_instance"] @property def import_instance( self, - ) -> Callable[[cloud_redis.ImportInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [cloud_redis.ImportInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the import instance method over gRPC. Import a Redis RDB snapshot file from Cloud Storage @@ -456,14 +461,16 @@ def import_instance( self._stubs["import_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/ImportInstance", request_serializer=cloud_redis.ImportInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["import_instance"] @property def export_instance( self, - ) -> Callable[[cloud_redis.ExportInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [cloud_redis.ExportInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the export instance method over gRPC. Export Redis instance data into a Redis RDB format @@ -486,7 +493,7 @@ def export_instance( self._stubs["export_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/ExportInstance", request_serializer=cloud_redis.ExportInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_instance"] @@ -494,7 +501,7 @@ def export_instance( def failover_instance( self, ) -> Callable[ - [cloud_redis.FailoverInstanceRequest], Awaitable[operations.Operation] + [cloud_redis.FailoverInstanceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the failover instance method over gRPC. @@ -516,14 +523,16 @@ def failover_instance( self._stubs["failover_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/FailoverInstance", request_serializer=cloud_redis.FailoverInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["failover_instance"] @property def delete_instance( self, - ) -> Callable[[cloud_redis.DeleteInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [cloud_redis.DeleteInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the delete instance method over gRPC. Deletes a specific Redis instance. Instance stops @@ -543,7 +552,7 @@ def delete_instance( self._stubs["delete_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/DeleteInstance", request_serializer=cloud_redis.DeleteInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_instance"] diff --git a/google/cloud/redis_v1/types/__init__.py b/google/cloud/redis_v1/types/__init__.py index 1f18cb9..909344d 100644 --- a/google/cloud/redis_v1/types/__init__.py +++ b/google/cloud/redis_v1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .cloud_redis import ( CreateInstanceRequest, DeleteInstanceRequest, diff --git a/google/cloud/redis_v1/types/cloud_redis.py b/google/cloud/redis_v1/types/cloud_redis.py index aba660c..2da8a95 100644 --- a/google/cloud/redis_v1/types/cloud_redis.py +++ b/google/cloud/redis_v1/types/cloud_redis.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -49,7 +46,6 @@ class Instance(proto.Message): r"""A Google Cloud Redis instance. - Attributes: name (str): Required. Unique name of the resource in this scope @@ -192,42 +188,26 @@ class ConnectMode(proto.Enum): DIRECT_PEERING = 1 PRIVATE_SERVICE_ACCESS = 2 - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - labels = proto.MapField(proto.STRING, proto.STRING, number=3) - - location_id = proto.Field(proto.STRING, number=4) - - alternative_location_id = proto.Field(proto.STRING, number=5) - - redis_version = proto.Field(proto.STRING, number=7) - - reserved_ip_range = proto.Field(proto.STRING, number=9) - - host = proto.Field(proto.STRING, number=10) - - port = proto.Field(proto.INT32, number=11) - - current_location_id = proto.Field(proto.STRING, number=12) - - create_time = proto.Field(proto.MESSAGE, number=13, message=timestamp.Timestamp,) - + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + labels = proto.MapField(proto.STRING, proto.STRING, number=3,) + location_id = proto.Field(proto.STRING, number=4,) + alternative_location_id = proto.Field(proto.STRING, number=5,) + redis_version = proto.Field(proto.STRING, number=7,) + reserved_ip_range = proto.Field(proto.STRING, number=9,) + host = proto.Field(proto.STRING, number=10,) + port = proto.Field(proto.INT32, number=11,) + current_location_id = proto.Field(proto.STRING, number=12,) + create_time = proto.Field( + proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp, + ) state = proto.Field(proto.ENUM, number=14, enum=State,) - - status_message = proto.Field(proto.STRING, number=15) - - redis_configs = proto.MapField(proto.STRING, proto.STRING, number=16) - + status_message = proto.Field(proto.STRING, number=15,) + redis_configs = proto.MapField(proto.STRING, proto.STRING, number=16,) tier = proto.Field(proto.ENUM, number=17, enum=Tier,) - - memory_size_gb = proto.Field(proto.INT32, number=18) - - authorized_network = proto.Field(proto.STRING, number=20) - - persistence_iam_identity = proto.Field(proto.STRING, number=21) - + memory_size_gb = proto.Field(proto.INT32, number=18,) + authorized_network = proto.Field(proto.STRING, number=20,) + persistence_iam_identity = proto.Field(proto.STRING, number=21,) connect_mode = proto.Field(proto.ENUM, number=22, enum=ConnectMode,) @@ -255,11 +235,9 @@ class ListInstancesRequest(proto.Message): request, if any. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) class ListInstancesResponse(proto.Message): @@ -293,10 +271,8 @@ def raw_page(self): return self instances = proto.RepeatedField(proto.MESSAGE, number=1, message="Instance",) - - next_page_token = proto.Field(proto.STRING, number=2) - - unreachable = proto.RepeatedField(proto.STRING, number=3) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) class GetInstanceRequest(proto.Message): @@ -310,7 +286,7 @@ class GetInstanceRequest(proto.Message): where ``location_id`` refers to a GCP region. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CreateInstanceRequest(proto.Message): @@ -336,10 +312,8 @@ class CreateInstanceRequest(proto.Message): Required. A Redis [Instance] resource """ - parent = proto.Field(proto.STRING, number=1) - - instance_id = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + instance_id = proto.Field(proto.STRING, number=2,) instance = proto.Field(proto.MESSAGE, number=3, message="Instance",) @@ -363,8 +337,9 @@ class UpdateInstanceRequest(proto.Message): update_mask are updated. """ - update_mask = proto.Field(proto.MESSAGE, number=1, message=field_mask.FieldMask,) - + update_mask = proto.Field( + proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + ) instance = proto.Field(proto.MESSAGE, number=2, message="Instance",) @@ -382,9 +357,8 @@ class UpgradeInstanceRequest(proto.Message): Redis software to upgrade to. """ - name = proto.Field(proto.STRING, number=1) - - redis_version = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + redis_version = proto.Field(proto.STRING, number=2,) class DeleteInstanceRequest(proto.Message): @@ -398,24 +372,22 @@ class DeleteInstanceRequest(proto.Message): where ``location_id`` refers to a GCP region. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GcsSource(proto.Message): r"""The Cloud Storage location for the input content - Attributes: uri (str): Required. Source data URI. (e.g. 'gs://my_bucket/my_object'). """ - uri = proto.Field(proto.STRING, number=1) + uri = proto.Field(proto.STRING, number=1,) class InputConfig(proto.Message): r"""The input content - Attributes: gcs_source (google.cloud.redis_v1.types.GcsSource): Google Cloud Storage location where input @@ -440,14 +412,12 @@ class ImportInstanceRequest(proto.Message): Required. Specify data to be imported. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) input_config = proto.Field(proto.MESSAGE, number=3, message="InputConfig",) class GcsDestination(proto.Message): r"""The Cloud Storage location for the output content - Attributes: uri (str): Required. Data destination URI (e.g. @@ -455,12 +425,11 @@ class GcsDestination(proto.Message): overwritten. """ - uri = proto.Field(proto.STRING, number=1) + uri = proto.Field(proto.STRING, number=1,) class OutputConfig(proto.Message): r"""The output content - Attributes: gcs_destination (google.cloud.redis_v1.types.GcsDestination): Google Cloud Storage destination for output @@ -485,8 +454,7 @@ class ExportInstanceRequest(proto.Message): Required. Specify data to be exported. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) output_config = proto.Field(proto.MESSAGE, number=3, message="OutputConfig",) @@ -513,14 +481,12 @@ class DataProtectionMode(proto.Enum): LIMITED_DATA_LOSS = 1 FORCE_DATA_LOSS = 2 - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) data_protection_mode = proto.Field(proto.ENUM, number=2, enum=DataProtectionMode,) class OperationMetadata(proto.Message): r"""Represents the v1 metadata of the long-running operation. - Attributes: create_time (google.protobuf.timestamp_pb2.Timestamp): Creation timestamp. @@ -539,19 +505,13 @@ class OperationMetadata(proto.Message): API version. """ - create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - target = proto.Field(proto.STRING, number=3) - - verb = proto.Field(proto.STRING, number=4) - - status_detail = proto.Field(proto.STRING, number=5) - - cancel_requested = proto.Field(proto.BOOL, number=6) - - api_version = proto.Field(proto.STRING, number=7) + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + target = proto.Field(proto.STRING, number=3,) + verb = proto.Field(proto.STRING, number=4,) + status_detail = proto.Field(proto.STRING, number=5,) + cancel_requested = proto.Field(proto.BOOL, number=6,) + api_version = proto.Field(proto.STRING, number=7,) class LocationMetadata(proto.Message): @@ -577,7 +537,7 @@ class LocationMetadata(proto.Message): class ZoneMetadata(proto.Message): r"""Defines specific information for a particular zone. Currently empty and reserved for future use only. - """ + """ __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/redis_v1beta1/__init__.py b/google/cloud/redis_v1beta1/__init__.py index ab39293..c39dd68 100644 --- a/google/cloud/redis_v1beta1/__init__.py +++ b/google/cloud/redis_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.cloud_redis import CloudRedisClient +from .services.cloud_redis import CloudRedisAsyncClient + from .types.cloud_redis import CreateInstanceRequest from .types.cloud_redis import DeleteInstanceRequest from .types.cloud_redis import ExportInstanceRequest @@ -34,8 +35,9 @@ from .types.cloud_redis import UpgradeInstanceRequest from .types.cloud_redis import ZoneMetadata - __all__ = ( + "CloudRedisAsyncClient", + "CloudRedisClient", "CreateInstanceRequest", "DeleteInstanceRequest", "ExportInstanceRequest", @@ -53,5 +55,4 @@ "UpdateInstanceRequest", "UpgradeInstanceRequest", "ZoneMetadata", - "CloudRedisClient", ) diff --git a/google/cloud/redis_v1beta1/gapic_metadata.json b/google/cloud/redis_v1beta1/gapic_metadata.json new file mode 100644 index 0000000..5bb1784 --- /dev/null +++ b/google/cloud/redis_v1beta1/gapic_metadata.json @@ -0,0 +1,113 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.redis_v1beta1", + "protoPackage": "google.cloud.redis.v1beta1", + "schema": "1.0", + "services": { + "CloudRedis": { + "clients": { + "grpc": { + "libraryClient": "CloudRedisClient", + "rpcs": { + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "ExportInstance": { + "methods": [ + "export_instance" + ] + }, + "FailoverInstance": { + "methods": [ + "failover_instance" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "ImportInstance": { + "methods": [ + "import_instance" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpgradeInstance": { + "methods": [ + "upgrade_instance" + ] + } + } + }, + "grpc-async": { + "libraryClient": "CloudRedisAsyncClient", + "rpcs": { + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "ExportInstance": { + "methods": [ + "export_instance" + ] + }, + "FailoverInstance": { + "methods": [ + "failover_instance" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "ImportInstance": { + "methods": [ + "import_instance" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpgradeInstance": { + "methods": [ + "upgrade_instance" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/redis_v1beta1/services/__init__.py b/google/cloud/redis_v1beta1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/redis_v1beta1/services/__init__.py +++ b/google/cloud/redis_v1beta1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/__init__.py b/google/cloud/redis_v1beta1/services/cloud_redis/__init__.py index e66c1aa..5a5662c 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/__init__.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import CloudRedisClient from .async_client import CloudRedisAsyncClient diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py b/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py index 4d125eb..bd4ace9 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,21 +20,20 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.redis_v1beta1.services.cloud_redis import pagers from google.cloud.redis_v1beta1.types import cloud_redis -from google.protobuf import any_pb2 as gp_any # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import CloudRedisTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import CloudRedisGrpcAsyncIOTransport from .client import CloudRedisClient @@ -73,25 +70,20 @@ class CloudRedisAsyncClient: instance_path = staticmethod(CloudRedisClient.instance_path) parse_instance_path = staticmethod(CloudRedisClient.parse_instance_path) - common_billing_account_path = staticmethod( CloudRedisClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( CloudRedisClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(CloudRedisClient.common_folder_path) parse_common_folder_path = staticmethod(CloudRedisClient.parse_common_folder_path) - common_organization_path = staticmethod(CloudRedisClient.common_organization_path) parse_common_organization_path = staticmethod( CloudRedisClient.parse_common_organization_path ) - common_project_path = staticmethod(CloudRedisClient.common_project_path) parse_common_project_path = staticmethod(CloudRedisClient.parse_common_project_path) - common_location_path = staticmethod(CloudRedisClient.common_location_path) parse_common_location_path = staticmethod( CloudRedisClient.parse_common_location_path @@ -99,7 +91,8 @@ class CloudRedisAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -114,7 +107,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -131,7 +124,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> CloudRedisTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: CloudRedisTransport: The transport used by the client instance. @@ -145,12 +138,12 @@ def transport(self) -> CloudRedisTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, CloudRedisTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the cloud redis client. + """Instantiates the cloud redis client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -182,7 +175,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = CloudRedisClient( credentials=credentials, transport=transport, @@ -223,7 +215,6 @@ async def list_instances( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -253,7 +244,6 @@ async def list_instances( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -306,7 +296,6 @@ async def get_instance( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -331,7 +320,6 @@ async def get_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -413,7 +401,6 @@ async def create_instance( This corresponds to the ``instance`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -443,7 +430,6 @@ async def create_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if instance_id is not None: @@ -473,7 +459,7 @@ async def create_instance( response, self._client._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -483,7 +469,7 @@ async def update_instance( self, request: cloud_redis.UpdateInstanceRequest = None, *, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, instance: cloud_redis.Instance = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -521,7 +507,6 @@ async def update_instance( This corresponds to the ``instance`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -551,7 +536,6 @@ async def update_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if update_mask is not None: request.update_mask = update_mask if instance is not None: @@ -581,7 +565,7 @@ async def update_instance( response, self._client._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -619,7 +603,6 @@ async def upgrade_instance( This corresponds to the ``redis_version`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -649,7 +632,6 @@ async def upgrade_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if redis_version is not None: @@ -677,7 +659,7 @@ async def upgrade_instance( response, self._client._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -722,7 +704,6 @@ async def import_instance( This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -752,7 +733,6 @@ async def import_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: @@ -780,7 +760,7 @@ async def import_instance( response, self._client._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -821,7 +801,6 @@ async def export_instance( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -851,7 +830,6 @@ async def export_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -879,7 +857,7 @@ async def export_instance( response, self._client._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -919,7 +897,6 @@ async def failover_instance( This corresponds to the ``data_protection_mode`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -949,7 +926,6 @@ async def failover_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if data_protection_mode is not None: @@ -977,7 +953,7 @@ async def failover_instance( response, self._client._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -1007,7 +983,6 @@ async def delete_instance( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1047,7 +1022,6 @@ async def delete_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1072,8 +1046,8 @@ async def delete_instance( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, - metadata_type=gp_any.Any, + empty_pb2.Empty, + metadata_type=any_pb2.Any, ) # Done; return the response. diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/client.py b/google/cloud/redis_v1beta1/services/cloud_redis/client.py index 7f0e208..7165d34 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/client.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -36,11 +34,10 @@ from google.api_core import operation_async # type: ignore from google.cloud.redis_v1beta1.services.cloud_redis import pagers from google.cloud.redis_v1beta1.types import cloud_redis -from google.protobuf import any_pb2 as gp_any # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import CloudRedisTransport, DEFAULT_CLIENT_INFO from .transports.grpc import CloudRedisGrpcTransport from .transports.grpc_asyncio import CloudRedisGrpcAsyncIOTransport @@ -59,7 +56,7 @@ class CloudRedisClientMeta(type): _transport_registry["grpc_asyncio"] = CloudRedisGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[CloudRedisTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -103,7 +100,8 @@ class CloudRedisClient(metaclass=CloudRedisClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -137,7 +135,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -154,7 +153,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -173,23 +172,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> CloudRedisTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - CloudRedisTransport: The transport used by the client instance. + CloudRedisTransport: The transport used by the client + instance. """ return self._transport @staticmethod def instance_path(project: str, location: str, instance: str,) -> str: - """Return a fully-qualified instance string.""" + """Returns a fully-qualified instance string.""" return "projects/{project}/locations/{location}/instances/{instance}".format( project=project, location=location, instance=instance, ) @staticmethod def parse_instance_path(path: str) -> Dict[str, str]: - """Parse a instance path into its component segments.""" + """Parses a instance path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/instances/(?P.+?)$", path, @@ -198,7 +198,7 @@ def parse_instance_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -211,7 +211,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -222,7 +222,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -233,7 +233,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -244,7 +244,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -258,12 +258,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, CloudRedisTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the cloud redis client. + """Instantiates the cloud redis client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -318,9 +318,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -332,12 +333,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -352,8 +355,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -401,7 +404,6 @@ def list_instances( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -433,10 +435,8 @@ def list_instances( # there are no flattened fields. if not isinstance(request, cloud_redis.ListInstancesRequest): request = cloud_redis.ListInstancesRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -485,7 +485,6 @@ def get_instance( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -512,10 +511,8 @@ def get_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.GetInstanceRequest): request = cloud_redis.GetInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -593,7 +590,6 @@ def create_instance( This corresponds to the ``instance`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -625,10 +621,8 @@ def create_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.CreateInstanceRequest): request = cloud_redis.CreateInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if instance_id is not None: @@ -654,7 +648,7 @@ def create_instance( response, self._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -664,7 +658,7 @@ def update_instance( self, request: cloud_redis.UpdateInstanceRequest = None, *, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, instance: cloud_redis.Instance = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -702,7 +696,6 @@ def update_instance( This corresponds to the ``instance`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -734,10 +727,8 @@ def update_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.UpdateInstanceRequest): request = cloud_redis.UpdateInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if update_mask is not None: request.update_mask = update_mask if instance is not None: @@ -763,7 +754,7 @@ def update_instance( response, self._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -801,7 +792,6 @@ def upgrade_instance( This corresponds to the ``redis_version`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -833,10 +823,8 @@ def upgrade_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.UpgradeInstanceRequest): request = cloud_redis.UpgradeInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if redis_version is not None: @@ -860,7 +848,7 @@ def upgrade_instance( response, self._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -905,7 +893,6 @@ def import_instance( This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -937,10 +924,8 @@ def import_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.ImportInstanceRequest): request = cloud_redis.ImportInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if input_config is not None: @@ -964,7 +949,7 @@ def import_instance( response, self._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -1005,7 +990,6 @@ def export_instance( This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1037,10 +1021,8 @@ def export_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.ExportInstanceRequest): request = cloud_redis.ExportInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if output_config is not None: @@ -1064,7 +1046,7 @@ def export_instance( response, self._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -1104,7 +1086,6 @@ def failover_instance( This corresponds to the ``data_protection_mode`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1136,10 +1117,8 @@ def failover_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.FailoverInstanceRequest): request = cloud_redis.FailoverInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if data_protection_mode is not None: @@ -1163,7 +1142,7 @@ def failover_instance( response, self._transport.operations_client, cloud_redis.Instance, - metadata_type=gp_any.Any, + metadata_type=any_pb2.Any, ) # Done; return the response. @@ -1193,7 +1172,6 @@ def delete_instance( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1235,10 +1213,8 @@ def delete_instance( # there are no flattened fields. if not isinstance(request, cloud_redis.DeleteInstanceRequest): request = cloud_redis.DeleteInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1259,8 +1235,8 @@ def delete_instance( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, - metadata_type=gp_any.Any, + empty_pb2.Empty, + metadata_type=any_pb2.Any, ) # Done; return the response. diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/pagers.py b/google/cloud/redis_v1beta1/services/cloud_redis/pagers.py index 7098490..08d7f75 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/pagers.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -117,7 +115,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/transports/__init__.py b/google/cloud/redis_v1beta1/services/cloud_redis/transports/__init__.py index 7959435..bf730b1 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/transports/__init__.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/transports/base.py b/google/cloud/redis_v1beta1/services/cloud_redis/transports/base.py index c3704df..5924854 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/transports/base.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.redis_v1beta1.types import cloud_redis -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -37,27 +36,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class CloudRedisTransport(abc.ABC): """Abstract transport class for CloudRedis.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "redis.googleapis.com" + def __init__( self, *, - host: str = "redis.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -66,7 +79,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (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): @@ -80,29 +93,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # 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: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -143,11 +203,11 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_instances( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.ListInstancesRequest], - typing.Union[ + Union[ cloud_redis.ListInstancesResponse, - typing.Awaitable[cloud_redis.ListInstancesResponse], + Awaitable[cloud_redis.ListInstancesResponse], ], ]: raise NotImplementedError() @@ -155,72 +215,72 @@ def list_instances( @property def get_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.GetInstanceRequest], - typing.Union[cloud_redis.Instance, typing.Awaitable[cloud_redis.Instance]], + Union[cloud_redis.Instance, Awaitable[cloud_redis.Instance]], ]: raise NotImplementedError() @property def create_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.CreateInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.UpdateInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def upgrade_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.UpgradeInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def import_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.ImportInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def export_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.ExportInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def failover_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.FailoverInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_redis.DeleteInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py b/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py index 1f3c559..433a8d6 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.redis_v1beta1.types import cloud_redis -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import CloudRedisTransport, DEFAULT_CLIENT_INFO @@ -72,7 +69,7 @@ def __init__( self, *, host: str = "redis.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -86,7 +83,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -197,7 +195,7 @@ def __init__( def create_channel( cls, host: str = "redis.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -228,13 +226,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -324,7 +324,7 @@ def get_instance( @property def create_instance( self, - ) -> Callable[[cloud_redis.CreateInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.CreateInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the create instance method over gRPC. Creates a Redis instance based on the specified tier and memory @@ -356,14 +356,14 @@ def create_instance( self._stubs["create_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/CreateInstance", request_serializer=cloud_redis.CreateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_instance"] @property def update_instance( self, - ) -> Callable[[cloud_redis.UpdateInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.UpdateInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the update instance method over gRPC. Updates the metadata and configuration of a specific @@ -387,14 +387,14 @@ def update_instance( self._stubs["update_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/UpdateInstance", request_serializer=cloud_redis.UpdateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_instance"] @property def upgrade_instance( self, - ) -> Callable[[cloud_redis.UpgradeInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.UpgradeInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the upgrade instance method over gRPC. Upgrades Redis instance to the newer Redis version @@ -414,14 +414,14 @@ def upgrade_instance( self._stubs["upgrade_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/UpgradeInstance", request_serializer=cloud_redis.UpgradeInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["upgrade_instance"] @property def import_instance( self, - ) -> Callable[[cloud_redis.ImportInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.ImportInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the import instance method over gRPC. Import a Redis RDB snapshot file from Cloud Storage @@ -448,14 +448,14 @@ def import_instance( self._stubs["import_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/ImportInstance", request_serializer=cloud_redis.ImportInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["import_instance"] @property def export_instance( self, - ) -> Callable[[cloud_redis.ExportInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.ExportInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the export instance method over gRPC. Export Redis instance data into a Redis RDB format @@ -478,14 +478,14 @@ def export_instance( self._stubs["export_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/ExportInstance", request_serializer=cloud_redis.ExportInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_instance"] @property def failover_instance( self, - ) -> Callable[[cloud_redis.FailoverInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.FailoverInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the failover instance method over gRPC. Initiates a failover of the master node to current @@ -506,14 +506,14 @@ def failover_instance( self._stubs["failover_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/FailoverInstance", request_serializer=cloud_redis.FailoverInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["failover_instance"] @property def delete_instance( self, - ) -> Callable[[cloud_redis.DeleteInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_redis.DeleteInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the delete instance method over gRPC. Deletes a specific Redis instance. Instance stops @@ -533,7 +533,7 @@ def delete_instance( self._stubs["delete_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/DeleteInstance", request_serializer=cloud_redis.DeleteInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_instance"] diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py b/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py index 62c9e0f..4dedbd9 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.redis_v1beta1.types import cloud_redis -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import CloudRedisTransport, DEFAULT_CLIENT_INFO from .grpc import CloudRedisGrpcTransport @@ -75,7 +72,7 @@ class CloudRedisGrpcAsyncIOTransport(CloudRedisTransport): def create_channel( cls, host: str = "redis.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -102,13 +99,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -116,7 +115,7 @@ def __init__( self, *, host: str = "redis.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -130,7 +129,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -189,7 +189,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -330,7 +329,9 @@ def get_instance( @property def create_instance( self, - ) -> Callable[[cloud_redis.CreateInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [cloud_redis.CreateInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the create instance method over gRPC. Creates a Redis instance based on the specified tier and memory @@ -362,14 +363,16 @@ def create_instance( self._stubs["create_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/CreateInstance", request_serializer=cloud_redis.CreateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_instance"] @property def update_instance( self, - ) -> Callable[[cloud_redis.UpdateInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [cloud_redis.UpdateInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the update instance method over gRPC. Updates the metadata and configuration of a specific @@ -393,7 +396,7 @@ def update_instance( self._stubs["update_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/UpdateInstance", request_serializer=cloud_redis.UpdateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_instance"] @@ -401,7 +404,7 @@ def update_instance( def upgrade_instance( self, ) -> Callable[ - [cloud_redis.UpgradeInstanceRequest], Awaitable[operations.Operation] + [cloud_redis.UpgradeInstanceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the upgrade instance method over gRPC. @@ -422,14 +425,16 @@ def upgrade_instance( self._stubs["upgrade_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/UpgradeInstance", request_serializer=cloud_redis.UpgradeInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["upgrade_instance"] @property def import_instance( self, - ) -> Callable[[cloud_redis.ImportInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [cloud_redis.ImportInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the import instance method over gRPC. Import a Redis RDB snapshot file from Cloud Storage @@ -456,14 +461,16 @@ def import_instance( self._stubs["import_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/ImportInstance", request_serializer=cloud_redis.ImportInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["import_instance"] @property def export_instance( self, - ) -> Callable[[cloud_redis.ExportInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [cloud_redis.ExportInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the export instance method over gRPC. Export Redis instance data into a Redis RDB format @@ -486,7 +493,7 @@ def export_instance( self._stubs["export_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/ExportInstance", request_serializer=cloud_redis.ExportInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["export_instance"] @@ -494,7 +501,7 @@ def export_instance( def failover_instance( self, ) -> Callable[ - [cloud_redis.FailoverInstanceRequest], Awaitable[operations.Operation] + [cloud_redis.FailoverInstanceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the failover instance method over gRPC. @@ -516,14 +523,16 @@ def failover_instance( self._stubs["failover_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/FailoverInstance", request_serializer=cloud_redis.FailoverInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["failover_instance"] @property def delete_instance( self, - ) -> Callable[[cloud_redis.DeleteInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [cloud_redis.DeleteInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the delete instance method over gRPC. Deletes a specific Redis instance. Instance stops @@ -543,7 +552,7 @@ def delete_instance( self._stubs["delete_instance"] = self.grpc_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/DeleteInstance", request_serializer=cloud_redis.DeleteInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_instance"] diff --git a/google/cloud/redis_v1beta1/types/__init__.py b/google/cloud/redis_v1beta1/types/__init__.py index 918e784..70064ba 100644 --- a/google/cloud/redis_v1beta1/types/__init__.py +++ b/google/cloud/redis_v1beta1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .cloud_redis import ( CreateInstanceRequest, DeleteInstanceRequest, diff --git a/google/cloud/redis_v1beta1/types/cloud_redis.py b/google/cloud/redis_v1beta1/types/cloud_redis.py index 8b588ae..78e7f32 100644 --- a/google/cloud/redis_v1beta1/types/cloud_redis.py +++ b/google/cloud/redis_v1beta1/types/cloud_redis.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -48,7 +45,6 @@ class Instance(proto.Message): r"""A Google Cloud Redis instance. - Attributes: name (str): Required. Unique name of the resource in this scope @@ -193,42 +189,26 @@ class ConnectMode(proto.Enum): DIRECT_PEERING = 1 PRIVATE_SERVICE_ACCESS = 2 - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - labels = proto.MapField(proto.STRING, proto.STRING, number=3) - - location_id = proto.Field(proto.STRING, number=4) - - alternative_location_id = proto.Field(proto.STRING, number=5) - - redis_version = proto.Field(proto.STRING, number=7) - - reserved_ip_range = proto.Field(proto.STRING, number=9) - - host = proto.Field(proto.STRING, number=10) - - port = proto.Field(proto.INT32, number=11) - - current_location_id = proto.Field(proto.STRING, number=12) - - create_time = proto.Field(proto.MESSAGE, number=13, message=timestamp.Timestamp,) - + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + labels = proto.MapField(proto.STRING, proto.STRING, number=3,) + location_id = proto.Field(proto.STRING, number=4,) + alternative_location_id = proto.Field(proto.STRING, number=5,) + redis_version = proto.Field(proto.STRING, number=7,) + reserved_ip_range = proto.Field(proto.STRING, number=9,) + host = proto.Field(proto.STRING, number=10,) + port = proto.Field(proto.INT32, number=11,) + current_location_id = proto.Field(proto.STRING, number=12,) + create_time = proto.Field( + proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp, + ) state = proto.Field(proto.ENUM, number=14, enum=State,) - - status_message = proto.Field(proto.STRING, number=15) - - redis_configs = proto.MapField(proto.STRING, proto.STRING, number=16) - + status_message = proto.Field(proto.STRING, number=15,) + redis_configs = proto.MapField(proto.STRING, proto.STRING, number=16,) tier = proto.Field(proto.ENUM, number=17, enum=Tier,) - - memory_size_gb = proto.Field(proto.INT32, number=18) - - authorized_network = proto.Field(proto.STRING, number=20) - - persistence_iam_identity = proto.Field(proto.STRING, number=21) - + memory_size_gb = proto.Field(proto.INT32, number=18,) + authorized_network = proto.Field(proto.STRING, number=20,) + persistence_iam_identity = proto.Field(proto.STRING, number=21,) connect_mode = proto.Field(proto.ENUM, number=22, enum=ConnectMode,) @@ -256,11 +236,9 @@ class ListInstancesRequest(proto.Message): request, if any. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) class ListInstancesResponse(proto.Message): @@ -294,10 +272,8 @@ def raw_page(self): return self instances = proto.RepeatedField(proto.MESSAGE, number=1, message="Instance",) - - next_page_token = proto.Field(proto.STRING, number=2) - - unreachable = proto.RepeatedField(proto.STRING, number=3) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) class GetInstanceRequest(proto.Message): @@ -311,7 +287,7 @@ class GetInstanceRequest(proto.Message): where ``location_id`` refers to a GCP region. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CreateInstanceRequest(proto.Message): @@ -337,10 +313,8 @@ class CreateInstanceRequest(proto.Message): Required. A Redis [Instance] resource """ - parent = proto.Field(proto.STRING, number=1) - - instance_id = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + instance_id = proto.Field(proto.STRING, number=2,) instance = proto.Field(proto.MESSAGE, number=3, message="Instance",) @@ -364,8 +338,9 @@ class UpdateInstanceRequest(proto.Message): update_mask are updated. """ - update_mask = proto.Field(proto.MESSAGE, number=1, message=field_mask.FieldMask,) - + update_mask = proto.Field( + proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + ) instance = proto.Field(proto.MESSAGE, number=2, message="Instance",) @@ -383,9 +358,8 @@ class UpgradeInstanceRequest(proto.Message): Redis software to upgrade to. """ - name = proto.Field(proto.STRING, number=1) - - redis_version = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + redis_version = proto.Field(proto.STRING, number=2,) class DeleteInstanceRequest(proto.Message): @@ -399,24 +373,22 @@ class DeleteInstanceRequest(proto.Message): where ``location_id`` refers to a GCP region. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GcsSource(proto.Message): r"""The Cloud Storage location for the input content - Attributes: uri (str): Required. Source data URI. (e.g. 'gs://my_bucket/my_object'). """ - uri = proto.Field(proto.STRING, number=1) + uri = proto.Field(proto.STRING, number=1,) class InputConfig(proto.Message): r"""The input content - Attributes: gcs_source (google.cloud.redis_v1beta1.types.GcsSource): Google Cloud Storage location where input @@ -441,14 +413,12 @@ class ImportInstanceRequest(proto.Message): Required. Specify data to be imported. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) input_config = proto.Field(proto.MESSAGE, number=3, message="InputConfig",) class GcsDestination(proto.Message): r"""The Cloud Storage location for the output content - Attributes: uri (str): Required. Data destination URI (e.g. @@ -456,12 +426,11 @@ class GcsDestination(proto.Message): overwritten. """ - uri = proto.Field(proto.STRING, number=1) + uri = proto.Field(proto.STRING, number=1,) class OutputConfig(proto.Message): r"""The output content - Attributes: gcs_destination (google.cloud.redis_v1beta1.types.GcsDestination): Google Cloud Storage destination for output @@ -486,8 +455,7 @@ class ExportInstanceRequest(proto.Message): Required. Specify data to be exported. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) output_config = proto.Field(proto.MESSAGE, number=3, message="OutputConfig",) @@ -514,8 +482,7 @@ class DataProtectionMode(proto.Enum): LIMITED_DATA_LOSS = 1 FORCE_DATA_LOSS = 2 - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) data_protection_mode = proto.Field(proto.ENUM, number=2, enum=DataProtectionMode,) @@ -542,7 +509,7 @@ class LocationMetadata(proto.Message): class ZoneMetadata(proto.Message): r"""Defines specific information for a particular zone. Currently empty and reserved for future use only. - """ + """ __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/scripts/fixup_redis_v1_keywords.py b/scripts/fixup_redis_v1_keywords.py index b142431..876e658 100644 --- a/scripts/fixup_redis_v1_keywords.py +++ b/scripts/fixup_redis_v1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,16 +39,15 @@ def partition( class redisCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_instance': ('parent', 'instance_id', 'instance', ), - 'delete_instance': ('name', ), - 'export_instance': ('name', 'output_config', ), - 'failover_instance': ('name', 'data_protection_mode', ), - 'get_instance': ('name', ), - 'import_instance': ('name', 'input_config', ), - 'list_instances': ('parent', 'page_size', 'page_token', ), - 'update_instance': ('update_mask', 'instance', ), - 'upgrade_instance': ('name', 'redis_version', ), - + 'create_instance': ('parent', 'instance_id', 'instance', ), + 'delete_instance': ('name', ), + 'export_instance': ('name', 'output_config', ), + 'failover_instance': ('name', 'data_protection_mode', ), + 'get_instance': ('name', ), + 'import_instance': ('name', 'input_config', ), + 'list_instances': ('parent', 'page_size', 'page_token', ), + 'update_instance': ('update_mask', 'instance', ), + 'upgrade_instance': ('name', 'redis_version', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -81,7 +78,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/scripts/fixup_redis_v1beta1_keywords.py b/scripts/fixup_redis_v1beta1_keywords.py index b142431..876e658 100644 --- a/scripts/fixup_redis_v1beta1_keywords.py +++ b/scripts/fixup_redis_v1beta1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,16 +39,15 @@ def partition( class redisCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_instance': ('parent', 'instance_id', 'instance', ), - 'delete_instance': ('name', ), - 'export_instance': ('name', 'output_config', ), - 'failover_instance': ('name', 'data_protection_mode', ), - 'get_instance': ('name', ), - 'import_instance': ('name', 'input_config', ), - 'list_instances': ('parent', 'page_size', 'page_token', ), - 'update_instance': ('update_mask', 'instance', ), - 'upgrade_instance': ('name', 'redis_version', ), - + 'create_instance': ('parent', 'instance_id', 'instance', ), + 'delete_instance': ('name', ), + 'export_instance': ('name', 'output_config', ), + 'failover_instance': ('name', 'data_protection_mode', ), + 'get_instance': ('name', ), + 'import_instance': ('name', 'input_config', ), + 'list_instances': ('parent', 'page_size', 'page_token', ), + 'update_instance': ('update_mask', 'instance', ), + 'upgrade_instance': ('name', 'redis_version', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -81,7 +78,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +# -*- 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/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1,15 @@ +# -*- 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/__init__.py b/tests/unit/gapic/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/gapic/__init__.py @@ -0,0 +1,15 @@ +# -*- 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/redis_v1/__init__.py b/tests/unit/gapic/redis_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/redis_v1/__init__.py +++ b/tests/unit/gapic/redis_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/unit/gapic/redis_v1/test_cloud_redis.py index 0527721..15de5cb 100644 --- a/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,26 +23,54 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import future from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.redis_v1.services.cloud_redis import CloudRedisAsyncClient from google.cloud.redis_v1.services.cloud_redis import CloudRedisClient from google.cloud.redis_v1.services.cloud_redis import pagers from google.cloud.redis_v1.services.cloud_redis import transports +from google.cloud.redis_v1.services.cloud_redis.transports.base import _API_CORE_VERSION +from google.cloud.redis_v1.services.cloud_redis.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.redis_v1.types import cloud_redis from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -89,7 +116,7 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize("client_class", [CloudRedisClient, CloudRedisAsyncClient,]) def test_cloud_redis_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -104,7 +131,7 @@ def test_cloud_redis_client_from_service_account_info(client_class): @pytest.mark.parametrize("client_class", [CloudRedisClient, CloudRedisAsyncClient,]) def test_cloud_redis_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -155,7 +182,7 @@ def test_cloud_redis_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(CloudRedisClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -439,7 +466,7 @@ def test_list_instances( transport: str = "grpc", request_type=cloud_redis.ListInstancesRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -452,21 +479,16 @@ def test_list_instances( call.return_value = cloud_redis.ListInstancesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) - response = client.list_instances(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ListInstancesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstancesPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -478,7 +500,7 @@ def test_list_instances_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -486,7 +508,6 @@ def test_list_instances_empty_call(): client.list_instances() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ListInstancesRequest() @@ -495,7 +516,7 @@ async def test_list_instances_async( transport: str = "grpc_asyncio", request_type=cloud_redis.ListInstancesRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -511,20 +532,16 @@ async def test_list_instances_async( unreachable=["unreachable_value"], ) ) - response = await client.list_instances(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ListInstancesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListInstancesAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -534,17 +551,17 @@ async def test_list_instances_async_from_dict(): def test_list_instances_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ListInstancesRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: call.return_value = cloud_redis.ListInstancesResponse() - client.list_instances(request) # Establish that the underlying gRPC stub method was called. @@ -559,11 +576,12 @@ def test_list_instances_field_headers(): @pytest.mark.asyncio async def test_list_instances_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ListInstancesRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -571,7 +589,6 @@ async def test_list_instances_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.ListInstancesResponse() ) - await client.list_instances(request) # Establish that the underlying gRPC stub method was called. @@ -585,13 +602,12 @@ async def test_list_instances_field_headers_async(): def test_list_instances_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.ListInstancesResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_instances(parent="parent_value",) @@ -600,12 +616,11 @@ def test_list_instances_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_instances_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -617,7 +632,7 @@ def test_list_instances_flattened_error(): @pytest.mark.asyncio async def test_list_instances_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: @@ -635,13 +650,12 @@ async def test_list_instances_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_instances_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -652,7 +666,7 @@ async def test_list_instances_flattened_error_async(): def test_list_instances_pager(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials,) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: @@ -690,7 +704,7 @@ def test_list_instances_pager(): def test_list_instances_pages(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials,) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: @@ -720,7 +734,7 @@ def test_list_instances_pages(): @pytest.mark.asyncio async def test_list_instances_async_pager(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials,) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -757,7 +771,7 @@ async def test_list_instances_async_pager(): @pytest.mark.asyncio async def test_list_instances_async_pages(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials,) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -793,7 +807,7 @@ def test_get_instance( transport: str = "grpc", request_type=cloud_redis.GetInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -821,49 +835,30 @@ def test_get_instance( persistence_iam_identity="persistence_iam_identity_value", connect_mode=cloud_redis.Instance.ConnectMode.DIRECT_PEERING, ) - response = client.get_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.GetInstanceRequest() # Establish that the response is the type that we expect. - assert isinstance(response, cloud_redis.Instance) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.location_id == "location_id_value" - assert response.alternative_location_id == "alternative_location_id_value" - assert response.redis_version == "redis_version_value" - assert response.reserved_ip_range == "reserved_ip_range_value" - assert response.host == "host_value" - assert response.port == 453 - assert response.current_location_id == "current_location_id_value" - assert response.state == cloud_redis.Instance.State.CREATING - assert response.status_message == "status_message_value" - assert response.tier == cloud_redis.Instance.Tier.BASIC - assert response.memory_size_gb == 1499 - assert response.authorized_network == "authorized_network_value" - assert response.persistence_iam_identity == "persistence_iam_identity_value" - assert response.connect_mode == cloud_redis.Instance.ConnectMode.DIRECT_PEERING @@ -875,7 +870,7 @@ def test_get_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -883,7 +878,6 @@ def test_get_instance_empty_call(): client.get_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.GetInstanceRequest() @@ -892,7 +886,7 @@ async def test_get_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.GetInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -922,48 +916,30 @@ async def test_get_instance_async( connect_mode=cloud_redis.Instance.ConnectMode.DIRECT_PEERING, ) ) - response = await client.get_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.GetInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, cloud_redis.Instance) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.location_id == "location_id_value" - assert response.alternative_location_id == "alternative_location_id_value" - assert response.redis_version == "redis_version_value" - assert response.reserved_ip_range == "reserved_ip_range_value" - assert response.host == "host_value" - assert response.port == 453 - assert response.current_location_id == "current_location_id_value" - assert response.state == cloud_redis.Instance.State.CREATING - assert response.status_message == "status_message_value" - assert response.tier == cloud_redis.Instance.Tier.BASIC - assert response.memory_size_gb == 1499 - assert response.authorized_network == "authorized_network_value" - assert response.persistence_iam_identity == "persistence_iam_identity_value" - assert response.connect_mode == cloud_redis.Instance.ConnectMode.DIRECT_PEERING @@ -973,17 +949,17 @@ async def test_get_instance_async_from_dict(): def test_get_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.GetInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_instance), "__call__") as call: call.return_value = cloud_redis.Instance() - client.get_instance(request) # Establish that the underlying gRPC stub method was called. @@ -998,11 +974,12 @@ def test_get_instance_field_headers(): @pytest.mark.asyncio async def test_get_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.GetInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1010,7 +987,6 @@ async def test_get_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.Instance() ) - await client.get_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1024,13 +1000,12 @@ async def test_get_instance_field_headers_async(): def test_get_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.Instance() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_instance(name="name_value",) @@ -1039,12 +1014,11 @@ def test_get_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1056,7 +1030,7 @@ def test_get_instance_flattened_error(): @pytest.mark.asyncio async def test_get_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_instance), "__call__") as call: @@ -1074,13 +1048,12 @@ async def test_get_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1094,7 +1067,7 @@ def test_create_instance( transport: str = "grpc", request_type=cloud_redis.CreateInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1105,13 +1078,11 @@ def test_create_instance( with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.CreateInstanceRequest() # Establish that the response is the type that we expect. @@ -1126,7 +1097,7 @@ def test_create_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1134,7 +1105,6 @@ def test_create_instance_empty_call(): client.create_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.CreateInstanceRequest() @@ -1143,7 +1113,7 @@ async def test_create_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.CreateInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1156,13 +1126,11 @@ async def test_create_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.CreateInstanceRequest() # Establish that the response is the type that we expect. @@ -1175,17 +1143,17 @@ async def test_create_instance_async_from_dict(): def test_create_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.CreateInstanceRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1200,11 +1168,12 @@ def test_create_instance_field_headers(): @pytest.mark.asyncio async def test_create_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.CreateInstanceRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1212,7 +1181,6 @@ async def test_create_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1226,13 +1194,12 @@ async def test_create_instance_field_headers_async(): def test_create_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_instance( @@ -1245,16 +1212,13 @@ def test_create_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].instance_id == "instance_id_value" - assert args[0].instance == cloud_redis.Instance(name="name_value") def test_create_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1269,7 +1233,7 @@ def test_create_instance_flattened_error(): @pytest.mark.asyncio async def test_create_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_instance), "__call__") as call: @@ -1291,17 +1255,14 @@ async def test_create_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].instance_id == "instance_id_value" - assert args[0].instance == cloud_redis.Instance(name="name_value") @pytest.mark.asyncio async def test_create_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1318,7 +1279,7 @@ def test_update_instance( transport: str = "grpc", request_type=cloud_redis.UpdateInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1329,13 +1290,11 @@ def test_update_instance( with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpdateInstanceRequest() # Establish that the response is the type that we expect. @@ -1350,7 +1309,7 @@ def test_update_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1358,7 +1317,6 @@ def test_update_instance_empty_call(): client.update_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpdateInstanceRequest() @@ -1367,7 +1325,7 @@ async def test_update_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.UpdateInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1380,13 +1338,11 @@ async def test_update_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpdateInstanceRequest() # Establish that the response is the type that we expect. @@ -1399,17 +1355,17 @@ async def test_update_instance_async_from_dict(): def test_update_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.UpdateInstanceRequest() + request.instance.name = "instance.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1426,11 +1382,12 @@ def test_update_instance_field_headers(): @pytest.mark.asyncio async def test_update_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.UpdateInstanceRequest() + request.instance.name = "instance.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1438,7 +1395,6 @@ async def test_update_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1454,17 +1410,16 @@ async def test_update_instance_field_headers_async(): def test_update_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_instance( - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), instance=cloud_redis.Instance(name="name_value"), ) @@ -1472,28 +1427,26 @@ def test_update_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) - + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) assert args[0].instance == cloud_redis.Instance(name="name_value") def test_update_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.update_instance( cloud_redis.UpdateInstanceRequest(), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), instance=cloud_redis.Instance(name="name_value"), ) @pytest.mark.asyncio async def test_update_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_instance), "__call__") as call: @@ -1506,7 +1459,7 @@ async def test_update_instance_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.update_instance( - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), instance=cloud_redis.Instance(name="name_value"), ) @@ -1514,22 +1467,20 @@ async def test_update_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) - + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) assert args[0].instance == cloud_redis.Instance(name="name_value") @pytest.mark.asyncio async def test_update_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.update_instance( cloud_redis.UpdateInstanceRequest(), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), instance=cloud_redis.Instance(name="name_value"), ) @@ -1538,7 +1489,7 @@ def test_upgrade_instance( transport: str = "grpc", request_type=cloud_redis.UpgradeInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1549,13 +1500,11 @@ def test_upgrade_instance( with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpgradeInstanceRequest() # Establish that the response is the type that we expect. @@ -1570,7 +1519,7 @@ def test_upgrade_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1578,7 +1527,6 @@ def test_upgrade_instance_empty_call(): client.upgrade_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpgradeInstanceRequest() @@ -1587,7 +1535,7 @@ async def test_upgrade_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.UpgradeInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1600,13 +1548,11 @@ async def test_upgrade_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpgradeInstanceRequest() # Establish that the response is the type that we expect. @@ -1619,17 +1565,17 @@ async def test_upgrade_instance_async_from_dict(): def test_upgrade_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.UpgradeInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1644,11 +1590,12 @@ def test_upgrade_instance_field_headers(): @pytest.mark.asyncio async def test_upgrade_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.UpgradeInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1656,7 +1603,6 @@ async def test_upgrade_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1670,13 +1616,12 @@ async def test_upgrade_instance_field_headers_async(): def test_upgrade_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.upgrade_instance( @@ -1687,14 +1632,12 @@ def test_upgrade_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].redis_version == "redis_version_value" def test_upgrade_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1708,7 +1651,7 @@ def test_upgrade_instance_flattened_error(): @pytest.mark.asyncio async def test_upgrade_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: @@ -1728,15 +1671,13 @@ async def test_upgrade_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].redis_version == "redis_version_value" @pytest.mark.asyncio async def test_upgrade_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1752,7 +1693,7 @@ def test_import_instance( transport: str = "grpc", request_type=cloud_redis.ImportInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1763,13 +1704,11 @@ def test_import_instance( with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.import_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ImportInstanceRequest() # Establish that the response is the type that we expect. @@ -1784,7 +1723,7 @@ def test_import_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1792,7 +1731,6 @@ def test_import_instance_empty_call(): client.import_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ImportInstanceRequest() @@ -1801,7 +1739,7 @@ async def test_import_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.ImportInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1814,13 +1752,11 @@ async def test_import_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.import_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ImportInstanceRequest() # Establish that the response is the type that we expect. @@ -1833,17 +1769,17 @@ async def test_import_instance_async_from_dict(): def test_import_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ImportInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.import_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1858,11 +1794,12 @@ def test_import_instance_field_headers(): @pytest.mark.asyncio async def test_import_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ImportInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1870,7 +1807,6 @@ async def test_import_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.import_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1884,13 +1820,12 @@ async def test_import_instance_field_headers_async(): def test_import_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.import_instance( @@ -1904,16 +1839,14 @@ def test_import_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == cloud_redis.InputConfig( gcs_source=cloud_redis.GcsSource(uri="uri_value") ) def test_import_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1929,7 +1862,7 @@ def test_import_instance_flattened_error(): @pytest.mark.asyncio async def test_import_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_instance), "__call__") as call: @@ -1952,9 +1885,7 @@ async def test_import_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == cloud_redis.InputConfig( gcs_source=cloud_redis.GcsSource(uri="uri_value") ) @@ -1962,7 +1893,7 @@ async def test_import_instance_flattened_async(): @pytest.mark.asyncio async def test_import_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1980,7 +1911,7 @@ def test_export_instance( transport: str = "grpc", request_type=cloud_redis.ExportInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1991,13 +1922,11 @@ def test_export_instance( with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.export_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ExportInstanceRequest() # Establish that the response is the type that we expect. @@ -2012,7 +1941,7 @@ def test_export_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2020,7 +1949,6 @@ def test_export_instance_empty_call(): client.export_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ExportInstanceRequest() @@ -2029,7 +1957,7 @@ async def test_export_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.ExportInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2042,13 +1970,11 @@ async def test_export_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.export_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ExportInstanceRequest() # Establish that the response is the type that we expect. @@ -2061,17 +1987,17 @@ async def test_export_instance_async_from_dict(): def test_export_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ExportInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.export_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2086,11 +2012,12 @@ def test_export_instance_field_headers(): @pytest.mark.asyncio async def test_export_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ExportInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2098,7 +2025,6 @@ async def test_export_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.export_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2112,13 +2038,12 @@ async def test_export_instance_field_headers_async(): def test_export_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.export_instance( @@ -2132,16 +2057,14 @@ def test_export_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == cloud_redis.OutputConfig( gcs_destination=cloud_redis.GcsDestination(uri="uri_value") ) def test_export_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2157,7 +2080,7 @@ def test_export_instance_flattened_error(): @pytest.mark.asyncio async def test_export_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_instance), "__call__") as call: @@ -2180,9 +2103,7 @@ async def test_export_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == cloud_redis.OutputConfig( gcs_destination=cloud_redis.GcsDestination(uri="uri_value") ) @@ -2190,7 +2111,7 @@ async def test_export_instance_flattened_async(): @pytest.mark.asyncio async def test_export_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2208,7 +2129,7 @@ def test_failover_instance( transport: str = "grpc", request_type=cloud_redis.FailoverInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2221,13 +2142,11 @@ def test_failover_instance( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.failover_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.FailoverInstanceRequest() # Establish that the response is the type that we expect. @@ -2242,7 +2161,7 @@ def test_failover_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2252,7 +2171,6 @@ def test_failover_instance_empty_call(): client.failover_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.FailoverInstanceRequest() @@ -2261,7 +2179,7 @@ async def test_failover_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.FailoverInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2276,13 +2194,11 @@ async def test_failover_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.failover_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.FailoverInstanceRequest() # Establish that the response is the type that we expect. @@ -2295,11 +2211,12 @@ async def test_failover_instance_async_from_dict(): def test_failover_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.FailoverInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2307,7 +2224,6 @@ def test_failover_instance_field_headers(): type(client.transport.failover_instance), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.failover_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2322,11 +2238,12 @@ def test_failover_instance_field_headers(): @pytest.mark.asyncio async def test_failover_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.FailoverInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2336,7 +2253,6 @@ async def test_failover_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.failover_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2350,7 +2266,7 @@ async def test_failover_instance_field_headers_async(): def test_failover_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2358,7 +2274,6 @@ def test_failover_instance_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.failover_instance( @@ -2370,9 +2285,7 @@ def test_failover_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert ( args[0].data_protection_mode == cloud_redis.FailoverInstanceRequest.DataProtectionMode.LIMITED_DATA_LOSS @@ -2380,7 +2293,7 @@ def test_failover_instance_flattened(): def test_failover_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2394,7 +2307,7 @@ def test_failover_instance_flattened_error(): @pytest.mark.asyncio async def test_failover_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2417,9 +2330,7 @@ async def test_failover_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert ( args[0].data_protection_mode == cloud_redis.FailoverInstanceRequest.DataProtectionMode.LIMITED_DATA_LOSS @@ -2428,7 +2339,7 @@ async def test_failover_instance_flattened_async(): @pytest.mark.asyncio async def test_failover_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2444,7 +2355,7 @@ def test_delete_instance( transport: str = "grpc", request_type=cloud_redis.DeleteInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2455,13 +2366,11 @@ def test_delete_instance( with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.DeleteInstanceRequest() # Establish that the response is the type that we expect. @@ -2476,7 +2385,7 @@ def test_delete_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2484,7 +2393,6 @@ def test_delete_instance_empty_call(): client.delete_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.DeleteInstanceRequest() @@ -2493,7 +2401,7 @@ async def test_delete_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.DeleteInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2506,13 +2414,11 @@ async def test_delete_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.DeleteInstanceRequest() # Establish that the response is the type that we expect. @@ -2525,17 +2431,17 @@ async def test_delete_instance_async_from_dict(): def test_delete_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.DeleteInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2550,11 +2456,12 @@ def test_delete_instance_field_headers(): @pytest.mark.asyncio async def test_delete_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.DeleteInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2562,7 +2469,6 @@ async def test_delete_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2576,13 +2482,12 @@ async def test_delete_instance_field_headers_async(): def test_delete_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_instance(name="name_value",) @@ -2591,12 +2496,11 @@ def test_delete_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2608,7 +2512,7 @@ def test_delete_instance_flattened_error(): @pytest.mark.asyncio async def test_delete_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: @@ -2626,13 +2530,12 @@ async def test_delete_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2645,16 +2548,16 @@ async def test_delete_instance_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CloudRedisGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.CloudRedisGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudRedisClient( @@ -2664,7 +2567,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.CloudRedisGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudRedisClient( @@ -2675,7 +2578,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CloudRedisGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = CloudRedisClient(transport=transport) assert client.transport is transport @@ -2684,13 +2587,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.CloudRedisGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.CloudRedisGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2702,23 +2605,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.CloudRedisGrpcTransport,) def test_cloud_redis_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.CloudRedisTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2730,7 +2633,7 @@ def test_cloud_redis_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CloudRedisTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2756,15 +2659,37 @@ def test_cloud_redis_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_cloud_redis_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.redis_v1.services.cloud_redis.transports.CloudRedisTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.CloudRedisTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_cloud_redis_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.redis_v1.services.cloud_redis.transports.CloudRedisTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudRedisTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -2777,19 +2702,33 @@ def test_cloud_redis_base_transport_with_credentials_file(): def test_cloud_redis_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.redis_v1.services.cloud_redis.transports.CloudRedisTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudRedisTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_cloud_redis_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + CloudRedisClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_cloud_redis_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) CloudRedisClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -2797,26 +2736,156 @@ def test_cloud_redis_auth_adc(): ) -def test_cloud_redis_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [transports.CloudRedisGrpcTransport, transports.CloudRedisGrpcAsyncIOTransport,], +) +@requires_google_auth_gte_1_25_0 +def test_cloud_redis_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.CloudRedisGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [transports.CloudRedisGrpcTransport, transports.CloudRedisGrpcAsyncIOTransport,], +) +@requires_google_auth_lt_1_25_0 +def test_cloud_redis_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.CloudRedisGrpcTransport, grpc_helpers), + (transports.CloudRedisGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_cloud_redis_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "redis.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="redis.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.CloudRedisGrpcTransport, grpc_helpers), + (transports.CloudRedisGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_cloud_redis_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "redis.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.CloudRedisGrpcTransport, grpc_helpers), + (transports.CloudRedisGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_cloud_redis_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "redis.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [transports.CloudRedisGrpcTransport, transports.CloudRedisGrpcAsyncIOTransport], ) def test_cloud_redis_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2855,7 +2924,7 @@ def test_cloud_redis_grpc_transport_client_cert_source_for_mtls(transport_class) def test_cloud_redis_host_no_port(): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="redis.googleapis.com" ), @@ -2865,7 +2934,7 @@ def test_cloud_redis_host_no_port(): def test_cloud_redis_host_with_port(): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="redis.googleapis.com:8000" ), @@ -2916,9 +2985,9 @@ def test_cloud_redis_transport_channel_mtls_with_client_cert_source(transport_cl mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -2991,7 +3060,7 @@ def test_cloud_redis_transport_channel_mtls_with_adc(transport_class): def test_cloud_redis_grpc_lro_client(): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -3004,7 +3073,7 @@ def test_cloud_redis_grpc_lro_client(): def test_cloud_redis_grpc_lro_async_client(): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -3019,7 +3088,6 @@ def test_instance_path(): project = "squid" location = "clam" instance = "whelk" - expected = "projects/{project}/locations/{location}/instances/{instance}".format( project=project, location=location, instance=instance, ) @@ -3042,7 +3110,6 @@ def test_parse_instance_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -3063,7 +3130,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = CloudRedisClient.common_folder_path(folder) assert expected == actual @@ -3082,7 +3148,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = CloudRedisClient.common_organization_path(organization) assert expected == actual @@ -3101,7 +3166,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = CloudRedisClient.common_project_path(project) assert expected == actual @@ -3121,7 +3185,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -3148,7 +3211,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.CloudRedisTransport, "_prep_wrapped_messages" ) as prep: client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3157,6 +3220,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = CloudRedisClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) diff --git a/tests/unit/gapic/redis_v1beta1/__init__.py b/tests/unit/gapic/redis_v1beta1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/redis_v1beta1/__init__.py +++ b/tests/unit/gapic/redis_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py b/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py index 4c2b6d5..77dad97 100644 --- a/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py +++ b/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,27 +23,57 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import future from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.redis_v1beta1.services.cloud_redis import CloudRedisAsyncClient from google.cloud.redis_v1beta1.services.cloud_redis import CloudRedisClient from google.cloud.redis_v1beta1.services.cloud_redis import pagers from google.cloud.redis_v1beta1.services.cloud_redis import transports +from google.cloud.redis_v1beta1.services.cloud_redis.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.redis_v1beta1.services.cloud_redis.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.redis_v1beta1.types import cloud_redis from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import any_pb2 as gp_any # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -90,7 +119,7 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize("client_class", [CloudRedisClient, CloudRedisAsyncClient,]) def test_cloud_redis_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -105,7 +134,7 @@ def test_cloud_redis_client_from_service_account_info(client_class): @pytest.mark.parametrize("client_class", [CloudRedisClient, CloudRedisAsyncClient,]) def test_cloud_redis_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -156,7 +185,7 @@ def test_cloud_redis_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(CloudRedisClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -440,7 +469,7 @@ def test_list_instances( transport: str = "grpc", request_type=cloud_redis.ListInstancesRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -453,21 +482,16 @@ def test_list_instances( call.return_value = cloud_redis.ListInstancesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) - response = client.list_instances(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ListInstancesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstancesPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -479,7 +503,7 @@ def test_list_instances_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -487,7 +511,6 @@ def test_list_instances_empty_call(): client.list_instances() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ListInstancesRequest() @@ -496,7 +519,7 @@ async def test_list_instances_async( transport: str = "grpc_asyncio", request_type=cloud_redis.ListInstancesRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -512,20 +535,16 @@ async def test_list_instances_async( unreachable=["unreachable_value"], ) ) - response = await client.list_instances(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ListInstancesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListInstancesAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -535,17 +554,17 @@ async def test_list_instances_async_from_dict(): def test_list_instances_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ListInstancesRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: call.return_value = cloud_redis.ListInstancesResponse() - client.list_instances(request) # Establish that the underlying gRPC stub method was called. @@ -560,11 +579,12 @@ def test_list_instances_field_headers(): @pytest.mark.asyncio async def test_list_instances_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ListInstancesRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -572,7 +592,6 @@ async def test_list_instances_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.ListInstancesResponse() ) - await client.list_instances(request) # Establish that the underlying gRPC stub method was called. @@ -586,13 +605,12 @@ async def test_list_instances_field_headers_async(): def test_list_instances_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.ListInstancesResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_instances(parent="parent_value",) @@ -601,12 +619,11 @@ def test_list_instances_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_instances_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -618,7 +635,7 @@ def test_list_instances_flattened_error(): @pytest.mark.asyncio async def test_list_instances_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: @@ -636,13 +653,12 @@ async def test_list_instances_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_instances_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -653,7 +669,7 @@ async def test_list_instances_flattened_error_async(): def test_list_instances_pager(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials,) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: @@ -691,7 +707,7 @@ def test_list_instances_pager(): def test_list_instances_pages(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials,) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: @@ -721,7 +737,7 @@ def test_list_instances_pages(): @pytest.mark.asyncio async def test_list_instances_async_pager(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials,) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -758,7 +774,7 @@ async def test_list_instances_async_pager(): @pytest.mark.asyncio async def test_list_instances_async_pages(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials,) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -794,7 +810,7 @@ def test_get_instance( transport: str = "grpc", request_type=cloud_redis.GetInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -822,49 +838,30 @@ def test_get_instance( persistence_iam_identity="persistence_iam_identity_value", connect_mode=cloud_redis.Instance.ConnectMode.DIRECT_PEERING, ) - response = client.get_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.GetInstanceRequest() # Establish that the response is the type that we expect. - assert isinstance(response, cloud_redis.Instance) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.location_id == "location_id_value" - assert response.alternative_location_id == "alternative_location_id_value" - assert response.redis_version == "redis_version_value" - assert response.reserved_ip_range == "reserved_ip_range_value" - assert response.host == "host_value" - assert response.port == 453 - assert response.current_location_id == "current_location_id_value" - assert response.state == cloud_redis.Instance.State.CREATING - assert response.status_message == "status_message_value" - assert response.tier == cloud_redis.Instance.Tier.BASIC - assert response.memory_size_gb == 1499 - assert response.authorized_network == "authorized_network_value" - assert response.persistence_iam_identity == "persistence_iam_identity_value" - assert response.connect_mode == cloud_redis.Instance.ConnectMode.DIRECT_PEERING @@ -876,7 +873,7 @@ def test_get_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -884,7 +881,6 @@ def test_get_instance_empty_call(): client.get_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.GetInstanceRequest() @@ -893,7 +889,7 @@ async def test_get_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.GetInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -923,48 +919,30 @@ async def test_get_instance_async( connect_mode=cloud_redis.Instance.ConnectMode.DIRECT_PEERING, ) ) - response = await client.get_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.GetInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, cloud_redis.Instance) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.location_id == "location_id_value" - assert response.alternative_location_id == "alternative_location_id_value" - assert response.redis_version == "redis_version_value" - assert response.reserved_ip_range == "reserved_ip_range_value" - assert response.host == "host_value" - assert response.port == 453 - assert response.current_location_id == "current_location_id_value" - assert response.state == cloud_redis.Instance.State.CREATING - assert response.status_message == "status_message_value" - assert response.tier == cloud_redis.Instance.Tier.BASIC - assert response.memory_size_gb == 1499 - assert response.authorized_network == "authorized_network_value" - assert response.persistence_iam_identity == "persistence_iam_identity_value" - assert response.connect_mode == cloud_redis.Instance.ConnectMode.DIRECT_PEERING @@ -974,17 +952,17 @@ async def test_get_instance_async_from_dict(): def test_get_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.GetInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_instance), "__call__") as call: call.return_value = cloud_redis.Instance() - client.get_instance(request) # Establish that the underlying gRPC stub method was called. @@ -999,11 +977,12 @@ def test_get_instance_field_headers(): @pytest.mark.asyncio async def test_get_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.GetInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1011,7 +990,6 @@ async def test_get_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.Instance() ) - await client.get_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1025,13 +1003,12 @@ async def test_get_instance_field_headers_async(): def test_get_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.Instance() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_instance(name="name_value",) @@ -1040,12 +1017,11 @@ def test_get_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1057,7 +1033,7 @@ def test_get_instance_flattened_error(): @pytest.mark.asyncio async def test_get_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_instance), "__call__") as call: @@ -1075,13 +1051,12 @@ async def test_get_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1095,7 +1070,7 @@ def test_create_instance( transport: str = "grpc", request_type=cloud_redis.CreateInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1106,13 +1081,11 @@ def test_create_instance( with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.CreateInstanceRequest() # Establish that the response is the type that we expect. @@ -1127,7 +1100,7 @@ def test_create_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1135,7 +1108,6 @@ def test_create_instance_empty_call(): client.create_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.CreateInstanceRequest() @@ -1144,7 +1116,7 @@ async def test_create_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.CreateInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1157,13 +1129,11 @@ async def test_create_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.CreateInstanceRequest() # Establish that the response is the type that we expect. @@ -1176,17 +1146,17 @@ async def test_create_instance_async_from_dict(): def test_create_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.CreateInstanceRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1201,11 +1171,12 @@ def test_create_instance_field_headers(): @pytest.mark.asyncio async def test_create_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.CreateInstanceRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1213,7 +1184,6 @@ async def test_create_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1227,13 +1197,12 @@ async def test_create_instance_field_headers_async(): def test_create_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_instance( @@ -1246,16 +1215,13 @@ def test_create_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].instance_id == "instance_id_value" - assert args[0].instance == cloud_redis.Instance(name="name_value") def test_create_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1270,7 +1236,7 @@ def test_create_instance_flattened_error(): @pytest.mark.asyncio async def test_create_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_instance), "__call__") as call: @@ -1292,17 +1258,14 @@ async def test_create_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].instance_id == "instance_id_value" - assert args[0].instance == cloud_redis.Instance(name="name_value") @pytest.mark.asyncio async def test_create_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1319,7 +1282,7 @@ def test_update_instance( transport: str = "grpc", request_type=cloud_redis.UpdateInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1330,13 +1293,11 @@ def test_update_instance( with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpdateInstanceRequest() # Establish that the response is the type that we expect. @@ -1351,7 +1312,7 @@ def test_update_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1359,7 +1320,6 @@ def test_update_instance_empty_call(): client.update_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpdateInstanceRequest() @@ -1368,7 +1328,7 @@ async def test_update_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.UpdateInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1381,13 +1341,11 @@ async def test_update_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpdateInstanceRequest() # Establish that the response is the type that we expect. @@ -1400,17 +1358,17 @@ async def test_update_instance_async_from_dict(): def test_update_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.UpdateInstanceRequest() + request.instance.name = "instance.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1427,11 +1385,12 @@ def test_update_instance_field_headers(): @pytest.mark.asyncio async def test_update_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.UpdateInstanceRequest() + request.instance.name = "instance.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1439,7 +1398,6 @@ async def test_update_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1455,17 +1413,16 @@ async def test_update_instance_field_headers_async(): def test_update_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_instance( - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), instance=cloud_redis.Instance(name="name_value"), ) @@ -1473,28 +1430,26 @@ def test_update_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) - + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) assert args[0].instance == cloud_redis.Instance(name="name_value") def test_update_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.update_instance( cloud_redis.UpdateInstanceRequest(), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), instance=cloud_redis.Instance(name="name_value"), ) @pytest.mark.asyncio async def test_update_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_instance), "__call__") as call: @@ -1507,7 +1462,7 @@ async def test_update_instance_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.update_instance( - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), instance=cloud_redis.Instance(name="name_value"), ) @@ -1515,22 +1470,20 @@ async def test_update_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) - + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) assert args[0].instance == cloud_redis.Instance(name="name_value") @pytest.mark.asyncio async def test_update_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.update_instance( cloud_redis.UpdateInstanceRequest(), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), instance=cloud_redis.Instance(name="name_value"), ) @@ -1539,7 +1492,7 @@ def test_upgrade_instance( transport: str = "grpc", request_type=cloud_redis.UpgradeInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1550,13 +1503,11 @@ def test_upgrade_instance( with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpgradeInstanceRequest() # Establish that the response is the type that we expect. @@ -1571,7 +1522,7 @@ def test_upgrade_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1579,7 +1530,6 @@ def test_upgrade_instance_empty_call(): client.upgrade_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpgradeInstanceRequest() @@ -1588,7 +1538,7 @@ async def test_upgrade_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.UpgradeInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1601,13 +1551,11 @@ async def test_upgrade_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.UpgradeInstanceRequest() # Establish that the response is the type that we expect. @@ -1620,17 +1568,17 @@ async def test_upgrade_instance_async_from_dict(): def test_upgrade_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.UpgradeInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1645,11 +1593,12 @@ def test_upgrade_instance_field_headers(): @pytest.mark.asyncio async def test_upgrade_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.UpgradeInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1657,7 +1606,6 @@ async def test_upgrade_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1671,13 +1619,12 @@ async def test_upgrade_instance_field_headers_async(): def test_upgrade_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.upgrade_instance( @@ -1688,14 +1635,12 @@ def test_upgrade_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].redis_version == "redis_version_value" def test_upgrade_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1709,7 +1654,7 @@ def test_upgrade_instance_flattened_error(): @pytest.mark.asyncio async def test_upgrade_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: @@ -1729,15 +1674,13 @@ async def test_upgrade_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].redis_version == "redis_version_value" @pytest.mark.asyncio async def test_upgrade_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1753,7 +1696,7 @@ def test_import_instance( transport: str = "grpc", request_type=cloud_redis.ImportInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1764,13 +1707,11 @@ def test_import_instance( with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.import_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ImportInstanceRequest() # Establish that the response is the type that we expect. @@ -1785,7 +1726,7 @@ def test_import_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1793,7 +1734,6 @@ def test_import_instance_empty_call(): client.import_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ImportInstanceRequest() @@ -1802,7 +1742,7 @@ async def test_import_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.ImportInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1815,13 +1755,11 @@ async def test_import_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.import_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ImportInstanceRequest() # Establish that the response is the type that we expect. @@ -1834,17 +1772,17 @@ async def test_import_instance_async_from_dict(): def test_import_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ImportInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.import_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1859,11 +1797,12 @@ def test_import_instance_field_headers(): @pytest.mark.asyncio async def test_import_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ImportInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1871,7 +1810,6 @@ async def test_import_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.import_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1885,13 +1823,12 @@ async def test_import_instance_field_headers_async(): def test_import_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.import_instance( @@ -1905,16 +1842,14 @@ def test_import_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == cloud_redis.InputConfig( gcs_source=cloud_redis.GcsSource(uri="uri_value") ) def test_import_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1930,7 +1865,7 @@ def test_import_instance_flattened_error(): @pytest.mark.asyncio async def test_import_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_instance), "__call__") as call: @@ -1953,9 +1888,7 @@ async def test_import_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].input_config == cloud_redis.InputConfig( gcs_source=cloud_redis.GcsSource(uri="uri_value") ) @@ -1963,7 +1896,7 @@ async def test_import_instance_flattened_async(): @pytest.mark.asyncio async def test_import_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1981,7 +1914,7 @@ def test_export_instance( transport: str = "grpc", request_type=cloud_redis.ExportInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1992,13 +1925,11 @@ def test_export_instance( with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.export_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ExportInstanceRequest() # Establish that the response is the type that we expect. @@ -2013,7 +1944,7 @@ def test_export_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2021,7 +1952,6 @@ def test_export_instance_empty_call(): client.export_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ExportInstanceRequest() @@ -2030,7 +1960,7 @@ async def test_export_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.ExportInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2043,13 +1973,11 @@ async def test_export_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.export_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.ExportInstanceRequest() # Establish that the response is the type that we expect. @@ -2062,17 +1990,17 @@ async def test_export_instance_async_from_dict(): def test_export_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ExportInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.export_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2087,11 +2015,12 @@ def test_export_instance_field_headers(): @pytest.mark.asyncio async def test_export_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.ExportInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2099,7 +2028,6 @@ async def test_export_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.export_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2113,13 +2041,12 @@ async def test_export_instance_field_headers_async(): def test_export_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.export_instance( @@ -2133,16 +2060,14 @@ def test_export_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == cloud_redis.OutputConfig( gcs_destination=cloud_redis.GcsDestination(uri="uri_value") ) def test_export_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2158,7 +2083,7 @@ def test_export_instance_flattened_error(): @pytest.mark.asyncio async def test_export_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_instance), "__call__") as call: @@ -2181,9 +2106,7 @@ async def test_export_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == cloud_redis.OutputConfig( gcs_destination=cloud_redis.GcsDestination(uri="uri_value") ) @@ -2191,7 +2114,7 @@ async def test_export_instance_flattened_async(): @pytest.mark.asyncio async def test_export_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2209,7 +2132,7 @@ def test_failover_instance( transport: str = "grpc", request_type=cloud_redis.FailoverInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2222,13 +2145,11 @@ def test_failover_instance( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.failover_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.FailoverInstanceRequest() # Establish that the response is the type that we expect. @@ -2243,7 +2164,7 @@ def test_failover_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2253,7 +2174,6 @@ def test_failover_instance_empty_call(): client.failover_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.FailoverInstanceRequest() @@ -2262,7 +2182,7 @@ async def test_failover_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.FailoverInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2277,13 +2197,11 @@ async def test_failover_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.failover_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.FailoverInstanceRequest() # Establish that the response is the type that we expect. @@ -2296,11 +2214,12 @@ async def test_failover_instance_async_from_dict(): def test_failover_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.FailoverInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2308,7 +2227,6 @@ def test_failover_instance_field_headers(): type(client.transport.failover_instance), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.failover_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2323,11 +2241,12 @@ def test_failover_instance_field_headers(): @pytest.mark.asyncio async def test_failover_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.FailoverInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2337,7 +2256,6 @@ async def test_failover_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.failover_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2351,7 +2269,7 @@ async def test_failover_instance_field_headers_async(): def test_failover_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2359,7 +2277,6 @@ def test_failover_instance_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.failover_instance( @@ -2371,9 +2288,7 @@ def test_failover_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert ( args[0].data_protection_mode == cloud_redis.FailoverInstanceRequest.DataProtectionMode.LIMITED_DATA_LOSS @@ -2381,7 +2296,7 @@ def test_failover_instance_flattened(): def test_failover_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2395,7 +2310,7 @@ def test_failover_instance_flattened_error(): @pytest.mark.asyncio async def test_failover_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2418,9 +2333,7 @@ async def test_failover_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert ( args[0].data_protection_mode == cloud_redis.FailoverInstanceRequest.DataProtectionMode.LIMITED_DATA_LOSS @@ -2429,7 +2342,7 @@ async def test_failover_instance_flattened_async(): @pytest.mark.asyncio async def test_failover_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2445,7 +2358,7 @@ def test_delete_instance( transport: str = "grpc", request_type=cloud_redis.DeleteInstanceRequest ): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2456,13 +2369,11 @@ def test_delete_instance( with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.DeleteInstanceRequest() # Establish that the response is the type that we expect. @@ -2477,7 +2388,7 @@ def test_delete_instance_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 = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2485,7 +2396,6 @@ def test_delete_instance_empty_call(): client.delete_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.DeleteInstanceRequest() @@ -2494,7 +2404,7 @@ async def test_delete_instance_async( transport: str = "grpc_asyncio", request_type=cloud_redis.DeleteInstanceRequest ): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2507,13 +2417,11 @@ async def test_delete_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_redis.DeleteInstanceRequest() # Establish that the response is the type that we expect. @@ -2526,17 +2434,17 @@ async def test_delete_instance_async_from_dict(): def test_delete_instance_field_headers(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.DeleteInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2551,11 +2459,12 @@ def test_delete_instance_field_headers(): @pytest.mark.asyncio async def test_delete_instance_field_headers_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = cloud_redis.DeleteInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2563,7 +2472,6 @@ async def test_delete_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2577,13 +2485,12 @@ async def test_delete_instance_field_headers_async(): def test_delete_instance_flattened(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_instance(name="name_value",) @@ -2592,12 +2499,11 @@ def test_delete_instance_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_instance_flattened_error(): - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2609,7 +2515,7 @@ def test_delete_instance_flattened_error(): @pytest.mark.asyncio async def test_delete_instance_flattened_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: @@ -2627,13 +2533,12 @@ async def test_delete_instance_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_instance_flattened_error_async(): - client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2646,16 +2551,16 @@ async def test_delete_instance_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CloudRedisGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.CloudRedisGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudRedisClient( @@ -2665,7 +2570,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.CloudRedisGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudRedisClient( @@ -2676,7 +2581,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CloudRedisGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = CloudRedisClient(transport=transport) assert client.transport is transport @@ -2685,13 +2590,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.CloudRedisGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.CloudRedisGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2703,23 +2608,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.CloudRedisGrpcTransport,) def test_cloud_redis_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.CloudRedisTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2731,7 +2636,7 @@ def test_cloud_redis_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CloudRedisTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2757,15 +2662,37 @@ def test_cloud_redis_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_cloud_redis_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.redis_v1beta1.services.cloud_redis.transports.CloudRedisTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.CloudRedisTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_cloud_redis_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.redis_v1beta1.services.cloud_redis.transports.CloudRedisTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudRedisTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -2778,19 +2705,33 @@ def test_cloud_redis_base_transport_with_credentials_file(): def test_cloud_redis_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.redis_v1beta1.services.cloud_redis.transports.CloudRedisTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudRedisTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_cloud_redis_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + CloudRedisClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_cloud_redis_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) CloudRedisClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -2798,26 +2739,156 @@ def test_cloud_redis_auth_adc(): ) -def test_cloud_redis_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [transports.CloudRedisGrpcTransport, transports.CloudRedisGrpcAsyncIOTransport,], +) +@requires_google_auth_gte_1_25_0 +def test_cloud_redis_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.CloudRedisGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [transports.CloudRedisGrpcTransport, transports.CloudRedisGrpcAsyncIOTransport,], +) +@requires_google_auth_lt_1_25_0 +def test_cloud_redis_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.CloudRedisGrpcTransport, grpc_helpers), + (transports.CloudRedisGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_cloud_redis_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "redis.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="redis.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.CloudRedisGrpcTransport, grpc_helpers), + (transports.CloudRedisGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_cloud_redis_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "redis.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.CloudRedisGrpcTransport, grpc_helpers), + (transports.CloudRedisGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_cloud_redis_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "redis.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [transports.CloudRedisGrpcTransport, transports.CloudRedisGrpcAsyncIOTransport], ) def test_cloud_redis_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2856,7 +2927,7 @@ def test_cloud_redis_grpc_transport_client_cert_source_for_mtls(transport_class) def test_cloud_redis_host_no_port(): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="redis.googleapis.com" ), @@ -2866,7 +2937,7 @@ def test_cloud_redis_host_no_port(): def test_cloud_redis_host_with_port(): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="redis.googleapis.com:8000" ), @@ -2917,9 +2988,9 @@ def test_cloud_redis_transport_channel_mtls_with_client_cert_source(transport_cl mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -2992,7 +3063,7 @@ def test_cloud_redis_transport_channel_mtls_with_adc(transport_class): def test_cloud_redis_grpc_lro_client(): client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -3005,7 +3076,7 @@ def test_cloud_redis_grpc_lro_client(): def test_cloud_redis_grpc_lro_async_client(): client = CloudRedisAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -3020,7 +3091,6 @@ def test_instance_path(): project = "squid" location = "clam" instance = "whelk" - expected = "projects/{project}/locations/{location}/instances/{instance}".format( project=project, location=location, instance=instance, ) @@ -3043,7 +3113,6 @@ def test_parse_instance_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -3064,7 +3133,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = CloudRedisClient.common_folder_path(folder) assert expected == actual @@ -3083,7 +3151,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = CloudRedisClient.common_organization_path(organization) assert expected == actual @@ -3102,7 +3169,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = CloudRedisClient.common_project_path(project) assert expected == actual @@ -3122,7 +3188,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -3149,7 +3214,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.CloudRedisTransport, "_prep_wrapped_messages" ) as prep: client = CloudRedisClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3158,6 +3223,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = CloudRedisClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info)