From 2d1aaf439d096857a727752ae129852b279c3658 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 26 Jun 2021 07:52:23 -0400 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.46.3 (#67) This PR is the result of manually running the following commands in order to pull in the latest changes from googleapis-gen which includes gapic generator version 0.46.3: 1. Download the latest docker image for owlbot-cli ``` docker pull gcr.io/repo-automation-bots/owlbot-cli:latest ``` 2. Run the owlbot-cli to copy the generated client from googleapis/googleapis-gen ``` docker run --rm --user $(id -u):$(id -g) -v $(pwd):/repo -w /repo gcr.io/repo-automation-bots/owlbot-cli:latest copy-code ``` 3. Download the latest docker image for owlbot-python ``` docker pull gcr.io/repo-automation-bots/owlbot-python:latest ``` 4. Run the post processor image ``` docker run --user $(id -u):$(id -g) --rm -v $(pwd):/repo -w /repo gcr.io/repo-automation-bots/owlbot-python:latest ``` Other features/fixes include: fix: add async client to %name_%version/init.py chore: add autogenerated snippets chore: remove auth, policy, and options from the reserved names list feat: support self-signed JWT flow for service accounts chore: enable GAPIC metadata generation chore: sort subpackages in %namespace/%name/init.py --- docs/memcache_v1/cloud_memcache.rst | 1 - docs/memcache_v1beta2/cloud_memcache.rst | 1 - google/cloud/memcache/__init__.py | 12 +- google/cloud/memcache_v1/__init__.py | 9 +- google/cloud/memcache_v1/gapic_metadata.json | 93 +++ google/cloud/memcache_v1/services/__init__.py | 1 - .../services/cloud_memcache/__init__.py | 2 - .../services/cloud_memcache/async_client.py | 51 +- .../services/cloud_memcache/client.py | 94 +-- .../services/cloud_memcache/pagers.py | 4 +- .../cloud_memcache/transports/__init__.py | 2 - .../cloud_memcache/transports/base.py | 132 +++- .../cloud_memcache/transports/grpc.py | 44 +- .../cloud_memcache/transports/grpc_asyncio.py | 45 +- google/cloud/memcache_v1/types/__init__.py | 2 - .../cloud/memcache_v1/types/cloud_memcache.py | 151 ++-- google/cloud/memcache_v1beta2/__init__.py | 9 +- .../memcache_v1beta2/gapic_metadata.json | 103 +++ .../memcache_v1beta2/services/__init__.py | 1 - .../services/cloud_memcache/__init__.py | 2 - .../services/cloud_memcache/async_client.py | 54 +- .../services/cloud_memcache/client.py | 97 +-- .../services/cloud_memcache/pagers.py | 4 +- .../cloud_memcache/transports/__init__.py | 2 - .../cloud_memcache/transports/base.py | 136 ++-- .../cloud_memcache/transports/grpc.py | 50 +- .../cloud_memcache/transports/grpc_asyncio.py | 49 +- .../cloud/memcache_v1beta2/types/__init__.py | 2 - .../memcache_v1beta2/types/cloud_memcache.py | 166 ++--- scripts/fixup_memcache_v1_keywords.py | 19 +- scripts/fixup_memcache_v1beta2_keywords.py | 21 +- setup.py | 1 + testing/constraints-3.6.txt | 2 + tests/__init__.py | 15 + tests/unit/__init__.py | 15 + tests/unit/gapic/__init__.py | 15 + tests/unit/gapic/memcache_v1/__init__.py | 1 - .../gapic/memcache_v1/test_cloud_memcache.py | 615 +++++++++------- tests/unit/gapic/memcache_v1beta2/__init__.py | 1 - .../memcache_v1beta2/test_cloud_memcache.py | 657 +++++++++++------- 40 files changed, 1558 insertions(+), 1123 deletions(-) create mode 100644 google/cloud/memcache_v1/gapic_metadata.json create mode 100644 google/cloud/memcache_v1beta2/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/memcache_v1/cloud_memcache.rst b/docs/memcache_v1/cloud_memcache.rst index 0c21866..35de375 100644 --- a/docs/memcache_v1/cloud_memcache.rst +++ b/docs/memcache_v1/cloud_memcache.rst @@ -5,7 +5,6 @@ CloudMemcache :members: :inherited-members: - .. automodule:: google.cloud.memcache_v1.services.cloud_memcache.pagers :members: :inherited-members: diff --git a/docs/memcache_v1beta2/cloud_memcache.rst b/docs/memcache_v1beta2/cloud_memcache.rst index b20fc3a..7dc7a82 100644 --- a/docs/memcache_v1beta2/cloud_memcache.rst +++ b/docs/memcache_v1beta2/cloud_memcache.rst @@ -5,7 +5,6 @@ CloudMemcache :members: :inherited-members: - .. automodule:: google.cloud.memcache_v1beta2.services.cloud_memcache.pagers :members: :inherited-members: diff --git a/google/cloud/memcache/__init__.py b/google/cloud/memcache/__init__.py index 4075bad..f2b7c14 100644 --- a/google/cloud/memcache/__init__.py +++ b/google/cloud/memcache/__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.memcache_v1.services.cloud_memcache.client import CloudMemcacheClient from google.cloud.memcache_v1.services.cloud_memcache.async_client import ( CloudMemcacheAsyncClient, ) -from google.cloud.memcache_v1.services.cloud_memcache.client import CloudMemcacheClient + from google.cloud.memcache_v1.types.cloud_memcache import ApplyParametersRequest from google.cloud.memcache_v1.types.cloud_memcache import CreateInstanceRequest from google.cloud.memcache_v1.types.cloud_memcache import DeleteInstanceRequest @@ -27,15 +27,15 @@ from google.cloud.memcache_v1.types.cloud_memcache import ListInstancesRequest from google.cloud.memcache_v1.types.cloud_memcache import ListInstancesResponse from google.cloud.memcache_v1.types.cloud_memcache import MemcacheParameters -from google.cloud.memcache_v1.types.cloud_memcache import MemcacheVersion from google.cloud.memcache_v1.types.cloud_memcache import OperationMetadata from google.cloud.memcache_v1.types.cloud_memcache import UpdateInstanceRequest from google.cloud.memcache_v1.types.cloud_memcache import UpdateParametersRequest +from google.cloud.memcache_v1.types.cloud_memcache import MemcacheVersion __all__ = ( - "ApplyParametersRequest", - "CloudMemcacheAsyncClient", "CloudMemcacheClient", + "CloudMemcacheAsyncClient", + "ApplyParametersRequest", "CreateInstanceRequest", "DeleteInstanceRequest", "GetInstanceRequest", @@ -43,8 +43,8 @@ "ListInstancesRequest", "ListInstancesResponse", "MemcacheParameters", - "MemcacheVersion", "OperationMetadata", "UpdateInstanceRequest", "UpdateParametersRequest", + "MemcacheVersion", ) diff --git a/google/cloud/memcache_v1/__init__.py b/google/cloud/memcache_v1/__init__.py index 4d28d1b..7d3016d 100644 --- a/google/cloud/memcache_v1/__init__.py +++ b/google/cloud/memcache_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_memcache import CloudMemcacheClient +from .services.cloud_memcache import CloudMemcacheAsyncClient + from .types.cloud_memcache import ApplyParametersRequest from .types.cloud_memcache import CreateInstanceRequest from .types.cloud_memcache import DeleteInstanceRequest @@ -24,14 +25,15 @@ from .types.cloud_memcache import ListInstancesRequest from .types.cloud_memcache import ListInstancesResponse from .types.cloud_memcache import MemcacheParameters -from .types.cloud_memcache import MemcacheVersion from .types.cloud_memcache import OperationMetadata from .types.cloud_memcache import UpdateInstanceRequest from .types.cloud_memcache import UpdateParametersRequest - +from .types.cloud_memcache import MemcacheVersion __all__ = ( + "CloudMemcacheAsyncClient", "ApplyParametersRequest", + "CloudMemcacheClient", "CreateInstanceRequest", "DeleteInstanceRequest", "GetInstanceRequest", @@ -43,5 +45,4 @@ "OperationMetadata", "UpdateInstanceRequest", "UpdateParametersRequest", - "CloudMemcacheClient", ) diff --git a/google/cloud/memcache_v1/gapic_metadata.json b/google/cloud/memcache_v1/gapic_metadata.json new file mode 100644 index 0000000..08d37fa --- /dev/null +++ b/google/cloud/memcache_v1/gapic_metadata.json @@ -0,0 +1,93 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.memcache_v1", + "protoPackage": "google.cloud.memcache.v1", + "schema": "1.0", + "services": { + "CloudMemcache": { + "clients": { + "grpc": { + "libraryClient": "CloudMemcacheClient", + "rpcs": { + "ApplyParameters": { + "methods": [ + "apply_parameters" + ] + }, + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpdateParameters": { + "methods": [ + "update_parameters" + ] + } + } + }, + "grpc-async": { + "libraryClient": "CloudMemcacheAsyncClient", + "rpcs": { + "ApplyParameters": { + "methods": [ + "apply_parameters" + ] + }, + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpdateParameters": { + "methods": [ + "update_parameters" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/memcache_v1/services/__init__.py b/google/cloud/memcache_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/memcache_v1/services/__init__.py +++ b/google/cloud/memcache_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/memcache_v1/services/cloud_memcache/__init__.py b/google/cloud/memcache_v1/services/cloud_memcache/__init__.py index 8524cb4..efb245e 100644 --- a/google/cloud/memcache_v1/services/cloud_memcache/__init__.py +++ b/google/cloud/memcache_v1/services/cloud_memcache/__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 CloudMemcacheClient from .async_client import CloudMemcacheAsyncClient diff --git a/google/cloud/memcache_v1/services/cloud_memcache/async_client.py b/google/cloud/memcache_v1/services/cloud_memcache/async_client.py index b09fddb..738a2db 100644 --- a/google/cloud/memcache_v1/services/cloud_memcache/async_client.py +++ b/google/cloud/memcache_v1/services/cloud_memcache/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.memcache_v1.services.cloud_memcache import pagers from google.cloud.memcache_v1.types import cloud_memcache -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 CloudMemcacheTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import CloudMemcacheGrpcAsyncIOTransport from .client import CloudMemcacheClient @@ -70,31 +67,26 @@ class CloudMemcacheAsyncClient: instance_path = staticmethod(CloudMemcacheClient.instance_path) parse_instance_path = staticmethod(CloudMemcacheClient.parse_instance_path) - common_billing_account_path = staticmethod( CloudMemcacheClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( CloudMemcacheClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(CloudMemcacheClient.common_folder_path) parse_common_folder_path = staticmethod( CloudMemcacheClient.parse_common_folder_path ) - common_organization_path = staticmethod( CloudMemcacheClient.common_organization_path ) parse_common_organization_path = staticmethod( CloudMemcacheClient.parse_common_organization_path ) - common_project_path = staticmethod(CloudMemcacheClient.common_project_path) parse_common_project_path = staticmethod( CloudMemcacheClient.parse_common_project_path ) - common_location_path = staticmethod(CloudMemcacheClient.common_location_path) parse_common_location_path = staticmethod( CloudMemcacheClient.parse_common_location_path @@ -102,7 +94,8 @@ class CloudMemcacheAsyncClient: @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. @@ -117,7 +110,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 @@ -134,7 +127,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> CloudMemcacheTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: CloudMemcacheTransport: The transport used by the client instance. @@ -148,12 +141,12 @@ def transport(self) -> CloudMemcacheTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, CloudMemcacheTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the cloud memcache client. + """Instantiates the cloud memcache client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -185,7 +178,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = CloudMemcacheClient( credentials=credentials, transport=transport, @@ -217,7 +209,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. @@ -247,7 +238,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 @@ -301,7 +291,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. @@ -326,7 +315,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 @@ -398,7 +386,6 @@ async def create_instance( This corresponds to the ``instance_id`` 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. @@ -427,7 +414,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 is not None: @@ -468,7 +454,7 @@ async def update_instance( request: cloud_memcache.UpdateInstanceRequest = None, *, instance: cloud_memcache.Instance = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -495,7 +481,6 @@ async def update_instance( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -524,7 +509,6 @@ async def update_instance( # If we have keyword arguments corresponding to fields on the # request, apply these. - if instance is not None: request.instance = instance if update_mask is not None: @@ -565,7 +549,7 @@ async def update_parameters( request: cloud_memcache.UpdateParametersRequest = None, *, name: str = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, parameters: cloud_memcache.MemcacheParameters = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -600,7 +584,6 @@ async def update_parameters( This corresponds to the ``parameters`` 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. @@ -629,7 +612,6 @@ async def update_parameters( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if update_mask is not None: @@ -689,7 +671,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. @@ -729,7 +710,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 @@ -754,7 +734,7 @@ async def delete_instance( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=cloud_memcache.OperationMetadata, ) @@ -806,7 +786,6 @@ async def apply_parameters( This corresponds to the ``apply_all`` 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. @@ -835,12 +814,10 @@ async def apply_parameters( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if apply_all is not None: request.apply_all = apply_all - if node_ids: request.node_ids.extend(node_ids) diff --git a/google/cloud/memcache_v1/services/cloud_memcache/client.py b/google/cloud/memcache_v1/services/cloud_memcache/client.py index 591ee49..3152eee 100644 --- a/google/cloud/memcache_v1/services/cloud_memcache/client.py +++ b/google/cloud/memcache_v1/services/cloud_memcache/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.memcache_v1.services.cloud_memcache import pagers from google.cloud.memcache_v1.types import cloud_memcache -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 CloudMemcacheTransport, DEFAULT_CLIENT_INFO from .transports.grpc import CloudMemcacheGrpcTransport from .transports.grpc_asyncio import CloudMemcacheGrpcAsyncIOTransport @@ -58,7 +55,7 @@ class CloudMemcacheClientMeta(type): _transport_registry["grpc_asyncio"] = CloudMemcacheGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[CloudMemcacheTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -100,7 +97,8 @@ class CloudMemcacheClient(metaclass=CloudMemcacheClientMeta): @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: @@ -134,7 +132,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. @@ -151,7 +150,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 @@ -170,23 +169,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> CloudMemcacheTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - CloudMemcacheTransport: The transport used by the client instance. + CloudMemcacheTransport: 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, @@ -195,7 +195,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, ) @@ -208,7 +208,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 @@ -219,7 +219,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 @@ -230,7 +230,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 @@ -241,7 +241,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, ) @@ -255,12 +255,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, CloudMemcacheTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the cloud memcache client. + """Instantiates the cloud memcache client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -315,9 +315,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: @@ -329,12 +330,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. @@ -349,8 +352,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: @@ -389,7 +392,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. @@ -421,10 +423,8 @@ def list_instances( # there are no flattened fields. if not isinstance(request, cloud_memcache.ListInstancesRequest): request = cloud_memcache.ListInstancesRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -474,7 +474,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. @@ -501,10 +500,8 @@ def get_instance( # there are no flattened fields. if not isinstance(request, cloud_memcache.GetInstanceRequest): request = cloud_memcache.GetInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -572,7 +569,6 @@ def create_instance( This corresponds to the ``instance_id`` 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. @@ -603,10 +599,8 @@ def create_instance( # there are no flattened fields. if not isinstance(request, cloud_memcache.CreateInstanceRequest): request = cloud_memcache.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 is not None: @@ -643,7 +637,7 @@ def update_instance( request: cloud_memcache.UpdateInstanceRequest = None, *, instance: cloud_memcache.Instance = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -670,7 +664,6 @@ def update_instance( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -701,10 +694,8 @@ def update_instance( # there are no flattened fields. if not isinstance(request, cloud_memcache.UpdateInstanceRequest): request = cloud_memcache.UpdateInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if instance is not None: request.instance = instance if update_mask is not None: @@ -741,7 +732,7 @@ def update_parameters( request: cloud_memcache.UpdateParametersRequest = None, *, name: str = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, parameters: cloud_memcache.MemcacheParameters = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -776,7 +767,6 @@ def update_parameters( This corresponds to the ``parameters`` 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. @@ -807,10 +797,8 @@ def update_parameters( # there are no flattened fields. if not isinstance(request, cloud_memcache.UpdateParametersRequest): request = cloud_memcache.UpdateParametersRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if update_mask is not None: @@ -866,7 +854,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. @@ -908,10 +895,8 @@ def delete_instance( # there are no flattened fields. if not isinstance(request, cloud_memcache.DeleteInstanceRequest): request = cloud_memcache.DeleteInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -932,7 +917,7 @@ def delete_instance( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=cloud_memcache.OperationMetadata, ) @@ -984,7 +969,6 @@ def apply_parameters( This corresponds to the ``apply_all`` 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. @@ -1015,10 +999,8 @@ def apply_parameters( # there are no flattened fields. if not isinstance(request, cloud_memcache.ApplyParametersRequest): request = cloud_memcache.ApplyParametersRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if node_ids is not None: diff --git a/google/cloud/memcache_v1/services/cloud_memcache/pagers.py b/google/cloud/memcache_v1/services/cloud_memcache/pagers.py index 7a1324e..7723778 100644 --- a/google/cloud/memcache_v1/services/cloud_memcache/pagers.py +++ b/google/cloud/memcache_v1/services/cloud_memcache/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/memcache_v1/services/cloud_memcache/transports/__init__.py b/google/cloud/memcache_v1/services/cloud_memcache/transports/__init__.py index 38122c6..32ad848 100644 --- a/google/cloud/memcache_v1/services/cloud_memcache/transports/__init__.py +++ b/google/cloud/memcache_v1/services/cloud_memcache/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/memcache_v1/services/cloud_memcache/transports/base.py b/google/cloud/memcache_v1/services/cloud_memcache/transports/base.py index c9b57c7..393f376 100644 --- a/google/cloud/memcache_v1/services/cloud_memcache/transports/base.py +++ b/google/cloud/memcache_v1/services/cloud_memcache/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.memcache_v1.types import cloud_memcache -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 CloudMemcacheTransport(abc.ABC): """Abstract transport class for CloudMemcache.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "memcache.googleapis.com" + def __init__( self, *, - host: str = "memcache.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 = { @@ -137,11 +197,11 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_instances( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.ListInstancesRequest], - typing.Union[ + Union[ cloud_memcache.ListInstancesResponse, - typing.Awaitable[cloud_memcache.ListInstancesResponse], + Awaitable[cloud_memcache.ListInstancesResponse], ], ]: raise NotImplementedError() @@ -149,56 +209,54 @@ def list_instances( @property def get_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.GetInstanceRequest], - typing.Union[ - cloud_memcache.Instance, typing.Awaitable[cloud_memcache.Instance] - ], + Union[cloud_memcache.Instance, Awaitable[cloud_memcache.Instance]], ]: raise NotImplementedError() @property def create_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.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_memcache.UpdateInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_parameters( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.UpdateParametersRequest], - 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_memcache.DeleteInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def apply_parameters( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.ApplyParametersRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc.py b/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc.py index 61c7dde..5467640 100644 --- a/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc.py +++ b/google/cloud/memcache_v1/services/cloud_memcache/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.memcache_v1.types import cloud_memcache -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import CloudMemcacheTransport, DEFAULT_CLIENT_INFO @@ -70,7 +67,7 @@ def __init__( self, *, host: str = "memcache.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -84,7 +81,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 @@ -195,7 +193,7 @@ def __init__( def create_channel( cls, host: str = "memcache.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, @@ -226,13 +224,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, ) @@ -313,7 +313,7 @@ def get_instance( @property def create_instance( self, - ) -> Callable[[cloud_memcache.CreateInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_memcache.CreateInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the create instance method over gRPC. Creates a new Instance in a given location. @@ -332,14 +332,14 @@ def create_instance( self._stubs["create_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1.CloudMemcache/CreateInstance", request_serializer=cloud_memcache.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_memcache.UpdateInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_memcache.UpdateInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the update instance method over gRPC. Updates an existing Instance in a given project and @@ -359,14 +359,14 @@ def update_instance( self._stubs["update_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1.CloudMemcache/UpdateInstance", request_serializer=cloud_memcache.UpdateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_instance"] @property def update_parameters( self, - ) -> Callable[[cloud_memcache.UpdateParametersRequest], operations.Operation]: + ) -> Callable[[cloud_memcache.UpdateParametersRequest], operations_pb2.Operation]: r"""Return a callable for the update parameters method over gRPC. Updates the defined Memcached Parameters for an @@ -388,14 +388,14 @@ def update_parameters( self._stubs["update_parameters"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1.CloudMemcache/UpdateParameters", request_serializer=cloud_memcache.UpdateParametersRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_parameters"] @property def delete_instance( self, - ) -> Callable[[cloud_memcache.DeleteInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_memcache.DeleteInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the delete instance method over gRPC. Deletes a single Instance. @@ -414,14 +414,14 @@ def delete_instance( self._stubs["delete_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1.CloudMemcache/DeleteInstance", request_serializer=cloud_memcache.DeleteInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_instance"] @property def apply_parameters( self, - ) -> Callable[[cloud_memcache.ApplyParametersRequest], operations.Operation]: + ) -> Callable[[cloud_memcache.ApplyParametersRequest], operations_pb2.Operation]: r"""Return a callable for the apply parameters method over gRPC. ApplyParameters will restart the set of specified @@ -442,7 +442,7 @@ def apply_parameters( self._stubs["apply_parameters"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1.CloudMemcache/ApplyParameters", request_serializer=cloud_memcache.ApplyParametersRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["apply_parameters"] diff --git a/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc_asyncio.py b/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc_asyncio.py index d669536..b21cfd3 100644 --- a/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc_asyncio.py +++ b/google/cloud/memcache_v1/services/cloud_memcache/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.memcache_v1.types import cloud_memcache -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import CloudMemcacheTransport, DEFAULT_CLIENT_INFO from .grpc import CloudMemcacheGrpcTransport @@ -73,7 +70,7 @@ class CloudMemcacheGrpcAsyncIOTransport(CloudMemcacheTransport): def create_channel( cls, host: str = "memcache.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, @@ -100,13 +97,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, ) @@ -114,7 +113,7 @@ def __init__( self, *, host: str = "memcache.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, @@ -128,7 +127,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 @@ -187,7 +187,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 @@ -323,7 +322,7 @@ def get_instance( def create_instance( self, ) -> Callable[ - [cloud_memcache.CreateInstanceRequest], Awaitable[operations.Operation] + [cloud_memcache.CreateInstanceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the create instance method over gRPC. @@ -343,7 +342,7 @@ def create_instance( self._stubs["create_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1.CloudMemcache/CreateInstance", request_serializer=cloud_memcache.CreateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_instance"] @@ -351,7 +350,7 @@ def create_instance( def update_instance( self, ) -> Callable[ - [cloud_memcache.UpdateInstanceRequest], Awaitable[operations.Operation] + [cloud_memcache.UpdateInstanceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the update instance method over gRPC. @@ -372,7 +371,7 @@ def update_instance( self._stubs["update_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1.CloudMemcache/UpdateInstance", request_serializer=cloud_memcache.UpdateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_instance"] @@ -380,7 +379,7 @@ def update_instance( def update_parameters( self, ) -> Callable[ - [cloud_memcache.UpdateParametersRequest], Awaitable[operations.Operation] + [cloud_memcache.UpdateParametersRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the update parameters method over gRPC. @@ -403,7 +402,7 @@ def update_parameters( self._stubs["update_parameters"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1.CloudMemcache/UpdateParameters", request_serializer=cloud_memcache.UpdateParametersRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_parameters"] @@ -411,7 +410,7 @@ def update_parameters( def delete_instance( self, ) -> Callable[ - [cloud_memcache.DeleteInstanceRequest], Awaitable[operations.Operation] + [cloud_memcache.DeleteInstanceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the delete instance method over gRPC. @@ -431,7 +430,7 @@ def delete_instance( self._stubs["delete_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1.CloudMemcache/DeleteInstance", request_serializer=cloud_memcache.DeleteInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_instance"] @@ -439,7 +438,7 @@ def delete_instance( def apply_parameters( self, ) -> Callable[ - [cloud_memcache.ApplyParametersRequest], Awaitable[operations.Operation] + [cloud_memcache.ApplyParametersRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the apply parameters method over gRPC. @@ -461,7 +460,7 @@ def apply_parameters( self._stubs["apply_parameters"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1.CloudMemcache/ApplyParameters", request_serializer=cloud_memcache.ApplyParametersRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["apply_parameters"] diff --git a/google/cloud/memcache_v1/types/__init__.py b/google/cloud/memcache_v1/types/__init__.py index 29acce6..2430991 100644 --- a/google/cloud/memcache_v1/types/__init__.py +++ b/google/cloud/memcache_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_memcache import ( ApplyParametersRequest, CreateInstanceRequest, diff --git a/google/cloud/memcache_v1/types/cloud_memcache.py b/google/cloud/memcache_v1/types/cloud_memcache.py index a148657..2a6777e 100644 --- a/google/cloud/memcache_v1/types/cloud_memcache.py +++ b/google/cloud/memcache_v1/types/cloud_memcache.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 MemcacheVersion(proto.Enum): class Instance(proto.Message): r""" - Attributes: name (str): Required. Unique name of the resource in this scope @@ -133,7 +129,6 @@ class State(proto.Enum): class NodeConfig(proto.Message): r"""Configuration for a Memcached Node. - Attributes: cpu_count (int): Required. Number of cpus per Memcached node. @@ -142,13 +137,11 @@ class NodeConfig(proto.Message): Memcached node. """ - cpu_count = proto.Field(proto.INT32, number=1) - - memory_size_mb = proto.Field(proto.INT32, number=2) + cpu_count = proto.Field(proto.INT32, number=1,) + memory_size_mb = proto.Field(proto.INT32, number=2,) class Node(proto.Message): r""" - Attributes: node_id (str): Output only. Identifier of the Memcached @@ -180,21 +173,15 @@ class State(proto.Enum): DELETING = 3 UPDATING = 4 - node_id = proto.Field(proto.STRING, number=1) - - zone = proto.Field(proto.STRING, number=2) - + node_id = proto.Field(proto.STRING, number=1,) + zone = proto.Field(proto.STRING, number=2,) state = proto.Field(proto.ENUM, number=3, enum="Instance.Node.State",) - - host = proto.Field(proto.STRING, number=4) - - port = proto.Field(proto.INT32, number=5) - + host = proto.Field(proto.STRING, number=4,) + port = proto.Field(proto.INT32, number=5,) parameters = proto.Field(proto.MESSAGE, number=6, message="MemcacheParameters",) class InstanceMessage(proto.Message): r""" - Attributes: code (google.cloud.memcache_v1.types.Instance.InstanceMessage.Code): A code that correspond to one type of user- @@ -210,42 +197,30 @@ class Code(proto.Enum): ZONE_DISTRIBUTION_UNBALANCED = 1 code = proto.Field(proto.ENUM, number=1, enum="Instance.InstanceMessage.Code",) - - message = proto.Field(proto.STRING, number=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) - - authorized_network = proto.Field(proto.STRING, number=4) - - zones = proto.RepeatedField(proto.STRING, number=5) - - node_count = proto.Field(proto.INT32, number=6) - + message = proto.Field(proto.STRING, number=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,) + authorized_network = proto.Field(proto.STRING, number=4,) + zones = proto.RepeatedField(proto.STRING, number=5,) + node_count = proto.Field(proto.INT32, number=6,) node_config = proto.Field(proto.MESSAGE, number=7, message=NodeConfig,) - memcache_version = proto.Field(proto.ENUM, number=9, enum="MemcacheVersion",) - parameters = proto.Field(proto.MESSAGE, number=11, message="MemcacheParameters",) - memcache_nodes = proto.RepeatedField(proto.MESSAGE, number=12, message=Node,) - - create_time = proto.Field(proto.MESSAGE, number=13, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=14, message=timestamp.Timestamp,) - + create_time = proto.Field( + proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + ) state = proto.Field(proto.ENUM, number=15, enum=State,) - - memcache_full_version = proto.Field(proto.STRING, number=18) - + memcache_full_version = proto.Field(proto.STRING, number=18,) instance_messages = proto.RepeatedField( proto.MESSAGE, number=19, message=InstanceMessage, ) - - discovery_endpoint = proto.Field(proto.STRING, number=20) + discovery_endpoint = proto.Field(proto.STRING, number=20,) class ListInstancesRequest(proto.Message): @@ -278,15 +253,11 @@ class ListInstancesRequest(proto.Message): "name desc" or "" (unsorted). """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - filter = proto.Field(proto.STRING, number=4) - - order_by = proto.Field(proto.STRING, number=5) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) class ListInstancesResponse(proto.Message): @@ -314,10 +285,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): @@ -331,7 +300,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): @@ -360,10 +329,8 @@ class CreateInstanceRequest(proto.Message): Required. A Memcached Instance """ - 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",) @@ -381,8 +348,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",) @@ -397,7 +365,7 @@ 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 ApplyParametersRequest(proto.Message): @@ -420,11 +388,9 @@ class ApplyParametersRequest(proto.Message): nodes within the instance. """ - name = proto.Field(proto.STRING, number=1) - - node_ids = proto.RepeatedField(proto.STRING, number=2) - - apply_all = proto.Field(proto.BOOL, number=3) + name = proto.Field(proto.STRING, number=1,) + node_ids = proto.RepeatedField(proto.STRING, number=2,) + apply_all = proto.Field(proto.BOOL, number=3,) class UpdateParametersRequest(proto.Message): @@ -442,16 +408,15 @@ class UpdateParametersRequest(proto.Message): The parameters to apply to the instance. """ - name = proto.Field(proto.STRING, number=1) - - update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) - + name = proto.Field(proto.STRING, number=1,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) parameters = proto.Field(proto.MESSAGE, number=3, message="MemcacheParameters",) class MemcacheParameters(proto.Message): r""" - Attributes: id (str): Output only. The unique ID associated with @@ -465,14 +430,12 @@ class MemcacheParameters(proto.Message): memcached process. """ - id = proto.Field(proto.STRING, number=1) - - params = proto.MapField(proto.STRING, proto.STRING, number=3) + id = proto.Field(proto.STRING, number=1,) + params = proto.MapField(proto.STRING, proto.STRING, number=3,) class OperationMetadata(proto.Message): r"""Represents the metadata of a long-running operation. - Attributes: create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time when the operation was @@ -500,19 +463,13 @@ class OperationMetadata(proto.Message): operation. """ - 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,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/memcache_v1beta2/__init__.py b/google/cloud/memcache_v1beta2/__init__.py index bac2393..54fa8a3 100644 --- a/google/cloud/memcache_v1beta2/__init__.py +++ b/google/cloud/memcache_v1beta2/__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_memcache import CloudMemcacheClient +from .services.cloud_memcache import CloudMemcacheAsyncClient + from .types.cloud_memcache import ApplyParametersRequest from .types.cloud_memcache import ApplySoftwareUpdateRequest from .types.cloud_memcache import CreateInstanceRequest @@ -26,16 +27,17 @@ from .types.cloud_memcache import ListInstancesResponse from .types.cloud_memcache import LocationMetadata from .types.cloud_memcache import MemcacheParameters -from .types.cloud_memcache import MemcacheVersion from .types.cloud_memcache import OperationMetadata from .types.cloud_memcache import UpdateInstanceRequest from .types.cloud_memcache import UpdateParametersRequest from .types.cloud_memcache import ZoneMetadata - +from .types.cloud_memcache import MemcacheVersion __all__ = ( + "CloudMemcacheAsyncClient", "ApplyParametersRequest", "ApplySoftwareUpdateRequest", + "CloudMemcacheClient", "CreateInstanceRequest", "DeleteInstanceRequest", "GetInstanceRequest", @@ -49,5 +51,4 @@ "UpdateInstanceRequest", "UpdateParametersRequest", "ZoneMetadata", - "CloudMemcacheClient", ) diff --git a/google/cloud/memcache_v1beta2/gapic_metadata.json b/google/cloud/memcache_v1beta2/gapic_metadata.json new file mode 100644 index 0000000..288ef89 --- /dev/null +++ b/google/cloud/memcache_v1beta2/gapic_metadata.json @@ -0,0 +1,103 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.memcache_v1beta2", + "protoPackage": "google.cloud.memcache.v1beta2", + "schema": "1.0", + "services": { + "CloudMemcache": { + "clients": { + "grpc": { + "libraryClient": "CloudMemcacheClient", + "rpcs": { + "ApplyParameters": { + "methods": [ + "apply_parameters" + ] + }, + "ApplySoftwareUpdate": { + "methods": [ + "apply_software_update" + ] + }, + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpdateParameters": { + "methods": [ + "update_parameters" + ] + } + } + }, + "grpc-async": { + "libraryClient": "CloudMemcacheAsyncClient", + "rpcs": { + "ApplyParameters": { + "methods": [ + "apply_parameters" + ] + }, + "ApplySoftwareUpdate": { + "methods": [ + "apply_software_update" + ] + }, + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpdateParameters": { + "methods": [ + "update_parameters" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/memcache_v1beta2/services/__init__.py b/google/cloud/memcache_v1beta2/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/memcache_v1beta2/services/__init__.py +++ b/google/cloud/memcache_v1beta2/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/memcache_v1beta2/services/cloud_memcache/__init__.py b/google/cloud/memcache_v1beta2/services/cloud_memcache/__init__.py index 8524cb4..efb245e 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/__init__.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/__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 CloudMemcacheClient from .async_client import CloudMemcacheAsyncClient diff --git a/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py b/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py index b687488..4417473 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/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.memcache_v1beta2.services.cloud_memcache import pagers from google.cloud.memcache_v1beta2.types import cloud_memcache -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 CloudMemcacheTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import CloudMemcacheGrpcAsyncIOTransport from .client import CloudMemcacheClient @@ -70,31 +67,26 @@ class CloudMemcacheAsyncClient: instance_path = staticmethod(CloudMemcacheClient.instance_path) parse_instance_path = staticmethod(CloudMemcacheClient.parse_instance_path) - common_billing_account_path = staticmethod( CloudMemcacheClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( CloudMemcacheClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(CloudMemcacheClient.common_folder_path) parse_common_folder_path = staticmethod( CloudMemcacheClient.parse_common_folder_path ) - common_organization_path = staticmethod( CloudMemcacheClient.common_organization_path ) parse_common_organization_path = staticmethod( CloudMemcacheClient.parse_common_organization_path ) - common_project_path = staticmethod(CloudMemcacheClient.common_project_path) parse_common_project_path = staticmethod( CloudMemcacheClient.parse_common_project_path ) - common_location_path = staticmethod(CloudMemcacheClient.common_location_path) parse_common_location_path = staticmethod( CloudMemcacheClient.parse_common_location_path @@ -102,7 +94,8 @@ class CloudMemcacheAsyncClient: @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. @@ -117,7 +110,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 @@ -134,7 +127,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> CloudMemcacheTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: CloudMemcacheTransport: The transport used by the client instance. @@ -148,12 +141,12 @@ def transport(self) -> CloudMemcacheTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, CloudMemcacheTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the cloud memcache client. + """Instantiates the cloud memcache client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -185,7 +178,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = CloudMemcacheClient( credentials=credentials, transport=transport, @@ -217,7 +209,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. @@ -247,7 +238,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 @@ -301,7 +291,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. @@ -326,7 +315,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 @@ -398,7 +386,6 @@ async def create_instance( This corresponds to the ``resource`` 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. @@ -428,7 +415,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: @@ -468,7 +454,7 @@ async def update_instance( self, request: cloud_memcache.UpdateInstanceRequest = None, *, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, resource: cloud_memcache.Instance = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -496,7 +482,6 @@ async def update_instance( This corresponds to the ``resource`` 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. @@ -526,7 +511,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 resource is not None: @@ -567,7 +551,7 @@ async def update_parameters( request: cloud_memcache.UpdateParametersRequest = None, *, name: str = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, parameters: cloud_memcache.MemcacheParameters = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -602,7 +586,6 @@ async def update_parameters( This corresponds to the ``parameters`` 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. @@ -632,7 +615,6 @@ async def update_parameters( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if update_mask is not None: @@ -692,7 +674,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. @@ -732,7 +713,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 @@ -757,7 +737,7 @@ async def delete_instance( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=cloud_memcache.OperationMetadata, ) @@ -807,7 +787,6 @@ async def apply_parameters( This corresponds to the ``apply_all`` 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. @@ -837,12 +816,10 @@ async def apply_parameters( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if apply_all is not None: request.apply_all = apply_all - if node_ids: request.node_ids.extend(node_ids) @@ -919,7 +896,6 @@ async def apply_software_update( This corresponds to the ``apply_all`` 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,12 +925,10 @@ async def apply_software_update( # If we have keyword arguments corresponding to fields on the # request, apply these. - if instance is not None: request.instance = instance if apply_all is not None: request.apply_all = apply_all - if node_ids: request.node_ids.extend(node_ids) diff --git a/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py b/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py index 8d43719..65a2bc3 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/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.memcache_v1beta2.services.cloud_memcache import pagers from google.cloud.memcache_v1beta2.types import cloud_memcache -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 CloudMemcacheTransport, DEFAULT_CLIENT_INFO from .transports.grpc import CloudMemcacheGrpcTransport from .transports.grpc_asyncio import CloudMemcacheGrpcAsyncIOTransport @@ -58,7 +55,7 @@ class CloudMemcacheClientMeta(type): _transport_registry["grpc_asyncio"] = CloudMemcacheGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[CloudMemcacheTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -100,7 +97,8 @@ class CloudMemcacheClient(metaclass=CloudMemcacheClientMeta): @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: @@ -134,7 +132,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. @@ -151,7 +150,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 @@ -170,23 +169,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> CloudMemcacheTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - CloudMemcacheTransport: The transport used by the client instance. + CloudMemcacheTransport: 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, @@ -195,7 +195,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, ) @@ -208,7 +208,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 @@ -219,7 +219,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 @@ -230,7 +230,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 @@ -241,7 +241,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, ) @@ -255,12 +255,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, CloudMemcacheTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the cloud memcache client. + """Instantiates the cloud memcache client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -315,9 +315,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: @@ -329,12 +330,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. @@ -349,8 +352,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: @@ -389,7 +392,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. @@ -421,10 +423,8 @@ def list_instances( # there are no flattened fields. if not isinstance(request, cloud_memcache.ListInstancesRequest): request = cloud_memcache.ListInstancesRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -474,7 +474,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. @@ -501,10 +500,8 @@ def get_instance( # there are no flattened fields. if not isinstance(request, cloud_memcache.GetInstanceRequest): request = cloud_memcache.GetInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -572,7 +569,6 @@ def create_instance( This corresponds to the ``resource`` 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. @@ -604,10 +600,8 @@ def create_instance( # there are no flattened fields. if not isinstance(request, cloud_memcache.CreateInstanceRequest): request = cloud_memcache.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: @@ -643,7 +637,7 @@ def update_instance( self, request: cloud_memcache.UpdateInstanceRequest = None, *, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, resource: cloud_memcache.Instance = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -671,7 +665,6 @@ def update_instance( This corresponds to the ``resource`` 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. @@ -703,10 +696,8 @@ def update_instance( # there are no flattened fields. if not isinstance(request, cloud_memcache.UpdateInstanceRequest): request = cloud_memcache.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 resource is not None: @@ -743,7 +734,7 @@ def update_parameters( request: cloud_memcache.UpdateParametersRequest = None, *, name: str = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, parameters: cloud_memcache.MemcacheParameters = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -778,7 +769,6 @@ def update_parameters( This corresponds to the ``parameters`` 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. @@ -810,10 +800,8 @@ def update_parameters( # there are no flattened fields. if not isinstance(request, cloud_memcache.UpdateParametersRequest): request = cloud_memcache.UpdateParametersRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if update_mask is not None: @@ -869,7 +857,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. @@ -911,10 +898,8 @@ def delete_instance( # there are no flattened fields. if not isinstance(request, cloud_memcache.DeleteInstanceRequest): request = cloud_memcache.DeleteInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -935,7 +920,7 @@ def delete_instance( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=cloud_memcache.OperationMetadata, ) @@ -985,7 +970,6 @@ def apply_parameters( This corresponds to the ``apply_all`` 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. @@ -1017,10 +1001,8 @@ def apply_parameters( # there are no flattened fields. if not isinstance(request, cloud_memcache.ApplyParametersRequest): request = cloud_memcache.ApplyParametersRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if node_ids is not None: @@ -1097,7 +1079,6 @@ def apply_software_update( This corresponds to the ``apply_all`` 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. @@ -1129,10 +1110,8 @@ def apply_software_update( # there are no flattened fields. if not isinstance(request, cloud_memcache.ApplySoftwareUpdateRequest): request = cloud_memcache.ApplySoftwareUpdateRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if instance is not None: request.instance = instance if node_ids is not None: diff --git a/google/cloud/memcache_v1beta2/services/cloud_memcache/pagers.py b/google/cloud/memcache_v1beta2/services/cloud_memcache/pagers.py index 5b69afd..381459d 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/pagers.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/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/memcache_v1beta2/services/cloud_memcache/transports/__init__.py b/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/__init__.py index 38122c6..32ad848 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/__init__.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/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/memcache_v1beta2/services/cloud_memcache/transports/base.py b/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/base.py index a1b9e2c..1fb1292 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/base.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/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.memcache_v1beta2.types import cloud_memcache -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 CloudMemcacheTransport(abc.ABC): """Abstract transport class for CloudMemcache.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "memcache.googleapis.com" + def __init__( self, *, - host: str = "memcache.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 = { @@ -142,11 +202,11 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_instances( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.ListInstancesRequest], - typing.Union[ + Union[ cloud_memcache.ListInstancesResponse, - typing.Awaitable[cloud_memcache.ListInstancesResponse], + Awaitable[cloud_memcache.ListInstancesResponse], ], ]: raise NotImplementedError() @@ -154,65 +214,63 @@ def list_instances( @property def get_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.GetInstanceRequest], - typing.Union[ - cloud_memcache.Instance, typing.Awaitable[cloud_memcache.Instance] - ], + Union[cloud_memcache.Instance, Awaitable[cloud_memcache.Instance]], ]: raise NotImplementedError() @property def create_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.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_memcache.UpdateInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_parameters( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.UpdateParametersRequest], - 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_memcache.DeleteInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def apply_parameters( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.ApplyParametersRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def apply_software_update( self, - ) -> typing.Callable[ + ) -> Callable[ [cloud_memcache.ApplySoftwareUpdateRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc.py b/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc.py index f5f202f..cf61dee 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/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.memcache_v1beta2.types import cloud_memcache -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import CloudMemcacheTransport, DEFAULT_CLIENT_INFO @@ -70,7 +67,7 @@ def __init__( self, *, host: str = "memcache.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -84,7 +81,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 @@ -195,7 +193,7 @@ def __init__( def create_channel( cls, host: str = "memcache.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, @@ -226,13 +224,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, ) @@ -313,7 +313,7 @@ def get_instance( @property def create_instance( self, - ) -> Callable[[cloud_memcache.CreateInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_memcache.CreateInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the create instance method over gRPC. Creates a new Instance in a given location. @@ -332,14 +332,14 @@ def create_instance( self._stubs["create_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/CreateInstance", request_serializer=cloud_memcache.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_memcache.UpdateInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_memcache.UpdateInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the update instance method over gRPC. Updates an existing Instance in a given project and @@ -359,14 +359,14 @@ def update_instance( self._stubs["update_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/UpdateInstance", request_serializer=cloud_memcache.UpdateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_instance"] @property def update_parameters( self, - ) -> Callable[[cloud_memcache.UpdateParametersRequest], operations.Operation]: + ) -> Callable[[cloud_memcache.UpdateParametersRequest], operations_pb2.Operation]: r"""Return a callable for the update parameters method over gRPC. Updates the defined Memcached parameters for an existing @@ -388,14 +388,14 @@ def update_parameters( self._stubs["update_parameters"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/UpdateParameters", request_serializer=cloud_memcache.UpdateParametersRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_parameters"] @property def delete_instance( self, - ) -> Callable[[cloud_memcache.DeleteInstanceRequest], operations.Operation]: + ) -> Callable[[cloud_memcache.DeleteInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the delete instance method over gRPC. Deletes a single Instance. @@ -414,14 +414,14 @@ def delete_instance( self._stubs["delete_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/DeleteInstance", request_serializer=cloud_memcache.DeleteInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_instance"] @property def apply_parameters( self, - ) -> Callable[[cloud_memcache.ApplyParametersRequest], operations.Operation]: + ) -> Callable[[cloud_memcache.ApplyParametersRequest], operations_pb2.Operation]: r"""Return a callable for the apply parameters method over gRPC. ``ApplyParameters`` restarts the set of specified nodes in order @@ -442,14 +442,16 @@ def apply_parameters( self._stubs["apply_parameters"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/ApplyParameters", request_serializer=cloud_memcache.ApplyParametersRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["apply_parameters"] @property def apply_software_update( self, - ) -> Callable[[cloud_memcache.ApplySoftwareUpdateRequest], operations.Operation]: + ) -> Callable[ + [cloud_memcache.ApplySoftwareUpdateRequest], operations_pb2.Operation + ]: r"""Return a callable for the apply software update method over gRPC. Updates software on the selected nodes of the @@ -469,7 +471,7 @@ def apply_software_update( self._stubs["apply_software_update"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/ApplySoftwareUpdate", request_serializer=cloud_memcache.ApplySoftwareUpdateRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["apply_software_update"] diff --git a/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc_asyncio.py b/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc_asyncio.py index f2452b4..e5a9f15 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc_asyncio.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/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.memcache_v1beta2.types import cloud_memcache -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import CloudMemcacheTransport, DEFAULT_CLIENT_INFO from .grpc import CloudMemcacheGrpcTransport @@ -73,7 +70,7 @@ class CloudMemcacheGrpcAsyncIOTransport(CloudMemcacheTransport): def create_channel( cls, host: str = "memcache.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, @@ -100,13 +97,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, ) @@ -114,7 +113,7 @@ def __init__( self, *, host: str = "memcache.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, @@ -128,7 +127,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 @@ -187,7 +187,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 @@ -323,7 +322,7 @@ def get_instance( def create_instance( self, ) -> Callable[ - [cloud_memcache.CreateInstanceRequest], Awaitable[operations.Operation] + [cloud_memcache.CreateInstanceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the create instance method over gRPC. @@ -343,7 +342,7 @@ def create_instance( self._stubs["create_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/CreateInstance", request_serializer=cloud_memcache.CreateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_instance"] @@ -351,7 +350,7 @@ def create_instance( def update_instance( self, ) -> Callable[ - [cloud_memcache.UpdateInstanceRequest], Awaitable[operations.Operation] + [cloud_memcache.UpdateInstanceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the update instance method over gRPC. @@ -372,7 +371,7 @@ def update_instance( self._stubs["update_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/UpdateInstance", request_serializer=cloud_memcache.UpdateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_instance"] @@ -380,7 +379,7 @@ def update_instance( def update_parameters( self, ) -> Callable[ - [cloud_memcache.UpdateParametersRequest], Awaitable[operations.Operation] + [cloud_memcache.UpdateParametersRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the update parameters method over gRPC. @@ -403,7 +402,7 @@ def update_parameters( self._stubs["update_parameters"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/UpdateParameters", request_serializer=cloud_memcache.UpdateParametersRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_parameters"] @@ -411,7 +410,7 @@ def update_parameters( def delete_instance( self, ) -> Callable[ - [cloud_memcache.DeleteInstanceRequest], Awaitable[operations.Operation] + [cloud_memcache.DeleteInstanceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the delete instance method over gRPC. @@ -431,7 +430,7 @@ def delete_instance( self._stubs["delete_instance"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/DeleteInstance", request_serializer=cloud_memcache.DeleteInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_instance"] @@ -439,7 +438,7 @@ def delete_instance( def apply_parameters( self, ) -> Callable[ - [cloud_memcache.ApplyParametersRequest], Awaitable[operations.Operation] + [cloud_memcache.ApplyParametersRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the apply parameters method over gRPC. @@ -461,7 +460,7 @@ def apply_parameters( self._stubs["apply_parameters"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/ApplyParameters", request_serializer=cloud_memcache.ApplyParametersRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["apply_parameters"] @@ -469,7 +468,7 @@ def apply_parameters( def apply_software_update( self, ) -> Callable[ - [cloud_memcache.ApplySoftwareUpdateRequest], Awaitable[operations.Operation] + [cloud_memcache.ApplySoftwareUpdateRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the apply software update method over gRPC. @@ -490,7 +489,7 @@ def apply_software_update( self._stubs["apply_software_update"] = self.grpc_channel.unary_unary( "/google.cloud.memcache.v1beta2.CloudMemcache/ApplySoftwareUpdate", request_serializer=cloud_memcache.ApplySoftwareUpdateRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["apply_software_update"] diff --git a/google/cloud/memcache_v1beta2/types/__init__.py b/google/cloud/memcache_v1beta2/types/__init__.py index 90cf3eb..a4e788a 100644 --- a/google/cloud/memcache_v1beta2/types/__init__.py +++ b/google/cloud/memcache_v1beta2/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_memcache import ( ApplyParametersRequest, ApplySoftwareUpdateRequest, diff --git a/google/cloud/memcache_v1beta2/types/cloud_memcache.py b/google/cloud/memcache_v1beta2/types/cloud_memcache.py index b7e9a43..6fdd3b8 100644 --- a/google/cloud/memcache_v1beta2/types/cloud_memcache.py +++ b/google/cloud/memcache_v1beta2/types/cloud_memcache.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( @@ -52,7 +49,6 @@ class MemcacheVersion(proto.Enum): class Instance(proto.Message): r"""A Memorystore for Memcached instance - Attributes: name (str): Required. Unique name of the resource in this scope @@ -142,7 +138,6 @@ class State(proto.Enum): class NodeConfig(proto.Message): r"""Configuration for a Memcached Node. - Attributes: cpu_count (int): Required. Number of cpus per Memcached node. @@ -151,13 +146,11 @@ class NodeConfig(proto.Message): Memcached node. """ - cpu_count = proto.Field(proto.INT32, number=1) - - memory_size_mb = proto.Field(proto.INT32, number=2) + cpu_count = proto.Field(proto.INT32, number=1,) + memory_size_mb = proto.Field(proto.INT32, number=2,) class Node(proto.Message): r""" - Attributes: node_id (str): Output only. Identifier of the Memcached @@ -192,23 +185,16 @@ class State(proto.Enum): DELETING = 3 UPDATING = 4 - node_id = proto.Field(proto.STRING, number=1) - - zone = proto.Field(proto.STRING, number=2) - + node_id = proto.Field(proto.STRING, number=1,) + zone = proto.Field(proto.STRING, number=2,) state = proto.Field(proto.ENUM, number=3, enum="Instance.Node.State",) - - host = proto.Field(proto.STRING, number=4) - - port = proto.Field(proto.INT32, number=5) - + host = proto.Field(proto.STRING, number=4,) + port = proto.Field(proto.INT32, number=5,) parameters = proto.Field(proto.MESSAGE, number=6, message="MemcacheParameters",) - - update_available = proto.Field(proto.BOOL, number=7) + update_available = proto.Field(proto.BOOL, number=7,) class InstanceMessage(proto.Message): r""" - Attributes: code (google.cloud.memcache_v1beta2.types.Instance.InstanceMessage.Code): A code that correspond to one type of user- @@ -224,44 +210,31 @@ class Code(proto.Enum): ZONE_DISTRIBUTION_UNBALANCED = 1 code = proto.Field(proto.ENUM, number=1, enum="Instance.InstanceMessage.Code",) - - message = proto.Field(proto.STRING, number=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) - - authorized_network = proto.Field(proto.STRING, number=4) - - zones = proto.RepeatedField(proto.STRING, number=5) - - node_count = proto.Field(proto.INT32, number=6) - + message = proto.Field(proto.STRING, number=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,) + authorized_network = proto.Field(proto.STRING, number=4,) + zones = proto.RepeatedField(proto.STRING, number=5,) + node_count = proto.Field(proto.INT32, number=6,) node_config = proto.Field(proto.MESSAGE, number=7, message=NodeConfig,) - memcache_version = proto.Field(proto.ENUM, number=9, enum="MemcacheVersion",) - parameters = proto.Field(proto.MESSAGE, number=11, message="MemcacheParameters",) - memcache_nodes = proto.RepeatedField(proto.MESSAGE, number=12, message=Node,) - - create_time = proto.Field(proto.MESSAGE, number=13, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=14, message=timestamp.Timestamp,) - + create_time = proto.Field( + proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + ) state = proto.Field(proto.ENUM, number=15, enum=State,) - - memcache_full_version = proto.Field(proto.STRING, number=18) - + memcache_full_version = proto.Field(proto.STRING, number=18,) instance_messages = proto.RepeatedField( proto.MESSAGE, number=19, message=InstanceMessage, ) - - discovery_endpoint = proto.Field(proto.STRING, number=20) - - update_available = proto.Field(proto.BOOL, number=21) + discovery_endpoint = proto.Field(proto.STRING, number=20,) + update_available = proto.Field(proto.BOOL, number=21,) class ListInstancesRequest(proto.Message): @@ -294,15 +267,11 @@ class ListInstancesRequest(proto.Message): "name desc" or "" (unsorted). """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - filter = proto.Field(proto.STRING, number=4) - - order_by = proto.Field(proto.STRING, number=5) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) class ListInstancesResponse(proto.Message): @@ -330,10 +299,8 @@ def raw_page(self): return self resources = 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): @@ -347,7 +314,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): @@ -376,10 +343,8 @@ class CreateInstanceRequest(proto.Message): Required. A Memcached [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,) resource = proto.Field(proto.MESSAGE, number=3, message="Instance",) @@ -397,8 +362,9 @@ class UpdateInstanceRequest(proto.Message): specified in 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, + ) resource = proto.Field(proto.MESSAGE, number=2, message="Instance",) @@ -413,7 +379,7 @@ 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 ApplyParametersRequest(proto.Message): @@ -435,11 +401,9 @@ class ApplyParametersRequest(proto.Message): within the instance. """ - name = proto.Field(proto.STRING, number=1) - - node_ids = proto.RepeatedField(proto.STRING, number=2) - - apply_all = proto.Field(proto.BOOL, number=3) + name = proto.Field(proto.STRING, number=1,) + node_ids = proto.RepeatedField(proto.STRING, number=2,) + apply_all = proto.Field(proto.BOOL, number=3,) class UpdateParametersRequest(proto.Message): @@ -457,10 +421,10 @@ class UpdateParametersRequest(proto.Message): The parameters to apply to the instance. """ - name = proto.Field(proto.STRING, number=1) - - update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) - + name = proto.Field(proto.STRING, number=1,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) parameters = proto.Field(proto.MESSAGE, number=3, message="MemcacheParameters",) @@ -485,11 +449,9 @@ class ApplySoftwareUpdateRequest(proto.Message): instance. """ - instance = proto.Field(proto.STRING, number=1) - - node_ids = proto.RepeatedField(proto.STRING, number=2) - - apply_all = proto.Field(proto.BOOL, number=3) + instance = proto.Field(proto.STRING, number=1,) + node_ids = proto.RepeatedField(proto.STRING, number=2,) + apply_all = proto.Field(proto.BOOL, number=3,) class MemcacheParameters(proto.Message): @@ -507,14 +469,12 @@ class MemcacheParameters(proto.Message): memcached process. """ - id = proto.Field(proto.STRING, number=1) - - params = proto.MapField(proto.STRING, proto.STRING, number=3) + id = proto.Field(proto.STRING, number=1,) + params = proto.MapField(proto.STRING, proto.STRING, number=3,) class OperationMetadata(proto.Message): r"""Represents the metadata of a long-running operation. - Attributes: create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time when the operation was @@ -542,19 +502,13 @@ class OperationMetadata(proto.Message): operation. """ - 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): @@ -575,7 +529,7 @@ class LocationMetadata(proto.Message): class ZoneMetadata(proto.Message): - r"""""" + r""" """ __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/scripts/fixup_memcache_v1_keywords.py b/scripts/fixup_memcache_v1_keywords.py index eac442a..774b03f 100644 --- a/scripts/fixup_memcache_v1_keywords.py +++ b/scripts/fixup_memcache_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,14 +39,13 @@ def partition( class memcacheCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'apply_parameters': ('name', 'node_ids', 'apply_all', ), - 'create_instance': ('parent', 'instance_id', 'instance', ), - 'delete_instance': ('name', ), - 'get_instance': ('name', ), - 'list_instances': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), - 'update_instance': ('update_mask', 'instance', ), - 'update_parameters': ('name', 'update_mask', 'parameters', ), - + 'apply_parameters': ('name', 'node_ids', 'apply_all', ), + 'create_instance': ('parent', 'instance_id', 'instance', ), + 'delete_instance': ('name', ), + 'get_instance': ('name', ), + 'list_instances': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'update_instance': ('update_mask', 'instance', ), + 'update_parameters': ('name', 'update_mask', 'parameters', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -79,7 +76,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_memcache_v1beta2_keywords.py b/scripts/fixup_memcache_v1beta2_keywords.py index 4267b6f..afe0f42 100644 --- a/scripts/fixup_memcache_v1beta2_keywords.py +++ b/scripts/fixup_memcache_v1beta2_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,15 +39,14 @@ def partition( class memcacheCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'apply_parameters': ('name', 'node_ids', 'apply_all', ), - 'apply_software_update': ('instance', 'node_ids', 'apply_all', ), - 'create_instance': ('parent', 'instance_id', 'resource', ), - 'delete_instance': ('name', ), - 'get_instance': ('name', ), - 'list_instances': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), - 'update_instance': ('update_mask', 'resource', ), - 'update_parameters': ('name', 'update_mask', 'parameters', ), - + 'apply_parameters': ('name', 'node_ids', 'apply_all', ), + 'apply_software_update': ('instance', 'node_ids', 'apply_all', ), + 'create_instance': ('parent', 'instance_id', 'resource', ), + 'delete_instance': ('name', ), + 'get_instance': ('name', ), + 'list_instances': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'update_instance': ('update_mask', 'resource', ), + 'update_parameters': ('name', 'update_mask', 'parameters', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -80,7 +77,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/setup.py b/setup.py index f8353b2..0490fba 100644 --- a/setup.py +++ b/setup.py @@ -42,6 +42,7 @@ install_requires=( "google-api-core[grpc] >= 1.22.2, < 2.0.0dev", "proto-plus >= 1.4.0", + "packaging >= 14.3", ), python_requires=">=3.6", classifiers=[ diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index a929701..3d61f06 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -7,3 +7,5 @@ # Then this file should have google-cloud-foo==1.14.0 google-api-core==1.22.2 proto-plus==1.15.0 +packaging==14.3 +google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is required through google-api-core 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/memcache_v1/__init__.py b/tests/unit/gapic/memcache_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/memcache_v1/__init__.py +++ b/tests/unit/gapic/memcache_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/memcache_v1/test_cloud_memcache.py b/tests/unit/gapic/memcache_v1/test_cloud_memcache.py index b4793ec..4970a18 100644 --- a/tests/unit/gapic/memcache_v1/test_cloud_memcache.py +++ b/tests/unit/gapic/memcache_v1/test_cloud_memcache.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,56 @@ 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.memcache_v1.services.cloud_memcache import CloudMemcacheAsyncClient from google.cloud.memcache_v1.services.cloud_memcache import CloudMemcacheClient from google.cloud.memcache_v1.services.cloud_memcache import pagers from google.cloud.memcache_v1.services.cloud_memcache import transports +from google.cloud.memcache_v1.services.cloud_memcache.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.memcache_v1.services.cloud_memcache.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.memcache_v1.types import cloud_memcache 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(): @@ -94,7 +123,7 @@ def test__get_default_mtls_endpoint(): "client_class", [CloudMemcacheClient, CloudMemcacheAsyncClient,] ) def test_cloud_memcache_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: @@ -111,7 +140,7 @@ def test_cloud_memcache_client_from_service_account_info(client_class): "client_class", [CloudMemcacheClient, CloudMemcacheAsyncClient,] ) def test_cloud_memcache_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: @@ -164,7 +193,7 @@ def test_cloud_memcache_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(CloudMemcacheClient, "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() @@ -452,7 +481,7 @@ def test_list_instances( transport: str = "grpc", request_type=cloud_memcache.ListInstancesRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -465,21 +494,16 @@ def test_list_instances( call.return_value = cloud_memcache.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_memcache.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"] @@ -491,7 +515,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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -499,7 +523,6 @@ def test_list_instances_empty_call(): client.list_instances() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.ListInstancesRequest() @@ -508,7 +531,7 @@ async def test_list_instances_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.ListInstancesRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -524,20 +547,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_memcache.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"] @@ -547,17 +566,17 @@ async def test_list_instances_async_from_dict(): def test_list_instances_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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_memcache.ListInstancesResponse() - client.list_instances(request) # Establish that the underlying gRPC stub method was called. @@ -572,11 +591,14 @@ def test_list_instances_field_headers(): @pytest.mark.asyncio async def test_list_instances_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.ListInstancesRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -584,7 +606,6 @@ async def test_list_instances_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_memcache.ListInstancesResponse() ) - await client.list_instances(request) # Establish that the underlying gRPC stub method was called. @@ -598,13 +619,12 @@ async def test_list_instances_field_headers_async(): def test_list_instances_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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",) @@ -613,12 +633,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 = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -630,7 +649,9 @@ def test_list_instances_flattened_error(): @pytest.mark.asyncio async def test_list_instances_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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: @@ -648,13 +669,14 @@ 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 = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -665,7 +687,7 @@ async def test_list_instances_flattened_error_async(): def test_list_instances_pager(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials,) + client = CloudMemcacheClient(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: @@ -703,7 +725,7 @@ def test_list_instances_pager(): def test_list_instances_pages(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials,) + client = CloudMemcacheClient(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: @@ -733,7 +755,7 @@ def test_list_instances_pages(): @pytest.mark.asyncio async def test_list_instances_async_pager(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials,) + client = CloudMemcacheAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -770,7 +792,7 @@ async def test_list_instances_async_pager(): @pytest.mark.asyncio async def test_list_instances_async_pages(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials,) + client = CloudMemcacheAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -806,7 +828,7 @@ def test_get_instance( transport: str = "grpc", request_type=cloud_memcache.GetInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -827,35 +849,23 @@ def test_get_instance( memcache_full_version="memcache_full_version_value", discovery_endpoint="discovery_endpoint_value", ) - 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_memcache.GetInstanceRequest() # Establish that the response is the type that we expect. - assert isinstance(response, cloud_memcache.Instance) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.authorized_network == "authorized_network_value" - assert response.zones == ["zones_value"] - assert response.node_count == 1070 - assert response.memcache_version == cloud_memcache.MemcacheVersion.MEMCACHE_1_5 - assert response.state == cloud_memcache.Instance.State.CREATING - assert response.memcache_full_version == "memcache_full_version_value" - assert response.discovery_endpoint == "discovery_endpoint_value" @@ -867,7 +877,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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -875,7 +885,6 @@ def test_get_instance_empty_call(): client.get_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.GetInstanceRequest() @@ -884,7 +893,7 @@ async def test_get_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.GetInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -907,34 +916,23 @@ async def test_get_instance_async( discovery_endpoint="discovery_endpoint_value", ) ) - 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_memcache.GetInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, cloud_memcache.Instance) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.authorized_network == "authorized_network_value" - assert response.zones == ["zones_value"] - assert response.node_count == 1070 - assert response.memcache_version == cloud_memcache.MemcacheVersion.MEMCACHE_1_5 - assert response.state == cloud_memcache.Instance.State.CREATING - assert response.memcache_full_version == "memcache_full_version_value" - assert response.discovery_endpoint == "discovery_endpoint_value" @@ -944,17 +942,17 @@ async def test_get_instance_async_from_dict(): def test_get_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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_memcache.Instance() - client.get_instance(request) # Establish that the underlying gRPC stub method was called. @@ -969,11 +967,14 @@ def test_get_instance_field_headers(): @pytest.mark.asyncio async def test_get_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.GetInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -981,7 +982,6 @@ async def test_get_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_memcache.Instance() ) - await client.get_instance(request) # Establish that the underlying gRPC stub method was called. @@ -995,13 +995,12 @@ async def test_get_instance_field_headers_async(): def test_get_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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",) @@ -1010,12 +1009,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 = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1027,7 +1025,9 @@ def test_get_instance_flattened_error(): @pytest.mark.asyncio async def test_get_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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: @@ -1045,13 +1045,14 @@ 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 = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1065,7 +1066,7 @@ def test_create_instance( transport: str = "grpc", request_type=cloud_memcache.CreateInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1076,13 +1077,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_memcache.CreateInstanceRequest() # Establish that the response is the type that we expect. @@ -1097,7 +1096,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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1105,7 +1104,6 @@ def test_create_instance_empty_call(): client.create_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.CreateInstanceRequest() @@ -1114,7 +1112,7 @@ async def test_create_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.CreateInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1127,13 +1125,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_memcache.CreateInstanceRequest() # Establish that the response is the type that we expect. @@ -1146,17 +1142,17 @@ async def test_create_instance_async_from_dict(): def test_create_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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. @@ -1171,11 +1167,14 @@ def test_create_instance_field_headers(): @pytest.mark.asyncio async def test_create_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.CreateInstanceRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1183,7 +1182,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. @@ -1197,13 +1195,12 @@ async def test_create_instance_field_headers_async(): def test_create_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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( @@ -1216,16 +1213,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 == cloud_memcache.Instance(name="name_value") - assert args[0].instance_id == "instance_id_value" def test_create_instance_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1240,7 +1234,9 @@ def test_create_instance_flattened_error(): @pytest.mark.asyncio async def test_create_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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: @@ -1262,17 +1258,16 @@ 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 == cloud_memcache.Instance(name="name_value") - assert args[0].instance_id == "instance_id_value" @pytest.mark.asyncio async def test_create_instance_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1289,7 +1284,7 @@ def test_update_instance( transport: str = "grpc", request_type=cloud_memcache.UpdateInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1300,13 +1295,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_memcache.UpdateInstanceRequest() # Establish that the response is the type that we expect. @@ -1321,7 +1314,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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1329,7 +1322,6 @@ def test_update_instance_empty_call(): client.update_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.UpdateInstanceRequest() @@ -1338,7 +1330,7 @@ async def test_update_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.UpdateInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1351,13 +1343,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_memcache.UpdateInstanceRequest() # Establish that the response is the type that we expect. @@ -1370,17 +1360,17 @@ async def test_update_instance_async_from_dict(): def test_update_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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. @@ -1397,11 +1387,14 @@ def test_update_instance_field_headers(): @pytest.mark.asyncio async def test_update_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.UpdateInstanceRequest() + request.instance.name = "instance.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1409,7 +1402,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. @@ -1425,32 +1417,29 @@ async def test_update_instance_field_headers_async(): def test_update_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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( instance=cloud_memcache.Instance(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].instance == cloud_memcache.Instance(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_instance_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1458,13 +1447,15 @@ def test_update_instance_flattened_error(): client.update_instance( cloud_memcache.UpdateInstanceRequest(), instance=cloud_memcache.Instance(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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: @@ -1478,22 +1469,22 @@ async def test_update_instance_flattened_async(): # using the keyword arguments to the method. response = await client.update_instance( instance=cloud_memcache.Instance(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].instance == cloud_memcache.Instance(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_instance_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1501,7 +1492,7 @@ async def test_update_instance_flattened_error_async(): await client.update_instance( cloud_memcache.UpdateInstanceRequest(), instance=cloud_memcache.Instance(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1509,7 +1500,7 @@ def test_update_parameters( transport: str = "grpc", request_type=cloud_memcache.UpdateParametersRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1522,13 +1513,11 @@ def test_update_parameters( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_parameters(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_memcache.UpdateParametersRequest() # Establish that the response is the type that we expect. @@ -1543,7 +1532,7 @@ def test_update_parameters_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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1553,7 +1542,6 @@ def test_update_parameters_empty_call(): client.update_parameters() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.UpdateParametersRequest() @@ -1562,7 +1550,7 @@ async def test_update_parameters_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.UpdateParametersRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1577,13 +1565,11 @@ async def test_update_parameters_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_parameters(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.UpdateParametersRequest() # Establish that the response is the type that we expect. @@ -1596,11 +1582,12 @@ async def test_update_parameters_async_from_dict(): def test_update_parameters_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.UpdateParametersRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1608,7 +1595,6 @@ def test_update_parameters_field_headers(): type(client.transport.update_parameters), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_parameters(request) # Establish that the underlying gRPC stub method was called. @@ -1623,11 +1609,14 @@ def test_update_parameters_field_headers(): @pytest.mark.asyncio async def test_update_parameters_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.UpdateParametersRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1637,7 +1626,6 @@ async def test_update_parameters_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_parameters(request) # Establish that the underlying gRPC stub method was called. @@ -1651,7 +1639,7 @@ async def test_update_parameters_field_headers_async(): def test_update_parameters_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1659,12 +1647,11 @@ def test_update_parameters_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.update_parameters( name="name_value", - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), parameters=cloud_memcache.MemcacheParameters(id="id_value"), ) @@ -1672,16 +1659,13 @@ def test_update_parameters_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - - 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].parameters == cloud_memcache.MemcacheParameters(id="id_value") def test_update_parameters_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1689,14 +1673,16 @@ def test_update_parameters_flattened_error(): client.update_parameters( cloud_memcache.UpdateParametersRequest(), name="name_value", - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), parameters=cloud_memcache.MemcacheParameters(id="id_value"), ) @pytest.mark.asyncio async def test_update_parameters_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1712,7 +1698,7 @@ async def test_update_parameters_flattened_async(): # using the keyword arguments to the method. response = await client.update_parameters( name="name_value", - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), parameters=cloud_memcache.MemcacheParameters(id="id_value"), ) @@ -1720,17 +1706,16 @@ async def test_update_parameters_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - - 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].parameters == cloud_memcache.MemcacheParameters(id="id_value") @pytest.mark.asyncio async def test_update_parameters_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1738,7 +1723,7 @@ async def test_update_parameters_flattened_error_async(): await client.update_parameters( cloud_memcache.UpdateParametersRequest(), name="name_value", - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), parameters=cloud_memcache.MemcacheParameters(id="id_value"), ) @@ -1747,7 +1732,7 @@ def test_delete_instance( transport: str = "grpc", request_type=cloud_memcache.DeleteInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1758,13 +1743,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_memcache.DeleteInstanceRequest() # Establish that the response is the type that we expect. @@ -1779,7 +1762,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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1787,7 +1770,6 @@ def test_delete_instance_empty_call(): client.delete_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.DeleteInstanceRequest() @@ -1796,7 +1778,7 @@ async def test_delete_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.DeleteInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1809,13 +1791,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_memcache.DeleteInstanceRequest() # Establish that the response is the type that we expect. @@ -1828,17 +1808,17 @@ async def test_delete_instance_async_from_dict(): def test_delete_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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. @@ -1853,11 +1833,14 @@ def test_delete_instance_field_headers(): @pytest.mark.asyncio async def test_delete_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.DeleteInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1865,7 +1848,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. @@ -1879,13 +1861,12 @@ async def test_delete_instance_field_headers_async(): def test_delete_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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",) @@ -1894,12 +1875,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 = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1911,7 +1891,9 @@ def test_delete_instance_flattened_error(): @pytest.mark.asyncio async def test_delete_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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: @@ -1929,13 +1911,14 @@ 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 = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1949,7 +1932,7 @@ def test_apply_parameters( transport: str = "grpc", request_type=cloud_memcache.ApplyParametersRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1960,13 +1943,11 @@ def test_apply_parameters( with mock.patch.object(type(client.transport.apply_parameters), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.apply_parameters(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_memcache.ApplyParametersRequest() # Establish that the response is the type that we expect. @@ -1981,7 +1962,7 @@ def test_apply_parameters_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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1989,7 +1970,6 @@ def test_apply_parameters_empty_call(): client.apply_parameters() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.ApplyParametersRequest() @@ -1998,7 +1978,7 @@ async def test_apply_parameters_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.ApplyParametersRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2011,13 +1991,11 @@ async def test_apply_parameters_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.apply_parameters(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.ApplyParametersRequest() # Establish that the response is the type that we expect. @@ -2030,17 +2008,17 @@ async def test_apply_parameters_async_from_dict(): def test_apply_parameters_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.ApplyParametersRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.apply_parameters), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.apply_parameters(request) # Establish that the underlying gRPC stub method was called. @@ -2055,11 +2033,14 @@ def test_apply_parameters_field_headers(): @pytest.mark.asyncio async def test_apply_parameters_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.ApplyParametersRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2067,7 +2048,6 @@ async def test_apply_parameters_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.apply_parameters(request) # Establish that the underlying gRPC stub method was called. @@ -2081,13 +2061,12 @@ async def test_apply_parameters_field_headers_async(): def test_apply_parameters_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.apply_parameters), "__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.apply_parameters( @@ -2098,16 +2077,13 @@ def test_apply_parameters_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].node_ids == ["node_ids_value"] - assert args[0].apply_all == True def test_apply_parameters_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2122,7 +2098,9 @@ def test_apply_parameters_flattened_error(): @pytest.mark.asyncio async def test_apply_parameters_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.apply_parameters), "__call__") as call: @@ -2142,17 +2120,16 @@ async def test_apply_parameters_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].node_ids == ["node_ids_value"] - assert args[0].apply_all == True @pytest.mark.asyncio async def test_apply_parameters_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2168,16 +2145,16 @@ async def test_apply_parameters_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudMemcacheClient( - 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.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudMemcacheClient( @@ -2187,7 +2164,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudMemcacheClient( @@ -2198,7 +2175,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = CloudMemcacheClient(transport=transport) assert client.transport is transport @@ -2207,13 +2184,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.CloudMemcacheGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2228,23 +2205,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 = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.CloudMemcacheGrpcTransport,) def test_cloud_memcache_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.CloudMemcacheTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2256,7 +2233,7 @@ def test_cloud_memcache_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CloudMemcacheTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2280,15 +2257,37 @@ def test_cloud_memcache_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_cloud_memcache_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.memcache_v1.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.CloudMemcacheTransport( + 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_memcache_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.memcache_v1.services.cloud_memcache.transports.CloudMemcacheTransport._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.CloudMemcacheTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -2301,19 +2300,33 @@ def test_cloud_memcache_base_transport_with_credentials_file(): def test_cloud_memcache_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.memcache_v1.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudMemcacheTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_cloud_memcache_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) + CloudMemcacheClient() + 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_memcache_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) CloudMemcacheClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -2321,20 +2334,156 @@ def test_cloud_memcache_auth_adc(): ) -def test_cloud_memcache_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.CloudMemcacheGrpcTransport, + transports.CloudMemcacheGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_cloud_memcache_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.CloudMemcacheGrpcTransport( - 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.CloudMemcacheGrpcTransport, + transports.CloudMemcacheGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_cloud_memcache_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.CloudMemcacheGrpcTransport, grpc_helpers), + (transports.CloudMemcacheGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_cloud_memcache_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( + "memcache.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="memcache.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.CloudMemcacheGrpcTransport, grpc_helpers), + (transports.CloudMemcacheGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_cloud_memcache_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( + "memcache.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.CloudMemcacheGrpcTransport, grpc_helpers), + (transports.CloudMemcacheGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_cloud_memcache_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( + "memcache.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", [ @@ -2343,7 +2492,7 @@ def test_cloud_memcache_transport_auth_adc(): ], ) def test_cloud_memcache_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: @@ -2382,7 +2531,7 @@ def test_cloud_memcache_grpc_transport_client_cert_source_for_mtls(transport_cla def test_cloud_memcache_host_no_port(): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="memcache.googleapis.com" ), @@ -2392,7 +2541,7 @@ def test_cloud_memcache_host_no_port(): def test_cloud_memcache_host_with_port(): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="memcache.googleapis.com:8000" ), @@ -2446,9 +2595,9 @@ def test_cloud_memcache_transport_channel_mtls_with_client_cert_source(transport 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", @@ -2524,7 +2673,7 @@ def test_cloud_memcache_transport_channel_mtls_with_adc(transport_class): def test_cloud_memcache_grpc_lro_client(): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -2537,7 +2686,7 @@ def test_cloud_memcache_grpc_lro_client(): def test_cloud_memcache_grpc_lro_async_client(): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -2552,7 +2701,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, ) @@ -2575,7 +2723,6 @@ def test_parse_instance_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2596,7 +2743,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = CloudMemcacheClient.common_folder_path(folder) assert expected == actual @@ -2615,7 +2761,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = CloudMemcacheClient.common_organization_path(organization) assert expected == actual @@ -2634,7 +2779,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = CloudMemcacheClient.common_project_path(project) assert expected == actual @@ -2654,7 +2798,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, ) @@ -2681,7 +2824,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.CloudMemcacheTransport, "_prep_wrapped_messages" ) as prep: client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2690,6 +2833,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = CloudMemcacheClient.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/memcache_v1beta2/__init__.py b/tests/unit/gapic/memcache_v1beta2/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/memcache_v1beta2/__init__.py +++ b/tests/unit/gapic/memcache_v1beta2/__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/memcache_v1beta2/test_cloud_memcache.py b/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py index 1e242ab..b991eec 100644 --- a/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py +++ b/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.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,16 +23,16 @@ 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.memcache_v1beta2.services.cloud_memcache import ( CloudMemcacheAsyncClient, @@ -41,11 +40,41 @@ from google.cloud.memcache_v1beta2.services.cloud_memcache import CloudMemcacheClient from google.cloud.memcache_v1beta2.services.cloud_memcache import pagers from google.cloud.memcache_v1beta2.services.cloud_memcache import transports +from google.cloud.memcache_v1beta2.services.cloud_memcache.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.memcache_v1beta2.services.cloud_memcache.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.memcache_v1beta2.types import cloud_memcache 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(): @@ -96,7 +125,7 @@ def test__get_default_mtls_endpoint(): "client_class", [CloudMemcacheClient, CloudMemcacheAsyncClient,] ) def test_cloud_memcache_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: @@ -113,7 +142,7 @@ def test_cloud_memcache_client_from_service_account_info(client_class): "client_class", [CloudMemcacheClient, CloudMemcacheAsyncClient,] ) def test_cloud_memcache_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: @@ -166,7 +195,7 @@ def test_cloud_memcache_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(CloudMemcacheClient, "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() @@ -454,7 +483,7 @@ def test_list_instances( transport: str = "grpc", request_type=cloud_memcache.ListInstancesRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -467,21 +496,16 @@ def test_list_instances( call.return_value = cloud_memcache.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_memcache.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"] @@ -493,7 +517,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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -501,7 +525,6 @@ def test_list_instances_empty_call(): client.list_instances() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.ListInstancesRequest() @@ -510,7 +533,7 @@ async def test_list_instances_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.ListInstancesRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -526,20 +549,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_memcache.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"] @@ -549,17 +568,17 @@ async def test_list_instances_async_from_dict(): def test_list_instances_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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_memcache.ListInstancesResponse() - client.list_instances(request) # Establish that the underlying gRPC stub method was called. @@ -574,11 +593,14 @@ def test_list_instances_field_headers(): @pytest.mark.asyncio async def test_list_instances_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.ListInstancesRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -586,7 +608,6 @@ async def test_list_instances_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_memcache.ListInstancesResponse() ) - await client.list_instances(request) # Establish that the underlying gRPC stub method was called. @@ -600,13 +621,12 @@ async def test_list_instances_field_headers_async(): def test_list_instances_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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",) @@ -615,12 +635,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 = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -632,7 +651,9 @@ def test_list_instances_flattened_error(): @pytest.mark.asyncio async def test_list_instances_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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: @@ -650,13 +671,14 @@ 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 = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -667,7 +689,7 @@ async def test_list_instances_flattened_error_async(): def test_list_instances_pager(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials,) + client = CloudMemcacheClient(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: @@ -705,7 +727,7 @@ def test_list_instances_pager(): def test_list_instances_pages(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials,) + client = CloudMemcacheClient(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: @@ -735,7 +757,7 @@ def test_list_instances_pages(): @pytest.mark.asyncio async def test_list_instances_async_pager(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials,) + client = CloudMemcacheAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -772,7 +794,7 @@ async def test_list_instances_async_pager(): @pytest.mark.asyncio async def test_list_instances_async_pages(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials,) + client = CloudMemcacheAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -808,7 +830,7 @@ def test_get_instance( transport: str = "grpc", request_type=cloud_memcache.GetInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -830,37 +852,24 @@ def test_get_instance( discovery_endpoint="discovery_endpoint_value", update_available=True, ) - 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_memcache.GetInstanceRequest() # Establish that the response is the type that we expect. - assert isinstance(response, cloud_memcache.Instance) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.authorized_network == "authorized_network_value" - assert response.zones == ["zones_value"] - assert response.node_count == 1070 - assert response.memcache_version == cloud_memcache.MemcacheVersion.MEMCACHE_1_5 - assert response.state == cloud_memcache.Instance.State.CREATING - assert response.memcache_full_version == "memcache_full_version_value" - assert response.discovery_endpoint == "discovery_endpoint_value" - assert response.update_available is True @@ -872,7 +881,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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -880,7 +889,6 @@ def test_get_instance_empty_call(): client.get_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.GetInstanceRequest() @@ -889,7 +897,7 @@ async def test_get_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.GetInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -913,36 +921,24 @@ async def test_get_instance_async( update_available=True, ) ) - 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_memcache.GetInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, cloud_memcache.Instance) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.authorized_network == "authorized_network_value" - assert response.zones == ["zones_value"] - assert response.node_count == 1070 - assert response.memcache_version == cloud_memcache.MemcacheVersion.MEMCACHE_1_5 - assert response.state == cloud_memcache.Instance.State.CREATING - assert response.memcache_full_version == "memcache_full_version_value" - assert response.discovery_endpoint == "discovery_endpoint_value" - assert response.update_available is True @@ -952,17 +948,17 @@ async def test_get_instance_async_from_dict(): def test_get_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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_memcache.Instance() - client.get_instance(request) # Establish that the underlying gRPC stub method was called. @@ -977,11 +973,14 @@ def test_get_instance_field_headers(): @pytest.mark.asyncio async def test_get_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.GetInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -989,7 +988,6 @@ async def test_get_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_memcache.Instance() ) - await client.get_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1003,13 +1001,12 @@ async def test_get_instance_field_headers_async(): def test_get_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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",) @@ -1018,12 +1015,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 = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1035,7 +1031,9 @@ def test_get_instance_flattened_error(): @pytest.mark.asyncio async def test_get_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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: @@ -1053,13 +1051,14 @@ 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 = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1073,7 +1072,7 @@ def test_create_instance( transport: str = "grpc", request_type=cloud_memcache.CreateInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1084,13 +1083,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_memcache.CreateInstanceRequest() # Establish that the response is the type that we expect. @@ -1105,7 +1102,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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1113,7 +1110,6 @@ def test_create_instance_empty_call(): client.create_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.CreateInstanceRequest() @@ -1122,7 +1118,7 @@ async def test_create_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.CreateInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1135,13 +1131,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_memcache.CreateInstanceRequest() # Establish that the response is the type that we expect. @@ -1154,17 +1148,17 @@ async def test_create_instance_async_from_dict(): def test_create_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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. @@ -1179,11 +1173,14 @@ def test_create_instance_field_headers(): @pytest.mark.asyncio async def test_create_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.CreateInstanceRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1191,7 +1188,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. @@ -1205,13 +1201,12 @@ async def test_create_instance_field_headers_async(): def test_create_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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( @@ -1224,16 +1219,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].resource == cloud_memcache.Instance(name="name_value") def test_create_instance_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1248,7 +1240,9 @@ def test_create_instance_flattened_error(): @pytest.mark.asyncio async def test_create_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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: @@ -1270,17 +1264,16 @@ 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].resource == cloud_memcache.Instance(name="name_value") @pytest.mark.asyncio async def test_create_instance_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1297,7 +1290,7 @@ def test_update_instance( transport: str = "grpc", request_type=cloud_memcache.UpdateInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1308,13 +1301,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_memcache.UpdateInstanceRequest() # Establish that the response is the type that we expect. @@ -1329,7 +1320,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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1337,7 +1328,6 @@ def test_update_instance_empty_call(): client.update_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.UpdateInstanceRequest() @@ -1346,7 +1336,7 @@ async def test_update_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.UpdateInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1359,13 +1349,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_memcache.UpdateInstanceRequest() # Establish that the response is the type that we expect. @@ -1378,17 +1366,17 @@ async def test_update_instance_async_from_dict(): def test_update_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.UpdateInstanceRequest() + request.resource.name = "resource.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. @@ -1405,11 +1393,14 @@ def test_update_instance_field_headers(): @pytest.mark.asyncio async def test_update_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.UpdateInstanceRequest() + request.resource.name = "resource.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1417,7 +1408,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. @@ -1433,17 +1423,16 @@ async def test_update_instance_field_headers_async(): def test_update_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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"]), resource=cloud_memcache.Instance(name="name_value"), ) @@ -1451,28 +1440,28 @@ 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].resource == cloud_memcache.Instance(name="name_value") def test_update_instance_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.UpdateInstanceRequest(), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), resource=cloud_memcache.Instance(name="name_value"), ) @pytest.mark.asyncio async def test_update_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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: @@ -1485,7 +1474,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"]), resource=cloud_memcache.Instance(name="name_value"), ) @@ -1493,22 +1482,22 @@ 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].resource == cloud_memcache.Instance(name="name_value") @pytest.mark.asyncio async def test_update_instance_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.UpdateInstanceRequest(), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), resource=cloud_memcache.Instance(name="name_value"), ) @@ -1517,7 +1506,7 @@ def test_update_parameters( transport: str = "grpc", request_type=cloud_memcache.UpdateParametersRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1530,13 +1519,11 @@ def test_update_parameters( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_parameters(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_memcache.UpdateParametersRequest() # Establish that the response is the type that we expect. @@ -1551,7 +1538,7 @@ def test_update_parameters_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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1561,7 +1548,6 @@ def test_update_parameters_empty_call(): client.update_parameters() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.UpdateParametersRequest() @@ -1570,7 +1556,7 @@ async def test_update_parameters_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.UpdateParametersRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1585,13 +1571,11 @@ async def test_update_parameters_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_parameters(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.UpdateParametersRequest() # Establish that the response is the type that we expect. @@ -1604,11 +1588,12 @@ async def test_update_parameters_async_from_dict(): def test_update_parameters_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.UpdateParametersRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1616,7 +1601,6 @@ def test_update_parameters_field_headers(): type(client.transport.update_parameters), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_parameters(request) # Establish that the underlying gRPC stub method was called. @@ -1631,11 +1615,14 @@ def test_update_parameters_field_headers(): @pytest.mark.asyncio async def test_update_parameters_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.UpdateParametersRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1645,7 +1632,6 @@ async def test_update_parameters_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_parameters(request) # Establish that the underlying gRPC stub method was called. @@ -1659,7 +1645,7 @@ async def test_update_parameters_field_headers_async(): def test_update_parameters_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1667,12 +1653,11 @@ def test_update_parameters_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.update_parameters( name="name_value", - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), parameters=cloud_memcache.MemcacheParameters(id="id_value"), ) @@ -1680,16 +1665,13 @@ def test_update_parameters_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - - 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].parameters == cloud_memcache.MemcacheParameters(id="id_value") def test_update_parameters_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1697,14 +1679,16 @@ def test_update_parameters_flattened_error(): client.update_parameters( cloud_memcache.UpdateParametersRequest(), name="name_value", - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), parameters=cloud_memcache.MemcacheParameters(id="id_value"), ) @pytest.mark.asyncio async def test_update_parameters_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1720,7 +1704,7 @@ async def test_update_parameters_flattened_async(): # using the keyword arguments to the method. response = await client.update_parameters( name="name_value", - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), parameters=cloud_memcache.MemcacheParameters(id="id_value"), ) @@ -1728,17 +1712,16 @@ async def test_update_parameters_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - - 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].parameters == cloud_memcache.MemcacheParameters(id="id_value") @pytest.mark.asyncio async def test_update_parameters_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1746,7 +1729,7 @@ async def test_update_parameters_flattened_error_async(): await client.update_parameters( cloud_memcache.UpdateParametersRequest(), name="name_value", - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), parameters=cloud_memcache.MemcacheParameters(id="id_value"), ) @@ -1755,7 +1738,7 @@ def test_delete_instance( transport: str = "grpc", request_type=cloud_memcache.DeleteInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1766,13 +1749,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_memcache.DeleteInstanceRequest() # Establish that the response is the type that we expect. @@ -1787,7 +1768,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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1795,7 +1776,6 @@ def test_delete_instance_empty_call(): client.delete_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.DeleteInstanceRequest() @@ -1804,7 +1784,7 @@ async def test_delete_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.DeleteInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1817,13 +1797,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_memcache.DeleteInstanceRequest() # Establish that the response is the type that we expect. @@ -1836,17 +1814,17 @@ async def test_delete_instance_async_from_dict(): def test_delete_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.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. @@ -1861,11 +1839,14 @@ def test_delete_instance_field_headers(): @pytest.mark.asyncio async def test_delete_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.DeleteInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1873,7 +1854,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. @@ -1887,13 +1867,12 @@ async def test_delete_instance_field_headers_async(): def test_delete_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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",) @@ -1902,12 +1881,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 = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1919,7 +1897,9 @@ def test_delete_instance_flattened_error(): @pytest.mark.asyncio async def test_delete_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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: @@ -1937,13 +1917,14 @@ 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 = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1957,7 +1938,7 @@ def test_apply_parameters( transport: str = "grpc", request_type=cloud_memcache.ApplyParametersRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1968,13 +1949,11 @@ def test_apply_parameters( with mock.patch.object(type(client.transport.apply_parameters), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.apply_parameters(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_memcache.ApplyParametersRequest() # Establish that the response is the type that we expect. @@ -1989,7 +1968,7 @@ def test_apply_parameters_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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1997,7 +1976,6 @@ def test_apply_parameters_empty_call(): client.apply_parameters() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.ApplyParametersRequest() @@ -2006,7 +1984,7 @@ async def test_apply_parameters_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.ApplyParametersRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2019,13 +1997,11 @@ async def test_apply_parameters_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.apply_parameters(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.ApplyParametersRequest() # Establish that the response is the type that we expect. @@ -2038,17 +2014,17 @@ async def test_apply_parameters_async_from_dict(): def test_apply_parameters_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.ApplyParametersRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.apply_parameters), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.apply_parameters(request) # Establish that the underlying gRPC stub method was called. @@ -2063,11 +2039,14 @@ def test_apply_parameters_field_headers(): @pytest.mark.asyncio async def test_apply_parameters_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.ApplyParametersRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2075,7 +2054,6 @@ async def test_apply_parameters_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.apply_parameters(request) # Establish that the underlying gRPC stub method was called. @@ -2089,13 +2067,12 @@ async def test_apply_parameters_field_headers_async(): def test_apply_parameters_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.apply_parameters), "__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.apply_parameters( @@ -2106,16 +2083,13 @@ def test_apply_parameters_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].node_ids == ["node_ids_value"] - assert args[0].apply_all == True def test_apply_parameters_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2130,7 +2104,9 @@ def test_apply_parameters_flattened_error(): @pytest.mark.asyncio async def test_apply_parameters_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.apply_parameters), "__call__") as call: @@ -2150,17 +2126,16 @@ async def test_apply_parameters_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].node_ids == ["node_ids_value"] - assert args[0].apply_all == True @pytest.mark.asyncio async def test_apply_parameters_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2177,7 +2152,7 @@ def test_apply_software_update( transport: str = "grpc", request_type=cloud_memcache.ApplySoftwareUpdateRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2190,13 +2165,11 @@ def test_apply_software_update( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.apply_software_update(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_memcache.ApplySoftwareUpdateRequest() # Establish that the response is the type that we expect. @@ -2211,7 +2184,7 @@ def test_apply_software_update_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 = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2221,7 +2194,6 @@ def test_apply_software_update_empty_call(): client.apply_software_update() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.ApplySoftwareUpdateRequest() @@ -2231,7 +2203,7 @@ async def test_apply_software_update_async( request_type=cloud_memcache.ApplySoftwareUpdateRequest, ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2246,13 +2218,11 @@ async def test_apply_software_update_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.apply_software_update(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_memcache.ApplySoftwareUpdateRequest() # Establish that the response is the type that we expect. @@ -2265,11 +2235,12 @@ async def test_apply_software_update_async_from_dict(): def test_apply_software_update_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(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_memcache.ApplySoftwareUpdateRequest() + request.instance = "instance/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2277,7 +2248,6 @@ def test_apply_software_update_field_headers(): type(client.transport.apply_software_update), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.apply_software_update(request) # Establish that the underlying gRPC stub method was called. @@ -2292,11 +2262,14 @@ def test_apply_software_update_field_headers(): @pytest.mark.asyncio async def test_apply_software_update_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + 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_memcache.ApplySoftwareUpdateRequest() + request.instance = "instance/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2306,7 +2279,6 @@ async def test_apply_software_update_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.apply_software_update(request) # Establish that the underlying gRPC stub method was called. @@ -2320,7 +2292,7 @@ async def test_apply_software_update_field_headers_async(): def test_apply_software_update_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2328,7 +2300,6 @@ def test_apply_software_update_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.apply_software_update( @@ -2339,16 +2310,13 @@ def test_apply_software_update_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].instance == "instance_value" - assert args[0].node_ids == ["node_ids_value"] - assert args[0].apply_all == True def test_apply_software_update_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2363,7 +2331,9 @@ def test_apply_software_update_flattened_error(): @pytest.mark.asyncio async def test_apply_software_update_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2385,17 +2355,16 @@ async def test_apply_software_update_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].instance == "instance_value" - assert args[0].node_ids == ["node_ids_value"] - assert args[0].apply_all == True @pytest.mark.asyncio async def test_apply_software_update_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2411,16 +2380,16 @@ async def test_apply_software_update_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudMemcacheClient( - 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.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudMemcacheClient( @@ -2430,7 +2399,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudMemcacheClient( @@ -2441,7 +2410,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = CloudMemcacheClient(transport=transport) assert client.transport is transport @@ -2450,13 +2419,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.CloudMemcacheGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2471,23 +2440,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 = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + client = CloudMemcacheClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.CloudMemcacheGrpcTransport,) def test_cloud_memcache_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.CloudMemcacheTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2499,7 +2468,7 @@ def test_cloud_memcache_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CloudMemcacheTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2524,15 +2493,37 @@ def test_cloud_memcache_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_cloud_memcache_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.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.CloudMemcacheTransport( + 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_memcache_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.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheTransport._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.CloudMemcacheTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -2545,19 +2536,33 @@ def test_cloud_memcache_base_transport_with_credentials_file(): def test_cloud_memcache_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.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudMemcacheTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_cloud_memcache_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) + CloudMemcacheClient() + 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_memcache_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) CloudMemcacheClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -2565,20 +2570,156 @@ def test_cloud_memcache_auth_adc(): ) -def test_cloud_memcache_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.CloudMemcacheGrpcTransport, + transports.CloudMemcacheGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_cloud_memcache_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.CloudMemcacheGrpcTransport( - 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.CloudMemcacheGrpcTransport, + transports.CloudMemcacheGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_cloud_memcache_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.CloudMemcacheGrpcTransport, grpc_helpers), + (transports.CloudMemcacheGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_cloud_memcache_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( + "memcache.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="memcache.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.CloudMemcacheGrpcTransport, grpc_helpers), + (transports.CloudMemcacheGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_cloud_memcache_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( + "memcache.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.CloudMemcacheGrpcTransport, grpc_helpers), + (transports.CloudMemcacheGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_cloud_memcache_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( + "memcache.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", [ @@ -2587,7 +2728,7 @@ def test_cloud_memcache_transport_auth_adc(): ], ) def test_cloud_memcache_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: @@ -2626,7 +2767,7 @@ def test_cloud_memcache_grpc_transport_client_cert_source_for_mtls(transport_cla def test_cloud_memcache_host_no_port(): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="memcache.googleapis.com" ), @@ -2636,7 +2777,7 @@ def test_cloud_memcache_host_no_port(): def test_cloud_memcache_host_with_port(): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="memcache.googleapis.com:8000" ), @@ -2690,9 +2831,9 @@ def test_cloud_memcache_transport_channel_mtls_with_client_cert_source(transport 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", @@ -2768,7 +2909,7 @@ def test_cloud_memcache_transport_channel_mtls_with_adc(transport_class): def test_cloud_memcache_grpc_lro_client(): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -2781,7 +2922,7 @@ def test_cloud_memcache_grpc_lro_client(): def test_cloud_memcache_grpc_lro_async_client(): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -2796,7 +2937,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, ) @@ -2819,7 +2959,6 @@ def test_parse_instance_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2840,7 +2979,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = CloudMemcacheClient.common_folder_path(folder) assert expected == actual @@ -2859,7 +2997,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = CloudMemcacheClient.common_organization_path(organization) assert expected == actual @@ -2878,7 +3015,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = CloudMemcacheClient.common_project_path(project) assert expected == actual @@ -2898,7 +3034,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, ) @@ -2925,7 +3060,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.CloudMemcacheTransport, "_prep_wrapped_messages" ) as prep: client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2934,6 +3069,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = CloudMemcacheClient.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)