- On January 1, 2020 this library will no longer support Python 2 on the latest released version. - Previously released library versions will continue to be available. For more information please + As of January 1, 2020 this library no longer supports Python 2 on the latest released version. + Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.
{% block body %} {% endblock %} diff --git a/docs/conf.py b/docs/conf.py index 54a5d17..a84e615 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,12 +20,16 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath("..")) +# For plugins that can not read conf.py. +# See also: https://github.com/docascode/sphinx-docfx-yaml/issues/85 +sys.path.insert(0, os.path.abspath(".")) + __version__ = "" # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "1.6.3" +needs_sphinx = "1.5.5" # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom @@ -35,6 +39,7 @@ "sphinx.ext.autosummary", "sphinx.ext.intersphinx", "sphinx.ext.coverage", + "sphinx.ext.doctest", "sphinx.ext.napoleon", "sphinx.ext.todo", "sphinx.ext.viewcode", @@ -43,7 +48,7 @@ # autodoc/autosummary flags autoclass_content = "both" -autodoc_default_flags = ["members"] +autodoc_default_options = {"members": True} autosummary_generate = True @@ -90,7 +95,12 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ["_build"] +exclude_patterns = [ + "_build", + "samples/AUTHORING_GUIDE.md", + "samples/CONTRIBUTING.md", + "samples/snippets/README.rst", +] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -335,10 +345,11 @@ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { - "python": ("http://python.readthedocs.org/en/latest/", None), - "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), - "grpc": ("https://grpc.io/grpc/python/", None), + "python": ("https://python.readthedocs.org/en/latest/", None), + "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), + "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), + "grpc": ("https://grpc.github.io/grpc/python/", None), + "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), } diff --git a/docs/memcache_v1beta2/services.rst b/docs/memcache_v1beta2/services.rst index 72a3e8a..6b2845e 100644 --- a/docs/memcache_v1beta2/services.rst +++ b/docs/memcache_v1beta2/services.rst @@ -1,6 +1,6 @@ -Client for Google Cloud Memcache API -==================================== +Services for Google Cloud Memcache v1beta2 API +============================================== -.. automodule:: google.cloud.memcache_v1beta2 +.. automodule:: google.cloud.memcache_v1beta2.services.cloud_memcache :members: :inherited-members: diff --git a/docs/memcache_v1beta2/types.rst b/docs/memcache_v1beta2/types.rst index 746c77b..1b47aa6 100644 --- a/docs/memcache_v1beta2/types.rst +++ b/docs/memcache_v1beta2/types.rst @@ -1,5 +1,6 @@ -Types for Google Cloud Memcache API -=================================== +Types for Google Cloud Memcache v1beta2 API +=========================================== .. automodule:: google.cloud.memcache_v1beta2.types :members: + :show-inheritance: diff --git a/google/cloud/memcache_v1beta2/services/cloud_memcache/__init__.py b/google/cloud/memcache_v1beta2/services/cloud_memcache/__init__.py index a2e5bf4..8524cb4 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/__init__.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/__init__.py @@ -18,4 +18,7 @@ from .client import CloudMemcacheClient from .async_client import CloudMemcacheAsyncClient -__all__ = ("CloudMemcacheClient", "CloudMemcacheAsyncClient") +__all__ = ( + "CloudMemcacheClient", + "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 3330874..886e32c 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py @@ -101,7 +101,6 @@ class CloudMemcacheAsyncClient: CloudMemcacheClient.parse_common_location_path ) - from_service_account_info = CloudMemcacheClient.from_service_account_info from_service_account_file = CloudMemcacheClient.from_service_account_file from_service_account_json = from_service_account_file @@ -227,7 +226,7 @@ async def list_instances( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_instances, - default_timeout=None, + default_timeout=1200.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -238,12 +237,12 @@ async def list_instances( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. response = pagers.ListInstancesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata + method=rpc, request=request, response=response, metadata=metadata, ) # Done; return the response. @@ -305,7 +304,7 @@ async def get_instance( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_instance, - default_timeout=None, + default_timeout=1200.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -316,7 +315,7 @@ async def get_instance( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -406,7 +405,7 @@ async def create_instance( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_instance, - default_timeout=None, + default_timeout=1200.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -417,7 +416,7 @@ async def create_instance( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -499,7 +498,7 @@ async def update_instance( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_instance, - default_timeout=None, + default_timeout=1200.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -512,7 +511,7 @@ async def update_instance( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -604,7 +603,7 @@ async def update_parameters( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_parameters, - default_timeout=None, + default_timeout=1200.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -615,7 +614,7 @@ async def update_parameters( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -700,7 +699,7 @@ async def delete_instance( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_instance, - default_timeout=None, + default_timeout=1200.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -711,7 +710,7 @@ async def delete_instance( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -807,7 +806,7 @@ async def apply_parameters( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.apply_parameters, - default_timeout=None, + default_timeout=1200.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -818,7 +817,7 @@ async def apply_parameters( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -834,7 +833,7 @@ async def apply_parameters( try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution("google-cloud-memcache").version + gapic_version=pkg_resources.get_distribution("google-cloud-memcache",).version, ) except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() diff --git a/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py b/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py index c98cfcc..0a1ef7c 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py @@ -57,7 +57,7 @@ class CloudMemcacheClientMeta(type): _transport_registry["grpc"] = CloudMemcacheGrpcTransport _transport_registry["grpc_asyncio"] = CloudMemcacheGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None) -> Type[CloudMemcacheTransport]: + def get_transport_class(cls, label: str = None,) -> Type[CloudMemcacheTransport]: """Return an appropriate transport class. Args: @@ -133,22 +133,6 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - {@api.name}: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_info(info) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -179,10 +163,10 @@ def transport(self) -> CloudMemcacheTransport: return self._transport @staticmethod - def instance_path(project: str, location: str, instance: str) -> str: + def instance_path(project: str, location: str, instance: str,) -> str: """Return a fully-qualified instance string.""" return "projects/{project}/locations/{location}/instances/{instance}".format( - project=project, location=location, instance=instance + project=project, location=location, instance=instance, ) @staticmethod @@ -198,7 +182,7 @@ def parse_instance_path(path: str) -> Dict[str, str]: def common_billing_account_path(billing_account: str,) -> str: """Return a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( - billing_account=billing_account + billing_account=billing_account, ) @staticmethod @@ -210,7 +194,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.""" - return "folders/{folder}".format(folder=folder) + return "folders/{folder}".format(folder=folder,) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -221,7 +205,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.""" - return "organizations/{organization}".format(organization=organization) + return "organizations/{organization}".format(organization=organization,) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -232,7 +216,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.""" - return "projects/{project}".format(project=project) + return "projects/{project}".format(project=project,) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -241,10 +225,10 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str) -> str: + def common_location_path(project: str, location: str,) -> str: """Return a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location + project=project, location=location, ) @staticmethod @@ -443,12 +427,12 @@ def list_instances( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # This method is paged; wrap the response in a pager, which provides # an `__iter__` convenience method. response = pagers.ListInstancesPager( - method=rpc, request=request, response=response, metadata=metadata + method=rpc, request=request, response=response, metadata=metadata, ) # Done; return the response. @@ -522,7 +506,7 @@ def get_instance( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -625,7 +609,7 @@ def create_instance( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation.from_gapic( @@ -722,7 +706,7 @@ def update_instance( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation.from_gapic( @@ -826,7 +810,7 @@ def update_parameters( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation.from_gapic( @@ -923,7 +907,7 @@ def delete_instance( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation.from_gapic( @@ -1031,7 +1015,7 @@ def apply_parameters( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation.from_gapic( @@ -1047,7 +1031,7 @@ def apply_parameters( try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution("google-cloud-memcache").version + gapic_version=pkg_resources.get_distribution("google-cloud-memcache",).version, ) except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() 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 717a972..3a96e70 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/base.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/base.py @@ -32,7 +32,7 @@ try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution("google-cloud-memcache").version + gapic_version=pkg_resources.get_distribution("google-cloud-memcache",).version, ) except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() @@ -107,25 +107,25 @@ def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.list_instances: gapic_v1.method.wrap_method( - self.list_instances, default_timeout=None, client_info=client_info + self.list_instances, default_timeout=1200.0, client_info=client_info, ), self.get_instance: gapic_v1.method.wrap_method( - self.get_instance, default_timeout=None, client_info=client_info + self.get_instance, default_timeout=1200.0, client_info=client_info, ), self.create_instance: gapic_v1.method.wrap_method( - self.create_instance, default_timeout=None, client_info=client_info + self.create_instance, default_timeout=1200.0, client_info=client_info, ), self.update_instance: gapic_v1.method.wrap_method( - self.update_instance, default_timeout=None, client_info=client_info + self.update_instance, default_timeout=1200.0, client_info=client_info, ), self.update_parameters: gapic_v1.method.wrap_method( - self.update_parameters, default_timeout=None, client_info=client_info + self.update_parameters, default_timeout=1200.0, client_info=client_info, ), self.delete_instance: gapic_v1.method.wrap_method( - self.delete_instance, default_timeout=None, client_info=client_info + self.delete_instance, default_timeout=1200.0, client_info=client_info, ), self.apply_parameters: gapic_v1.method.wrap_method( - self.apply_parameters, default_timeout=None, client_info=client_info + self.apply_parameters, default_timeout=1200.0, client_info=client_info, ), } @@ -136,7 +136,7 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_instances( - self + self, ) -> typing.Callable[ [cloud_memcache.ListInstancesRequest], typing.Union[ @@ -148,7 +148,7 @@ def list_instances( @property def get_instance( - self + self, ) -> typing.Callable[ [cloud_memcache.GetInstanceRequest], typing.Union[ @@ -159,7 +159,7 @@ def get_instance( @property def create_instance( - self + self, ) -> typing.Callable[ [cloud_memcache.CreateInstanceRequest], typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], @@ -168,7 +168,7 @@ def create_instance( @property def update_instance( - self + self, ) -> typing.Callable[ [cloud_memcache.UpdateInstanceRequest], typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], @@ -177,7 +177,7 @@ def update_instance( @property def update_parameters( - self + self, ) -> typing.Callable[ [cloud_memcache.UpdateParametersRequest], typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], @@ -186,7 +186,7 @@ def update_parameters( @property def delete_instance( - self + self, ) -> typing.Callable[ [cloud_memcache.DeleteInstanceRequest], typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], @@ -195,7 +195,7 @@ def delete_instance( @property def apply_parameters( - self + self, ) -> typing.Callable[ [cloud_memcache.ApplyParametersRequest], typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], 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 cb915b3..09e1170 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc.py @@ -275,7 +275,7 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_instances( - self + self, ) -> Callable[ [cloud_memcache.ListInstancesRequest], cloud_memcache.ListInstancesResponse ]: @@ -303,7 +303,7 @@ def list_instances( @property def get_instance( - self + self, ) -> Callable[[cloud_memcache.GetInstanceRequest], cloud_memcache.Instance]: r"""Return a callable for the get instance method over gRPC. @@ -329,7 +329,7 @@ def get_instance( @property def create_instance( - self + self, ) -> Callable[[cloud_memcache.CreateInstanceRequest], operations.Operation]: r"""Return a callable for the create instance method over gRPC. @@ -356,7 +356,7 @@ def create_instance( @property def update_instance( - self + self, ) -> Callable[[cloud_memcache.UpdateInstanceRequest], operations.Operation]: r"""Return a callable for the update instance method over gRPC. @@ -383,7 +383,7 @@ def update_instance( @property def update_parameters( - self + self, ) -> Callable[[cloud_memcache.UpdateParametersRequest], operations.Operation]: r"""Return a callable for the update parameters method over gRPC. @@ -412,7 +412,7 @@ def update_parameters( @property def delete_instance( - self + self, ) -> Callable[[cloud_memcache.DeleteInstanceRequest], operations.Operation]: r"""Return a callable for the delete instance method over gRPC. @@ -438,7 +438,7 @@ def delete_instance( @property def apply_parameters( - self + self, ) -> Callable[[cloud_memcache.ApplyParametersRequest], operations.Operation]: r"""Return a callable for the apply parameters method over gRPC. 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 c0eec4f..009acf5 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 @@ -281,7 +281,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: @property def list_instances( - self + self, ) -> Callable[ [cloud_memcache.ListInstancesRequest], Awaitable[cloud_memcache.ListInstancesResponse], @@ -310,7 +310,7 @@ def list_instances( @property def get_instance( - self + self, ) -> Callable[ [cloud_memcache.GetInstanceRequest], Awaitable[cloud_memcache.Instance] ]: @@ -338,7 +338,7 @@ def get_instance( @property def create_instance( - self + self, ) -> Callable[ [cloud_memcache.CreateInstanceRequest], Awaitable[operations.Operation] ]: @@ -367,7 +367,7 @@ def create_instance( @property def update_instance( - self + self, ) -> Callable[ [cloud_memcache.UpdateInstanceRequest], Awaitable[operations.Operation] ]: @@ -396,7 +396,7 @@ def update_instance( @property def update_parameters( - self + self, ) -> Callable[ [cloud_memcache.UpdateParametersRequest], Awaitable[operations.Operation] ]: @@ -427,7 +427,7 @@ def update_parameters( @property def delete_instance( - self + self, ) -> Callable[ [cloud_memcache.DeleteInstanceRequest], Awaitable[operations.Operation] ]: @@ -455,7 +455,7 @@ def delete_instance( @property def apply_parameters( - self + self, ) -> Callable[ [cloud_memcache.ApplyParametersRequest], Awaitable[operations.Operation] ]: diff --git a/google/cloud/memcache_v1beta2/types/cloud_memcache.py b/google/cloud/memcache_v1beta2/types/cloud_memcache.py index 60e2d0c..36cd39e 100644 --- a/google/cloud/memcache_v1beta2/types/cloud_memcache.py +++ b/google/cloud/memcache_v1beta2/types/cloud_memcache.py @@ -191,13 +191,13 @@ class State(proto.Enum): zone = proto.Field(proto.STRING, number=2) - state = proto.Field(proto.ENUM, number=3, enum="Instance.Node.State") + 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) - parameters = proto.Field(proto.MESSAGE, number=6, message="MemcacheParameters") + parameters = proto.Field(proto.MESSAGE, number=6, message="MemcacheParameters",) class InstanceMessage(proto.Message): r""" @@ -216,7 +216,7 @@ class Code(proto.Enum): CODE_UNSPECIFIED = 0 ZONE_DISTRIBUTION_UNBALANCED = 1 - code = proto.Field(proto.ENUM, number=1, enum="Instance.InstanceMessage.Code") + code = proto.Field(proto.ENUM, number=1, enum="Instance.InstanceMessage.Code",) message = proto.Field(proto.STRING, number=2) @@ -232,24 +232,24 @@ class Code(proto.Enum): node_count = proto.Field(proto.INT32, number=6) - node_config = proto.Field(proto.MESSAGE, number=7, message=NodeConfig) + node_config = proto.Field(proto.MESSAGE, number=7, message=NodeConfig,) - memcache_version = proto.Field(proto.ENUM, number=9, enum="MemcacheVersion") + memcache_version = proto.Field(proto.ENUM, number=9, enum="MemcacheVersion",) - parameters = proto.Field(proto.MESSAGE, number=11, message="MemcacheParameters") + parameters = proto.Field(proto.MESSAGE, number=11, message="MemcacheParameters",) - memcache_nodes = proto.RepeatedField(proto.MESSAGE, number=12, message=Node) + memcache_nodes = proto.RepeatedField(proto.MESSAGE, number=12, message=Node,) - create_time = proto.Field(proto.MESSAGE, number=13, message=timestamp.Timestamp) + create_time = proto.Field(proto.MESSAGE, number=13, message=timestamp.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=14, message=timestamp.Timestamp) + update_time = proto.Field(proto.MESSAGE, number=14, message=timestamp.Timestamp,) - state = proto.Field(proto.ENUM, number=15, enum=State) + state = proto.Field(proto.ENUM, number=15, enum=State,) memcache_full_version = proto.Field(proto.STRING, number=18) instance_messages = proto.RepeatedField( - proto.MESSAGE, number=19, message=InstanceMessage + proto.MESSAGE, number=19, message=InstanceMessage, ) discovery_endpoint = proto.Field(proto.STRING, number=20) @@ -320,7 +320,7 @@ class ListInstancesResponse(proto.Message): def raw_page(self): return self - resources = proto.RepeatedField(proto.MESSAGE, number=1, message="Instance") + resources = proto.RepeatedField(proto.MESSAGE, number=1, message="Instance",) next_page_token = proto.Field(proto.STRING, number=2) @@ -368,7 +368,7 @@ class CreateInstanceRequest(proto.Message): instance_id = proto.Field(proto.STRING, number=2) - resource = proto.Field(proto.MESSAGE, number=3, message="Instance") + resource = proto.Field(proto.MESSAGE, number=3, message="Instance",) class UpdateInstanceRequest(proto.Message): @@ -385,9 +385,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.FieldMask,) - resource = proto.Field(proto.MESSAGE, number=2, message="Instance") + resource = proto.Field(proto.MESSAGE, number=2, message="Instance",) class DeleteInstanceRequest(proto.Message): @@ -448,9 +448,9 @@ class UpdateParametersRequest(proto.Message): name = proto.Field(proto.STRING, number=1) - update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask) + update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) - parameters = proto.Field(proto.MESSAGE, number=3, message="MemcacheParameters") + parameters = proto.Field(proto.MESSAGE, number=3, message="MemcacheParameters",) class MemcacheParameters(proto.Message): @@ -500,9 +500,9 @@ class OperationMetadata(proto.Message): API version used to start the operation. """ - create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp) + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp) + end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) target = proto.Field(proto.STRING, number=3) @@ -528,7 +528,7 @@ class LocationMetadata(proto.Message): """ available_zones = proto.MapField( - proto.STRING, proto.MESSAGE, number=1, message="ZoneMetadata" + proto.STRING, proto.MESSAGE, number=1, message="ZoneMetadata", ) diff --git a/noxfile.py b/noxfile.py index 8563032..8004482 100644 --- a/noxfile.py +++ b/noxfile.py @@ -23,14 +23,15 @@ import nox -BLACK_VERSION = "black==19.3b0" +BLACK_VERSION = "black==19.10b0" BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] -if os.path.exists("samples"): - BLACK_PATHS.append("samples") +DEFAULT_PYTHON_VERSION = "3.8" +SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] +UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] -@nox.session(python="3.7") +@nox.session(python=DEFAULT_PYTHON_VERSION) def lint(session): """Run linters. @@ -38,7 +39,9 @@ def lint(session): serious code quality issues. """ session.install("flake8", BLACK_VERSION) - session.run("black", "--check", *BLACK_PATHS) + session.run( + "black", "--check", *BLACK_PATHS, + ) session.run("flake8", "google", "tests") @@ -53,10 +56,12 @@ def blacken(session): check the state of the `gcp_ubuntu_config` we use for that Kokoro run. """ session.install(BLACK_VERSION) - session.run("black", *BLACK_PATHS) + session.run( + "black", *BLACK_PATHS, + ) -@nox.session(python="3.7") +@nox.session(python=DEFAULT_PYTHON_VERSION) def lint_setup_py(session): """Verify that setup.py is valid (including RST check).""" session.install("docutils", "pygments") @@ -65,16 +70,19 @@ def lint_setup_py(session): def default(session): # Install all test dependencies, then install this package in-place. - session.install("mock", "pytest", "pytest-cov") + session.install("asyncmock", "pytest-asyncio") + + session.install( + "mock", "pytest", "pytest-cov", + ) session.install("-e", ".") # Run py.test against the unit tests. session.run( "py.test", "--quiet", - "--cov=google.cloud.memcache", - "--cov=google.cloud", - "--cov=tests.unit", + "--cov=google/cloud", + "--cov=tests/unit", "--cov-append", "--cov-config=.coveragerc", "--cov-report=", @@ -84,17 +92,21 @@ def default(session): ) -@nox.session(python=["3.6", "3.7", "3.8"]) +@nox.session(python=UNIT_TEST_PYTHON_VERSIONS) def unit(session): """Run the unit test suite.""" default(session) -@nox.session(python=["3.7"]) +@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def system(session): """Run the system test suite.""" system_test_path = os.path.join("tests", "system.py") system_test_folder_path = os.path.join("tests", "system") + + # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true. + if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false": + session.skip("RUN_SYSTEM_TESTS is set to false, skipping") # Sanity check: Only run tests if the environment variable is set. if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""): session.skip("Credentials must be set via environment variable") @@ -110,7 +122,9 @@ def system(session): # Install all test dependencies, then install this package into the # virtualenv's dist-packages. - session.install("mock", "pytest", "google-cloud-testutils") + session.install( + "mock", "pytest", "google-cloud-testutils", + ) session.install("-e", ".") # Run py.test against the system tests. @@ -120,7 +134,7 @@ def system(session): session.run("py.test", "--quiet", system_test_folder_path, *session.posargs) -@nox.session(python="3.7") +@nox.session(python=DEFAULT_PYTHON_VERSION) def cover(session): """Run the final coverage report. @@ -133,7 +147,7 @@ def cover(session): session.run("coverage", "erase") -@nox.session(python="3.7") +@nox.session(python=DEFAULT_PYTHON_VERSION) def docs(session): """Build the docs for this library.""" @@ -153,3 +167,38 @@ def docs(session): os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def docfx(session): + """Build the docfx yaml files for this library.""" + + session.install("-e", ".") + # sphinx-docfx-yaml supports up to sphinx version 1.5.5. + # https://github.com/docascode/sphinx-docfx-yaml/issues/97 + session.install("sphinx==1.5.5", "alabaster", "recommonmark", "sphinx-docfx-yaml") + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-T", # show full traceback on exception + "-N", # no colors + "-D", + ( + "extensions=sphinx.ext.autodoc," + "sphinx.ext.autosummary," + "docfx_yaml.extension," + "sphinx.ext.intersphinx," + "sphinx.ext.coverage," + "sphinx.ext.napoleon," + "sphinx.ext.todo," + "sphinx.ext.viewcode," + "recommonmark" + ), + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) diff --git a/scripts/decrypt-secrets.sh b/scripts/decrypt-secrets.sh new file mode 100755 index 0000000..21f6d2a --- /dev/null +++ b/scripts/decrypt-secrets.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Copyright 2015 Google Inc. All rights reserved. +# +# 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. + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ROOT=$( dirname "$DIR" ) + +# Work from the project root. +cd $ROOT + +# Prevent it from overriding files. +# We recommend that sample authors use their own service account files and cloud project. +# In that case, they are supposed to prepare these files by themselves. +if [[ -f "testing/test-env.sh" ]] || \ + [[ -f "testing/service-account.json" ]] || \ + [[ -f "testing/client-secrets.json" ]]; then + echo "One or more target files exist, aborting." + exit 1 +fi + +# Use SECRET_MANAGER_PROJECT if set, fallback to cloud-devrel-kokoro-resources. +PROJECT_ID="${SECRET_MANAGER_PROJECT:-cloud-devrel-kokoro-resources}" + +gcloud secrets versions access latest --secret="python-docs-samples-test-env" \ + --project="${PROJECT_ID}" \ + > testing/test-env.sh +gcloud secrets versions access latest \ + --secret="python-docs-samples-service-account" \ + --project="${PROJECT_ID}" \ + > testing/service-account.json +gcloud secrets versions access latest \ + --secret="python-docs-samples-client-secrets" \ + --project="${PROJECT_ID}" \ + > testing/client-secrets.json diff --git a/scripts/readme-gen/readme_gen.py b/scripts/readme-gen/readme_gen.py new file mode 100644 index 0000000..d309d6e --- /dev/null +++ b/scripts/readme-gen/readme_gen.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python + +# Copyright 2016 Google Inc +# +# 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. + +"""Generates READMEs using configuration defined in yaml.""" + +import argparse +import io +import os +import subprocess + +import jinja2 +import yaml + + +jinja_env = jinja2.Environment( + trim_blocks=True, + loader=jinja2.FileSystemLoader( + os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates')))) + +README_TMPL = jinja_env.get_template('README.tmpl.rst') + + +def get_help(file): + return subprocess.check_output(['python', file, '--help']).decode() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('source') + parser.add_argument('--destination', default='README.rst') + + args = parser.parse_args() + + source = os.path.abspath(args.source) + root = os.path.dirname(source) + destination = os.path.join(root, args.destination) + + jinja_env.globals['get_help'] = get_help + + with io.open(source, 'r') as f: + config = yaml.load(f) + + # This allows get_help to execute in the right directory. + os.chdir(root) + + output = README_TMPL.render(config) + + with io.open(destination, 'w') as f: + f.write(output) + + +if __name__ == '__main__': + main() diff --git a/scripts/readme-gen/templates/README.tmpl.rst b/scripts/readme-gen/templates/README.tmpl.rst new file mode 100644 index 0000000..4fd2397 --- /dev/null +++ b/scripts/readme-gen/templates/README.tmpl.rst @@ -0,0 +1,87 @@ +{# The following line is a lie. BUT! Once jinja2 is done with it, it will + become truth! #} +.. This file is automatically generated. Do not edit this file directly. + +{{product.name}} Python Samples +=============================================================================== + +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor={{folder}}/README.rst + + +This directory contains samples for {{product.name}}. {{product.description}} + +{{description}} + +.. _{{product.name}}: {{product.url}} + +{% if required_api_url %} +To run the sample, you need to enable the API at: {{required_api_url}} +{% endif %} + +{% if required_role %} +To run the sample, you need to have `{{required_role}}` role. +{% endif %} + +{{other_required_steps}} + +{% if setup %} +Setup +------------------------------------------------------------------------------- + +{% for section in setup %} + +{% include section + '.tmpl.rst' %} + +{% endfor %} +{% endif %} + +{% if samples %} +Samples +------------------------------------------------------------------------------- + +{% for sample in samples %} +{{sample.name}} ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +{% if not sample.hide_cloudshell_button %} +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor={{folder}}/{{sample.file}},{{folder}}/README.rst +{% endif %} + + +{{sample.description}} + +To run this sample: + +.. code-block:: bash + + $ python {{sample.file}} +{% if sample.show_help %} + + {{get_help(sample.file)|indent}} +{% endif %} + + +{% endfor %} +{% endif %} + +{% if cloud_client_library %} + +The client library +------------------------------------------------------------------------------- + +This sample uses the `Google Cloud Client Library for Python`_. +You can read the documentation for more details on API usage and use GitHub +to `browse the source`_ and `report issues`_. + +.. _Google Cloud Client Library for Python: + https://googlecloudplatform.github.io/google-cloud-python/ +.. _browse the source: + https://github.com/GoogleCloudPlatform/google-cloud-python +.. _report issues: + https://github.com/GoogleCloudPlatform/google-cloud-python/issues + +{% endif %} + +.. _Google Cloud SDK: https://cloud.google.com/sdk/ \ No newline at end of file diff --git a/scripts/readme-gen/templates/auth.tmpl.rst b/scripts/readme-gen/templates/auth.tmpl.rst new file mode 100644 index 0000000..1446b94 --- /dev/null +++ b/scripts/readme-gen/templates/auth.tmpl.rst @@ -0,0 +1,9 @@ +Authentication +++++++++++++++ + +This sample requires you to have authentication setup. Refer to the +`Authentication Getting Started Guide`_ for instructions on setting up +credentials for applications. + +.. _Authentication Getting Started Guide: + https://cloud.google.com/docs/authentication/getting-started diff --git a/scripts/readme-gen/templates/auth_api_key.tmpl.rst b/scripts/readme-gen/templates/auth_api_key.tmpl.rst new file mode 100644 index 0000000..11957ce --- /dev/null +++ b/scripts/readme-gen/templates/auth_api_key.tmpl.rst @@ -0,0 +1,14 @@ +Authentication +++++++++++++++ + +Authentication for this service is done via an `API Key`_. To obtain an API +Key: + +1. Open the `Cloud Platform Console`_ +2. Make sure that billing is enabled for your project. +3. From the **Credentials** page, create a new **API Key** or use an existing + one for your project. + +.. _API Key: + https://developers.google.com/api-client-library/python/guide/aaa_apikeys +.. _Cloud Console: https://console.cloud.google.com/project?_ diff --git a/scripts/readme-gen/templates/install_deps.tmpl.rst b/scripts/readme-gen/templates/install_deps.tmpl.rst new file mode 100644 index 0000000..a0406db --- /dev/null +++ b/scripts/readme-gen/templates/install_deps.tmpl.rst @@ -0,0 +1,29 @@ +Install Dependencies +++++++++++++++++++++ + +#. Clone python-docs-samples and change directory to the sample directory you want to use. + + .. code-block:: bash + + $ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git + +#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions. + + .. _Python Development Environment Setup Guide: + https://cloud.google.com/python/setup + +#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. + + .. code-block:: bash + + $ virtualenv env + $ source env/bin/activate + +#. Install the dependencies needed to run the samples. + + .. code-block:: bash + + $ pip install -r requirements.txt + +.. _pip: https://pip.pypa.io/ +.. _virtualenv: https://virtualenv.pypa.io/ diff --git a/scripts/readme-gen/templates/install_portaudio.tmpl.rst b/scripts/readme-gen/templates/install_portaudio.tmpl.rst new file mode 100644 index 0000000..5ea33d1 --- /dev/null +++ b/scripts/readme-gen/templates/install_portaudio.tmpl.rst @@ -0,0 +1,35 @@ +Install PortAudio ++++++++++++++++++ + +Install `PortAudio`_. This is required by the `PyAudio`_ library to stream +audio from your computer's microphone. PyAudio depends on PortAudio for cross-platform compatibility, and is installed differently depending on the +platform. + +* For Mac OS X, you can use `Homebrew`_:: + + brew install portaudio + + **Note**: if you encounter an error when running `pip install` that indicates + it can't find `portaudio.h`, try running `pip install` with the following + flags:: + + pip install --global-option='build_ext' \ + --global-option='-I/usr/local/include' \ + --global-option='-L/usr/local/lib' \ + pyaudio + +* For Debian / Ubuntu Linux:: + + apt-get install portaudio19-dev python-all-dev + +* Windows may work without having to install PortAudio explicitly (it will get + installed with PyAudio). + +For more details, see the `PyAudio installation`_ page. + + +.. _PyAudio: https://people.csail.mit.edu/hubert/pyaudio/ +.. _PortAudio: http://www.portaudio.com/ +.. _PyAudio installation: + https://people.csail.mit.edu/hubert/pyaudio/#downloads +.. _Homebrew: http://brew.sh diff --git a/synth.metadata b/synth.metadata index f06d462..3581571 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,30 +3,22 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-memcache.git", - "sha": "63d578c2938fcb8dc1442eca2d33129b5d3c237d" - } - }, - { - "git": { - "name": "googleapis", - "remote": "https://github.com/googleapis/googleapis.git", - "sha": "81226871ce438cdeec241dd81f33f796e37e1c03", - "internalRef": "315786558" + "remote": "git@github.com:googleapis/python-memcache", + "sha": "2b4aaed6308e23d2ee8756fdde8d1b27d23ff8d5" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "71b8a272549c06b5768d00fa48d3ae990e871bec" + "sha": "6b026e1443948dcfc0b9e3289c85e940eb70f694" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "71b8a272549c06b5768d00fa48d3ae990e871bec" + "sha": "6b026e1443948dcfc0b9e3289c85e940eb70f694" } } ], @@ -37,61 +29,8 @@ "apiName": "memcache", "apiVersion": "v1beta2", "language": "python", - "generator": "gapic-generator-python" + "generator": "bazel" } } - ], - "generatedFiles": [ - ".coveragerc", - ".flake8", - ".github/CONTRIBUTING.md", - ".github/ISSUE_TEMPLATE/bug_report.md", - ".github/ISSUE_TEMPLATE/feature_request.md", - ".github/ISSUE_TEMPLATE/support_request.md", - ".github/PULL_REQUEST_TEMPLATE.md", - ".github/release-please.yml", - ".gitignore", - ".kokoro/build.sh", - ".kokoro/continuous/common.cfg", - ".kokoro/continuous/continuous.cfg", - ".kokoro/docs/common.cfg", - ".kokoro/docs/docs.cfg", - ".kokoro/presubmit/common.cfg", - ".kokoro/presubmit/presubmit.cfg", - ".kokoro/publish-docs.sh", - ".kokoro/release.sh", - ".kokoro/release/common.cfg", - ".kokoro/release/release.cfg", - ".kokoro/trampoline.sh", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.rst", - "LICENSE", - "MANIFEST.in", - "docs/_static/custom.css", - "docs/_templates/layout.html", - "docs/conf.py", - "docs/multiprocessing.rst", - "google/cloud/memcache/__init__.py", - "google/cloud/memcache/py.typed", - "google/cloud/memcache_v1beta2/__init__.py", - "google/cloud/memcache_v1beta2/py.typed", - "google/cloud/memcache_v1beta2/services/__init__.py", - "google/cloud/memcache_v1beta2/services/cloud_memcache/__init__.py", - "google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py", - "google/cloud/memcache_v1beta2/services/cloud_memcache/client.py", - "google/cloud/memcache_v1beta2/services/cloud_memcache/pagers.py", - "google/cloud/memcache_v1beta2/services/cloud_memcache/transports/__init__.py", - "google/cloud/memcache_v1beta2/services/cloud_memcache/transports/base.py", - "google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc.py", - "google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc_asyncio.py", - "google/cloud/memcache_v1beta2/types/__init__.py", - "google/cloud/memcache_v1beta2/types/cloud_memcache.py", - "mypy.ini", - "noxfile.py", - "renovate.json", - "scripts/fixup_memcache_v1beta2_keywords.py", - "setup.cfg", - "tests/unit/gapic/memcache_v1beta2/__init__.py", - "tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py" ] } \ No newline at end of file diff --git a/synth.py b/synth.py index 869359a..3ccdf32 100644 --- a/synth.py +++ b/synth.py @@ -40,9 +40,9 @@ s.move(library, excludes=excludes) # Add extra linebreak after bulleted list to appease sphinx -# s.replace("google/**/client.py", """- Must be unique within the user project / location""", -# """- Must be unique within the user project / location\n""") -# s.replace("google/**/client.py", "- ``displayName``", "- ``displayName``\n") +s.replace("google/**/client.py", """- Must be unique within the user project / location""", +"""- Must be unique within the user project / location\n""") +s.replace("google/**/client.py", "- ``displayName``", "- ``displayName``\n") # ---------------------------------------------------------------------------- diff --git a/testing/.gitignore b/testing/.gitignore new file mode 100644 index 0000000..b05fbd6 --- /dev/null +++ b/testing/.gitignore @@ -0,0 +1,3 @@ +test-env.sh +service-account.json +client-secrets.json \ No newline at end of file diff --git a/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py b/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py index e2b472b..3050c18 100644 --- a/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py +++ b/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py @@ -92,19 +92,6 @@ def test__get_default_mtls_endpoint(): ) -def test_cloud_memcache_client_from_service_account_info(): - creds = credentials.AnonymousCredentials() - with mock.patch.object( - service_account.Credentials, "from_service_account_info" - ) as factory: - factory.return_value = creds - info = {"valid": True} - client = CloudMemcacheClient.from_service_account_info(info) - assert client.transport._credentials == creds - - assert client.transport._host == "memcache.googleapis.com:443" - - @pytest.mark.parametrize( "client_class", [CloudMemcacheClient, CloudMemcacheAsyncClient] ) @@ -394,7 +381,7 @@ def test_cloud_memcache_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"]) + options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options) @@ -462,7 +449,7 @@ def test_list_instances( transport: str = "grpc", request_type=cloud_memcache.ListInstancesRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -473,7 +460,7 @@ def test_list_instances( 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( - next_page_token="next_page_token_value", unreachable=["unreachable_value"] + next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) response = client.list_instances(request) @@ -502,7 +489,7 @@ async def test_list_instances_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.ListInstancesRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -541,7 +528,7 @@ async def test_list_instances_async_from_dict(): def test_list_instances_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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. @@ -561,12 +548,12 @@ def test_list_instances_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value") in kw["metadata"] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] @pytest.mark.asyncio async def test_list_instances_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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. @@ -588,11 +575,11 @@ async def test_list_instances_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value") in kw["metadata"] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] def test_list_instances_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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: @@ -601,7 +588,7 @@ def test_list_instances_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_instances(parent="parent_value") + client.list_instances(parent="parent_value",) # Establish that the underlying call was made with the expected # request object values. @@ -612,19 +599,19 @@ def test_list_instances_flattened(): def test_list_instances_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_instances( - cloud_memcache.ListInstancesRequest(), parent="parent_value" + cloud_memcache.ListInstancesRequest(), parent="parent_value", ) @pytest.mark.asyncio async def test_list_instances_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: @@ -636,7 +623,7 @@ async def test_list_instances_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_instances(parent="parent_value") + response = await client.list_instances(parent="parent_value",) # Establish that the underlying call was made with the expected # request object values. @@ -648,18 +635,18 @@ async def test_list_instances_flattened_async(): @pytest.mark.asyncio async def test_list_instances_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_instances( - cloud_memcache.ListInstancesRequest(), parent="parent_value" + cloud_memcache.ListInstancesRequest(), parent="parent_value", ) def test_list_instances_pager(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials) + client = CloudMemcacheClient(credentials=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: @@ -673,12 +660,12 @@ def test_list_instances_pager(): ], next_page_token="abc", ), - cloud_memcache.ListInstancesResponse(resources=[], next_page_token="def"), + cloud_memcache.ListInstancesResponse(resources=[], next_page_token="def",), cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance()], next_page_token="ghi" + resources=[cloud_memcache.Instance(),], next_page_token="ghi", ), cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance(), cloud_memcache.Instance()] + resources=[cloud_memcache.Instance(), cloud_memcache.Instance(),], ), RuntimeError, ) @@ -697,7 +684,7 @@ def test_list_instances_pager(): def test_list_instances_pages(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials) + client = CloudMemcacheClient(credentials=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: @@ -711,12 +698,12 @@ def test_list_instances_pages(): ], next_page_token="abc", ), - cloud_memcache.ListInstancesResponse(resources=[], next_page_token="def"), + cloud_memcache.ListInstancesResponse(resources=[], next_page_token="def",), cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance()], next_page_token="ghi" + resources=[cloud_memcache.Instance(),], next_page_token="ghi", ), cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance(), cloud_memcache.Instance()] + resources=[cloud_memcache.Instance(), cloud_memcache.Instance(),], ), RuntimeError, ) @@ -727,7 +714,7 @@ def test_list_instances_pages(): @pytest.mark.asyncio async def test_list_instances_async_pager(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials) + client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -743,16 +730,16 @@ async def test_list_instances_async_pager(): ], next_page_token="abc", ), - cloud_memcache.ListInstancesResponse(resources=[], next_page_token="def"), + cloud_memcache.ListInstancesResponse(resources=[], next_page_token="def",), cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance()], next_page_token="ghi" + resources=[cloud_memcache.Instance(),], next_page_token="ghi", ), cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance(), cloud_memcache.Instance()] + resources=[cloud_memcache.Instance(), cloud_memcache.Instance(),], ), RuntimeError, ) - async_pager = await client.list_instances(request={}) + async_pager = await client.list_instances(request={},) assert async_pager.next_page_token == "abc" responses = [] async for response in async_pager: @@ -764,7 +751,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=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -780,12 +767,12 @@ async def test_list_instances_async_pages(): ], next_page_token="abc", ), - cloud_memcache.ListInstancesResponse(resources=[], next_page_token="def"), + cloud_memcache.ListInstancesResponse(resources=[], next_page_token="def",), cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance()], next_page_token="ghi" + resources=[cloud_memcache.Instance(),], next_page_token="ghi", ), cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance(), cloud_memcache.Instance()] + resources=[cloud_memcache.Instance(), cloud_memcache.Instance(),], ), RuntimeError, ) @@ -800,7 +787,7 @@ def test_get_instance( transport: str = "grpc", request_type=cloud_memcache.GetInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -862,7 +849,7 @@ async def test_get_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.GetInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -922,7 +909,7 @@ async def test_get_instance_async_from_dict(): def test_get_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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. @@ -942,12 +929,12 @@ def test_get_instance_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value") in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] @pytest.mark.asyncio async def test_get_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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. @@ -969,11 +956,11 @@ async def test_get_instance_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value") in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] def test_get_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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: @@ -982,7 +969,7 @@ def test_get_instance_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_instance(name="name_value") + client.get_instance(name="name_value",) # Establish that the underlying call was made with the expected # request object values. @@ -993,17 +980,19 @@ def test_get_instance_flattened(): def test_get_instance_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_instance(cloud_memcache.GetInstanceRequest(), name="name_value") + client.get_instance( + cloud_memcache.GetInstanceRequest(), name="name_value", + ) @pytest.mark.asyncio async def test_get_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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: @@ -1015,7 +1004,7 @@ async def test_get_instance_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_instance(name="name_value") + response = await client.get_instance(name="name_value",) # Establish that the underlying call was made with the expected # request object values. @@ -1027,13 +1016,13 @@ async def test_get_instance_flattened_async(): @pytest.mark.asyncio async def test_get_instance_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_instance( - cloud_memcache.GetInstanceRequest(), name="name_value" + cloud_memcache.GetInstanceRequest(), name="name_value", ) @@ -1041,7 +1030,7 @@ def test_create_instance( transport: str = "grpc", request_type=cloud_memcache.CreateInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1074,7 +1063,7 @@ async def test_create_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.CreateInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1106,7 +1095,7 @@ async def test_create_instance_async_from_dict(): def test_create_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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. @@ -1126,12 +1115,12 @@ def test_create_instance_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value") in kw["metadata"] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] @pytest.mark.asyncio async def test_create_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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. @@ -1153,11 +1142,11 @@ async def test_create_instance_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value") in kw["metadata"] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] def test_create_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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: @@ -1185,7 +1174,7 @@ def test_create_instance_flattened(): def test_create_instance_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1200,7 +1189,7 @@ def test_create_instance_flattened_error(): @pytest.mark.asyncio async def test_create_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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: @@ -1232,7 +1221,7 @@ async def test_create_instance_flattened_async(): @pytest.mark.asyncio async def test_create_instance_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1249,7 +1238,7 @@ def test_update_instance( transport: str = "grpc", request_type=cloud_memcache.UpdateInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1282,7 +1271,7 @@ async def test_update_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.UpdateInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1314,7 +1303,7 @@ async def test_update_instance_async_from_dict(): def test_update_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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. @@ -1334,14 +1323,14 @@ def test_update_instance_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource.name=resource.name/value") in kw[ + assert ("x-goog-request-params", "resource.name=resource.name/value",) in kw[ "metadata" ] @pytest.mark.asyncio async def test_update_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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. @@ -1363,13 +1352,13 @@ async def test_update_instance_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource.name=resource.name/value") in kw[ + assert ("x-goog-request-params", "resource.name=resource.name/value",) in kw[ "metadata" ] def test_update_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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: @@ -1394,7 +1383,7 @@ def test_update_instance_flattened(): def test_update_instance_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1408,7 +1397,7 @@ def test_update_instance_flattened_error(): @pytest.mark.asyncio async def test_update_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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: @@ -1437,7 +1426,7 @@ async def test_update_instance_flattened_async(): @pytest.mark.asyncio async def test_update_instance_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1453,7 +1442,7 @@ def test_update_parameters( transport: str = "grpc", request_type=cloud_memcache.UpdateParametersRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1488,7 +1477,7 @@ async def test_update_parameters_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.UpdateParametersRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1522,7 +1511,7 @@ async def test_update_parameters_async_from_dict(): def test_update_parameters_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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. @@ -1544,12 +1533,12 @@ def test_update_parameters_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value") in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] @pytest.mark.asyncio async def test_update_parameters_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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. @@ -1573,11 +1562,11 @@ async def test_update_parameters_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value") in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] def test_update_parameters_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1607,7 +1596,7 @@ def test_update_parameters_flattened(): def test_update_parameters_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1622,7 +1611,7 @@ def test_update_parameters_flattened_error(): @pytest.mark.asyncio async def test_update_parameters_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1656,7 +1645,7 @@ async def test_update_parameters_flattened_async(): @pytest.mark.asyncio async def test_update_parameters_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1673,7 +1662,7 @@ def test_delete_instance( transport: str = "grpc", request_type=cloud_memcache.DeleteInstanceRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1706,7 +1695,7 @@ async def test_delete_instance_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.DeleteInstanceRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1738,7 +1727,7 @@ async def test_delete_instance_async_from_dict(): def test_delete_instance_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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. @@ -1758,12 +1747,12 @@ def test_delete_instance_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value") in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] @pytest.mark.asyncio async def test_delete_instance_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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. @@ -1785,11 +1774,11 @@ async def test_delete_instance_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value") in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] def test_delete_instance_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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: @@ -1798,7 +1787,7 @@ def test_delete_instance_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_instance(name="name_value") + client.delete_instance(name="name_value",) # Establish that the underlying call was made with the expected # request object values. @@ -1809,19 +1798,19 @@ def test_delete_instance_flattened(): def test_delete_instance_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_instance( - cloud_memcache.DeleteInstanceRequest(), name="name_value" + cloud_memcache.DeleteInstanceRequest(), name="name_value", ) @pytest.mark.asyncio async def test_delete_instance_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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: @@ -1833,7 +1822,7 @@ async def test_delete_instance_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_instance(name="name_value") + response = await client.delete_instance(name="name_value",) # Establish that the underlying call was made with the expected # request object values. @@ -1845,13 +1834,13 @@ async def test_delete_instance_flattened_async(): @pytest.mark.asyncio async def test_delete_instance_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_instance( - cloud_memcache.DeleteInstanceRequest(), name="name_value" + cloud_memcache.DeleteInstanceRequest(), name="name_value", ) @@ -1859,7 +1848,7 @@ def test_apply_parameters( transport: str = "grpc", request_type=cloud_memcache.ApplyParametersRequest ): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1892,7 +1881,7 @@ async def test_apply_parameters_async( transport: str = "grpc_asyncio", request_type=cloud_memcache.ApplyParametersRequest ): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1924,7 +1913,7 @@ async def test_apply_parameters_async_from_dict(): def test_apply_parameters_field_headers(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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. @@ -1944,12 +1933,12 @@ def test_apply_parameters_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value") in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] @pytest.mark.asyncio async def test_apply_parameters_field_headers_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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. @@ -1971,11 +1960,11 @@ async def test_apply_parameters_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value") in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] def test_apply_parameters_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=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: @@ -1985,7 +1974,7 @@ def test_apply_parameters_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.apply_parameters( - name="name_value", node_ids=["node_ids_value"], apply_all=True + name="name_value", node_ids=["node_ids_value"], apply_all=True, ) # Establish that the underlying call was made with the expected @@ -2001,7 +1990,7 @@ def test_apply_parameters_flattened(): def test_apply_parameters_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2016,7 +2005,7 @@ def test_apply_parameters_flattened_error(): @pytest.mark.asyncio async def test_apply_parameters_flattened_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=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: @@ -2029,7 +2018,7 @@ async def test_apply_parameters_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.apply_parameters( - name="name_value", node_ids=["node_ids_value"], apply_all=True + name="name_value", node_ids=["node_ids_value"], apply_all=True, ) # Establish that the underlying call was made with the expected @@ -2046,7 +2035,7 @@ async def test_apply_parameters_flattened_async(): @pytest.mark.asyncio async def test_apply_parameters_flattened_error_async(): - client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials()) + client = CloudMemcacheAsyncClient(credentials=credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2062,36 +2051,37 @@ 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=credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport + credentials=credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials() + credentials=credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudMemcacheClient( - client_options={"credentials_file": "credentials.json"}, transport=transport + client_options={"credentials_file": "credentials.json"}, + transport=transport, ) # It is an error to provide scopes and a transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials() + credentials=credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CloudMemcacheClient( - client_options={"scopes": ["1", "2"]}, transport=transport + client_options={"scopes": ["1", "2"]}, transport=transport, ) def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials() + credentials=credentials.AnonymousCredentials(), ) client = CloudMemcacheClient(transport=transport) assert client.transport is transport @@ -2100,13 +2090,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=credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.CloudMemcacheGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials() + credentials=credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2129,8 +2119,8 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) - assert isinstance(client.transport, transports.CloudMemcacheGrpcTransport) + client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials(),) + assert isinstance(client.transport, transports.CloudMemcacheGrpcTransport,) def test_cloud_memcache_base_transport_error(): @@ -2149,7 +2139,7 @@ def test_cloud_memcache_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CloudMemcacheTransport( - credentials=credentials.AnonymousCredentials() + credentials=credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2183,7 +2173,7 @@ def test_cloud_memcache_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (credentials.AnonymousCredentials(), None) transport = transports.CloudMemcacheTransport( - credentials_file="credentials.json", quota_project_id="octopus" + credentials_file="credentials.json", quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -2253,7 +2243,7 @@ def test_cloud_memcache_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.CloudMemcacheGrpcTransport( - host="squid.clam.whelk", channel=channel + host="squid.clam.whelk", channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2265,7 +2255,7 @@ def test_cloud_memcache_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.CloudMemcacheGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel + host="squid.clam.whelk", channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2368,12 +2358,12 @@ 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=credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient) + assert isinstance(transport.operations_client, operations_v1.OperationsClient,) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2381,12 +2371,12 @@ def test_cloud_memcache_grpc_lro_client(): def test_cloud_memcache_grpc_lro_async_client(): client = CloudMemcacheAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio" + credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient) + assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2398,14 +2388,18 @@ def test_instance_path(): instance = "whelk" expected = "projects/{project}/locations/{location}/instances/{instance}".format( - project=project, location=location, instance=instance + project=project, location=location, instance=instance, ) actual = CloudMemcacheClient.instance_path(project, location, instance) assert expected == actual def test_parse_instance_path(): - expected = {"project": "octopus", "location": "oyster", "instance": "nudibranch"} + expected = { + "project": "octopus", + "location": "oyster", + "instance": "nudibranch", + } path = CloudMemcacheClient.instance_path(**expected) # Check that the path construction is reversible. @@ -2417,14 +2411,16 @@ def test_common_billing_account_path(): billing_account = "cuttlefish" expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account + billing_account=billing_account, ) actual = CloudMemcacheClient.common_billing_account_path(billing_account) assert expected == actual def test_parse_common_billing_account_path(): - expected = {"billing_account": "mussel"} + expected = { + "billing_account": "mussel", + } path = CloudMemcacheClient.common_billing_account_path(**expected) # Check that the path construction is reversible. @@ -2435,13 +2431,15 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder) + expected = "folders/{folder}".format(folder=folder,) actual = CloudMemcacheClient.common_folder_path(folder) assert expected == actual def test_parse_common_folder_path(): - expected = {"folder": "nautilus"} + expected = { + "folder": "nautilus", + } path = CloudMemcacheClient.common_folder_path(**expected) # Check that the path construction is reversible. @@ -2452,13 +2450,15 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization) + expected = "organizations/{organization}".format(organization=organization,) actual = CloudMemcacheClient.common_organization_path(organization) assert expected == actual def test_parse_common_organization_path(): - expected = {"organization": "abalone"} + expected = { + "organization": "abalone", + } path = CloudMemcacheClient.common_organization_path(**expected) # Check that the path construction is reversible. @@ -2469,13 +2469,15 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project) + expected = "projects/{project}".format(project=project,) actual = CloudMemcacheClient.common_project_path(project) assert expected == actual def test_parse_common_project_path(): - expected = {"project": "clam"} + expected = { + "project": "clam", + } path = CloudMemcacheClient.common_project_path(**expected) # Check that the path construction is reversible. @@ -2488,14 +2490,17 @@ def test_common_location_path(): location = "octopus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location + project=project, location=location, ) actual = CloudMemcacheClient.common_location_path(project, location) assert expected == actual def test_parse_common_location_path(): - expected = {"project": "oyster", "location": "nudibranch"} + expected = { + "project": "oyster", + "location": "nudibranch", + } path = CloudMemcacheClient.common_location_path(**expected) # Check that the path construction is reversible. @@ -2510,7 +2515,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.CloudMemcacheTransport, "_prep_wrapped_messages" ) as prep: client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info + credentials=credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2519,6 +2524,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=credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) diff --git a/tests/unit/memcache_v1beta2/test_cloud_memcache.py b/tests/unit/memcache_v1beta2/test_cloud_memcache.py deleted file mode 100644 index b7e87f4..0000000 --- a/tests/unit/memcache_v1beta2/test_cloud_memcache.py +++ /dev/null @@ -1,929 +0,0 @@ -# -*- 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. -# - -from unittest import mock - -import grpc -import math -import pytest - -from google import auth -from google.api_core import client_options -from google.api_core import future -from google.api_core import grpc_helpers -from google.api_core import operations_v1 -from google.auth import credentials -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.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 - - -def client_cert_source_callback(): - return b"cert bytes", b"key bytes" - - -def test__get_default_mtls_endpoint(): - api_endpoint = "example.googleapis.com" - api_mtls_endpoint = "example.mtls.googleapis.com" - sandbox_endpoint = "example.sandbox.googleapis.com" - sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" - non_googleapi = "api.example.com" - - assert CloudMemcacheClient._get_default_mtls_endpoint(None) is None - assert ( - CloudMemcacheClient._get_default_mtls_endpoint(api_endpoint) - == api_mtls_endpoint - ) - assert ( - CloudMemcacheClient._get_default_mtls_endpoint(api_mtls_endpoint) - == api_mtls_endpoint - ) - assert ( - CloudMemcacheClient._get_default_mtls_endpoint(sandbox_endpoint) - == sandbox_mtls_endpoint - ) - assert ( - CloudMemcacheClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) - == sandbox_mtls_endpoint - ) - assert ( - CloudMemcacheClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - ) - - -def test_cloud_memcache_client_from_service_account_file(): - creds = credentials.AnonymousCredentials() - with mock.patch.object( - service_account.Credentials, "from_service_account_file" - ) as factory: - factory.return_value = creds - client = CloudMemcacheClient.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds - - client = CloudMemcacheClient.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds - - assert client._transport._host == "memcache.googleapis.com:443" - - -def test_cloud_memcache_client_client_options(): - # Check that if channel is provided we won't create a new one. - with mock.patch( - "google.cloud.memcache_v1beta2.services.cloud_memcache.CloudMemcacheClient.get_transport_class" - ) as gtc: - transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials() - ) - client = CloudMemcacheClient(transport=transport) - gtc.assert_not_called() - - # Check mTLS is not triggered with empty client options. - options = client_options.ClientOptions() - with mock.patch( - "google.cloud.memcache_v1beta2.services.cloud_memcache.CloudMemcacheClient.get_transport_class" - ) as gtc: - transport = gtc.return_value = mock.MagicMock() - client = CloudMemcacheClient(client_options=options) - transport.assert_called_once_with( - credentials=None, host=client.DEFAULT_ENDPOINT - ) - - # Check mTLS is not triggered if api_endpoint is provided but - # client_cert_source is None. - options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch( - "google.cloud.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheGrpcTransport.__init__" - ) as grpc_transport: - grpc_transport.return_value = None - client = CloudMemcacheClient(client_options=options) - grpc_transport.assert_called_once_with( - api_mtls_endpoint=None, - client_cert_source=None, - credentials=None, - host="squid.clam.whelk", - ) - - # Check mTLS is triggered if client_cert_source is provided. - options = client_options.ClientOptions( - client_cert_source=client_cert_source_callback - ) - with mock.patch( - "google.cloud.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheGrpcTransport.__init__" - ) as grpc_transport: - grpc_transport.return_value = None - client = CloudMemcacheClient(client_options=options) - grpc_transport.assert_called_once_with( - api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, - client_cert_source=client_cert_source_callback, - credentials=None, - host=client.DEFAULT_ENDPOINT, - ) - - # Check mTLS is triggered if api_endpoint and client_cert_source are provided. - options = client_options.ClientOptions( - api_endpoint="squid.clam.whelk", client_cert_source=client_cert_source_callback - ) - with mock.patch( - "google.cloud.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheGrpcTransport.__init__" - ) as grpc_transport: - grpc_transport.return_value = None - client = CloudMemcacheClient(client_options=options) - grpc_transport.assert_called_once_with( - api_mtls_endpoint="squid.clam.whelk", - client_cert_source=client_cert_source_callback, - credentials=None, - host="squid.clam.whelk", - ) - - -def test_cloud_memcache_client_client_options_from_dict(): - with mock.patch( - "google.cloud.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheGrpcTransport.__init__" - ) as grpc_transport: - grpc_transport.return_value = None - client = CloudMemcacheClient( - client_options={"api_endpoint": "squid.clam.whelk"} - ) - grpc_transport.assert_called_once_with( - api_mtls_endpoint=None, - client_cert_source=None, - credentials=None, - host="squid.clam.whelk", - ) - - -def test_list_instances(transport: str = "grpc"): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = cloud_memcache.ListInstancesRequest() - - # 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( - 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] == request - - # 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"] - - -def test_list_instances_field_headers(): - client = CloudMemcacheClient(credentials=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(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. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value") in kw["metadata"] - - -def test_list_instances_flattened(): - client = CloudMemcacheClient(credentials=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. - response = client.list_instances(parent="parent_value") - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - - -def test_list_instances_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_instances( - cloud_memcache.ListInstancesRequest(), parent="parent_value" - ) - - -def test_list_instances_pager(): - client = CloudMemcacheClient(credentials=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: - # Set the response to a series of pages. - call.side_effect = ( - cloud_memcache.ListInstancesResponse( - resources=[ - cloud_memcache.Instance(), - cloud_memcache.Instance(), - cloud_memcache.Instance(), - ], - next_page_token="abc", - ), - cloud_memcache.ListInstancesResponse(resources=[], next_page_token="def"), - cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance()], next_page_token="ghi" - ), - cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance(), cloud_memcache.Instance()] - ), - RuntimeError, - ) - results = [i for i in client.list_instances(request={})] - assert len(results) == 6 - assert all(isinstance(i, cloud_memcache.Instance) for i in results) - - -def test_list_instances_pages(): - client = CloudMemcacheClient(credentials=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: - # Set the response to a series of pages. - call.side_effect = ( - cloud_memcache.ListInstancesResponse( - resources=[ - cloud_memcache.Instance(), - cloud_memcache.Instance(), - cloud_memcache.Instance(), - ], - next_page_token="abc", - ), - cloud_memcache.ListInstancesResponse(resources=[], next_page_token="def"), - cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance()], next_page_token="ghi" - ), - cloud_memcache.ListInstancesResponse( - resources=[cloud_memcache.Instance(), cloud_memcache.Instance()] - ), - RuntimeError, - ) - pages = list(client.list_instances(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token - - -def test_get_instance(transport: str = "grpc"): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = cloud_memcache.GetInstanceRequest() - - # 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( - name="name_value", - display_name="display_name_value", - authorized_network="authorized_network_value", - zones=["zones_value"], - node_count=1070, - memcache_version=cloud_memcache.MemcacheVersion.MEMCACHE_1_5, - state=cloud_memcache.Instance.State.CREATING, - 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] == request - - # 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" - - -def test_get_instance_field_headers(): - client = CloudMemcacheClient(credentials=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(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. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value") in kw["metadata"] - - -def test_get_instance_flattened(): - client = CloudMemcacheClient(credentials=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. - response = client.get_instance(name="name_value") - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - - -def test_get_instance_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_instance(cloud_memcache.GetInstanceRequest(), name="name_value") - - -def test_create_instance(transport: str = "grpc"): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = cloud_memcache.CreateInstanceRequest() - - # 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/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] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_create_instance_flattened(): - client = CloudMemcacheClient(credentials=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. - response = client.create_instance( - parent="parent_value", - instance_id="instance_id_value", - resource=cloud_memcache.Instance(name="name_value"), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - 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()) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_instance( - cloud_memcache.CreateInstanceRequest(), - parent="parent_value", - instance_id="instance_id_value", - resource=cloud_memcache.Instance(name="name_value"), - ) - - -def test_update_instance(transport: str = "grpc"): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = cloud_memcache.UpdateInstanceRequest() - - # 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/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] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_update_instance_flattened(): - client = CloudMemcacheClient(credentials=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. - response = client.update_instance( - update_mask=field_mask.FieldMask(paths=["paths_value"]), - resource=cloud_memcache.Instance(name="name_value"), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].update_mask == field_mask.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()) - - # 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"]), - resource=cloud_memcache.Instance(name="name_value"), - ) - - -def test_update_parameters(transport: str = "grpc"): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = cloud_memcache.UpdateParametersRequest() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.update_parameters), "__call__" - ) 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] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_update_parameters_flattened(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.update_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. - response = client.update_parameters( - name="name_value", - update_mask=field_mask.FieldMask(paths=["paths_value"]), - parameters=cloud_memcache.MemcacheParameters(id="id_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].name == "name_value" - assert args[0].update_mask == field_mask.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()) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_parameters( - cloud_memcache.UpdateParametersRequest(), - name="name_value", - update_mask=field_mask.FieldMask(paths=["paths_value"]), - parameters=cloud_memcache.MemcacheParameters(id="id_value"), - ) - - -def test_delete_instance(transport: str = "grpc"): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = cloud_memcache.DeleteInstanceRequest() - - # 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/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] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_delete_instance_flattened(): - client = CloudMemcacheClient(credentials=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. - response = client.delete_instance(name="name_value") - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - - -def test_delete_instance_flattened_error(): - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_instance( - cloud_memcache.DeleteInstanceRequest(), name="name_value" - ) - - -def test_apply_parameters(transport: str = "grpc"): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = cloud_memcache.ApplyParametersRequest() - - # 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/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] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_apply_parameters_flattened(): - client = CloudMemcacheClient(credentials=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. - response = client.apply_parameters( - name="name_value", node_ids=["node_ids_value"], apply_all=True - ) - - # 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].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()) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.apply_parameters( - cloud_memcache.ApplyParametersRequest(), - name="name_value", - node_ids=["node_ids_value"], - apply_all=True, - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials() - ) - with pytest.raises(ValueError): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport=transport - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.CloudMemcacheGrpcTransport( - credentials=credentials.AnonymousCredentials() - ) - client = CloudMemcacheClient(transport=transport) - assert client._transport is transport - - -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) - assert isinstance(client._transport, transports.CloudMemcacheGrpcTransport) - - -def test_cloud_memcache_base_transport(): - # Instantiate the base transport. - transport = transports.CloudMemcacheTransport( - credentials=credentials.AnonymousCredentials() - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - "list_instances", - "get_instance", - "create_instance", - "update_instance", - "update_parameters", - "delete_instance", - "apply_parameters", - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client - - -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) - CloudMemcacheClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",) - ) - - -def test_cloud_memcache_host_no_port(): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="memcache.googleapis.com" - ), - transport="grpc", - ) - assert client._transport._host == "memcache.googleapis.com:443" - - -def test_cloud_memcache_host_with_port(): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="memcache.googleapis.com:8000" - ), - transport="grpc", - ) - assert client._transport._host == "memcache.googleapis.com:8000" - - -def test_cloud_memcache_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") - - # Check that if channel is provided, mtls endpoint and client_cert_source - # won't be used. - callback = mock.MagicMock() - transport = transports.CloudMemcacheGrpcTransport( - host="squid.clam.whelk", - channel=channel, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=callback, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert not callback.called - - -@mock.patch("grpc.ssl_channel_credentials", autospec=True) -@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) -def test_cloud_memcache_grpc_transport_channel_mtls_with_client_cert_source( - grpc_create_channel, grpc_ssl_channel_cred -): - # Check that if channel is None, but api_mtls_endpoint and client_cert_source - # are provided, then a mTLS channel will be created. - mock_cred = mock.Mock() - - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - transport = transports.CloudMemcacheGrpcTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - ssl_credentials=mock_ssl_cred, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ) - assert transport.grpc_channel == mock_grpc_channel - - -@pytest.mark.parametrize( - "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] -) -@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) -def test_cloud_memcache_grpc_transport_channel_mtls_with_adc( - grpc_create_channel, api_mtls_endpoint -): - # Check that if channel and client_cert_source are None, but api_mtls_endpoint - # is provided, then a mTLS channel will be created with SSL ADC. - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - # Mock google.auth.transport.grpc.SslCredentials class. - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - mock_cred = mock.Mock() - transport = transports.CloudMemcacheGrpcTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint=api_mtls_endpoint, - client_cert_source=None, - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - ssl_credentials=mock_ssl_cred, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ) - assert transport.grpc_channel == mock_grpc_channel - - -def test_cloud_memcache_grpc_lro_client(): - client = CloudMemcacheClient( - credentials=credentials.AnonymousCredentials(), transport="grpc" - ) - transport = client._transport - - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_instance_path(): - project = "squid" - location = "clam" - instance = "whelk" - - expected = "projects/{project}/locations/{location}/instances/{instance}".format( - project=project, location=location, instance=instance - ) - actual = CloudMemcacheClient.instance_path(project, location, instance) - assert expected == actual - - -def test_parse_instance_path(): - expected = {"project": "octopus", "location": "oyster", "instance": "nudibranch"} - path = CloudMemcacheClient.instance_path(**expected) - - # Check that the path construction is reversible. - actual = CloudMemcacheClient.parse_instance_path(path) - assert expected == actual From 4b5da0c92c03e5218efc571d62c27d5494bb04a2 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Mon, 28 Dec 2020 17:48:46 +0000 Subject: [PATCH 5/5] fix: fix docs in async client --- .../memcache_v1beta2/services/cloud_memcache/async_client.py | 2 ++ synth.metadata | 2 +- synth.py | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) 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 886e32c..9373a06 100644 --- a/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py +++ b/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py @@ -356,6 +356,7 @@ async def create_instance( - Must be between 1-40 characters. - Must end with a number or a letter. - Must be unique within the user project / location + This corresponds to the ``instance_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -450,6 +451,7 @@ async def update_instance( Required. Mask of fields to update. - ``displayName`` + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. diff --git a/synth.metadata b/synth.metadata index 3581571..b83959d 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "git@github.com:googleapis/python-memcache", - "sha": "2b4aaed6308e23d2ee8756fdde8d1b27d23ff8d5" + "sha": "b068bfca843c0d792bb2b79f5b6b28fcc80ae7c8" } }, { diff --git a/synth.py b/synth.py index 3ccdf32..4b2ffa1 100644 --- a/synth.py +++ b/synth.py @@ -40,9 +40,9 @@ s.move(library, excludes=excludes) # Add extra linebreak after bulleted list to appease sphinx -s.replace("google/**/client.py", """- Must be unique within the user project / location""", +s.replace("google/**/*client.py", """- Must be unique within the user project / location""", """- Must be unique within the user project / location\n""") -s.replace("google/**/client.py", "- ``displayName``", "- ``displayName``\n") +s.replace("google/**/*client.py", "- ``displayName``", "- ``displayName``\n") # ----------------------------------------------------------------------------