From 97de272a8839dc96cadcd589c9d2ec93496a86c2 Mon Sep 17 00:00:00 2001 From: Christopher Wilcox Date: Wed, 28 Nov 2018 14:28:56 -0800 Subject: [PATCH] Run Black on Generated libraries (#6666) * blacken appveyor * Blacken all gen'd libraries not under PR --- packages/google-cloud-redis/docs/conf.py | 161 +++++------ .../google-cloud-redis/google/__init__.py | 2 + .../google/cloud/__init__.py | 2 + .../google-cloud-redis/google/cloud/redis.py | 6 +- .../google/cloud/redis_v1/__init__.py | 6 +- .../redis_v1/gapic/cloud_redis_client.py | 254 +++++++++--------- .../gapic/cloud_redis_client_config.py | 18 +- .../google/cloud/redis_v1/gapic/enums.py | 2 + .../transports/cloud_redis_grpc_transport.py | 44 ++- .../google/cloud/redis_v1/types.py | 6 +- .../google/cloud/redis_v1beta1/__init__.py | 6 +- .../redis_v1beta1/gapic/cloud_redis_client.py | 254 +++++++++--------- .../gapic/cloud_redis_client_config.py | 18 +- .../google/cloud/redis_v1beta1/gapic/enums.py | 2 + .../transports/cloud_redis_grpc_transport.py | 44 ++- .../google/cloud/redis_v1beta1/types.py | 6 +- .../gapic/v1/test_cloud_redis_client_v1.py | 241 ++++++++--------- .../test_cloud_redis_client_v1beta1.py | 241 ++++++++--------- 18 files changed, 656 insertions(+), 657 deletions(-) diff --git a/packages/google-cloud-redis/docs/conf.py b/packages/google-cloud-redis/docs/conf.py index bbd8a724003e..40161d814d84 100644 --- a/packages/google-cloud-redis/docs/conf.py +++ b/packages/google-cloud-redis/docs/conf.py @@ -18,50 +18,50 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('..')) +sys.path.insert(0, os.path.abspath("..")) -__version__ = '0.1.0' +__version__ = "0.1.0" # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.autosummary', - 'sphinx.ext.intersphinx', - 'sphinx.ext.coverage', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.napoleon", + "sphinx.ext.viewcode", ] # autodoc/autosummary flags -autoclass_content = 'both' -autodoc_default_flags = ['members'] +autoclass_content = "both" +autodoc_default_flags = ["members"] autosummary_generate = True # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'google-cloud-redis' -copyright = u'2017, Google' -author = u'Google APIs' +project = u"google-cloud-redis" +copyright = u"2017, Google" +author = u"Google APIs" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -70,7 +70,7 @@ # The full version, including alpha/beta/rc tags. release = __version__ # The short X.Y version. -version = '.'.join(release.split('.')[0:2]) +version = ".".join(release.split(".")[0:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -81,37 +81,37 @@ # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # 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"] # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = True @@ -120,31 +120,31 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, @@ -154,78 +154,75 @@ # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Language to be used for generating the HTML full-text search index. # Sphinx supports the following languages: # 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' # 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -#html_search_language = 'en' +# html_search_language = 'en' # A dictionary with options for the search language support, empty by default. # Now only 'ja' uses this config value -#html_search_options = {'type': 'default'} +# html_search_options = {'type': 'default'} # The name of a javascript file (relative to the configuration directory) that # implements a search results scorer. If empty, the default will be used. -#html_search_scorer = 'scorer.js' +# html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. -htmlhelp_basename = 'google-cloud-redis-doc' +htmlhelp_basename = "google-cloud-redis-doc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. #'preamble': '', - # Latex figure (float) alignment #'figure_align': 'htbp', } @@ -234,39 +231,45 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'google-cloud-redis.tex', u'google-cloud-redis Documentation', - author, 'manual'), + ( + master_doc, + "google-cloud-redis.tex", + u"google-cloud-redis Documentation", + author, + "manual", + ) ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [(master_doc, 'google-cloud-redis', - u'google-cloud-redis Documentation', [author], 1)] +man_pages = [ + (master_doc, "google-cloud-redis", u"google-cloud-redis Documentation", [author], 1) +] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -274,27 +277,33 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'google-cloud-redis', u'google-cloud-redis Documentation', - author, 'google-cloud-redis', - 'GAPIC library for the {metadata.shortName} v1beta1 service', 'APIs'), + ( + master_doc, + "google-cloud-redis", + u"google-cloud-redis Documentation", + author, + "google-cloud-redis", + "GAPIC library for the {metadata.shortName} v1beta1 service", + "APIs", + ) ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { - 'python': ('http://python.readthedocs.org/en/latest/', None), - 'gax': ('https://gax-python.readthedocs.org/en/latest/', None), + "python": ("http://python.readthedocs.org/en/latest/", None), + "gax": ("https://gax-python.readthedocs.org/en/latest/", None), } # Napoleon settings diff --git a/packages/google-cloud-redis/google/__init__.py b/packages/google-cloud-redis/google/__init__.py index f65701dd143f..7aa71bb4e2f1 100644 --- a/packages/google-cloud-redis/google/__init__.py +++ b/packages/google-cloud-redis/google/__init__.py @@ -16,7 +16,9 @@ try: import pkg_resources + pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/packages/google-cloud-redis/google/cloud/__init__.py b/packages/google-cloud-redis/google/cloud/__init__.py index f65701dd143f..7aa71bb4e2f1 100644 --- a/packages/google-cloud-redis/google/cloud/__init__.py +++ b/packages/google-cloud-redis/google/cloud/__init__.py @@ -16,7 +16,9 @@ try: import pkg_resources + pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/packages/google-cloud-redis/google/cloud/redis.py b/packages/google-cloud-redis/google/cloud/redis.py index 8d88b66280a3..532e43b9a9e3 100644 --- a/packages/google-cloud-redis/google/cloud/redis.py +++ b/packages/google-cloud-redis/google/cloud/redis.py @@ -20,8 +20,4 @@ from google.cloud.redis_v1 import enums from google.cloud.redis_v1 import types -__all__ = ( - 'enums', - 'types', - 'CloudRedisClient', -) +__all__ = ("enums", "types", "CloudRedisClient") diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/__init__.py b/packages/google-cloud-redis/google/cloud/redis_v1/__init__.py index 9be2b9e1ff0f..5aae905e6568 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/__init__.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/__init__.py @@ -26,8 +26,4 @@ class CloudRedisClient(cloud_redis_client.CloudRedisClient): enums = enums -__all__ = ( - 'enums', - 'types', - 'CloudRedisClient', -) +__all__ = ("enums", "types", "CloudRedisClient") diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/gapic/cloud_redis_client.py b/packages/google-cloud-redis/google/cloud/redis_v1/gapic/cloud_redis_client.py index 325ad9f59ac6..6992ebe08ad5 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/gapic/cloud_redis_client.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/gapic/cloud_redis_client.py @@ -39,8 +39,7 @@ from google.protobuf import empty_pb2 from google.protobuf import field_mask_pb2 -_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution( - 'google-cloud-redis', ).version +_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution("google-cloud-redis").version class CloudRedisClient(object): @@ -63,12 +62,12 @@ class CloudRedisClient(object): ``projects/redpepper-1290/locations/us-central1/instances/my-redis`` """ - SERVICE_ADDRESS = 'redis.googleapis.com:443' + SERVICE_ADDRESS = "redis.googleapis.com:443" """The default address of the service.""" # The name of the interface for this client. This is the key used to # find the method configuration in the client_config dictionary. - _INTERFACE_NAME = 'google.cloud.redis.v1.CloudRedis' + _INTERFACE_NAME = "google.cloud.redis.v1.CloudRedis" @classmethod def from_service_account_file(cls, filename, *args, **kwargs): @@ -84,9 +83,8 @@ def from_service_account_file(cls, filename, *args, **kwargs): Returns: CloudRedisClient: The constructed client. """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs['credentials'] = credentials + credentials = service_account.Credentials.from_service_account_file(filename) + kwargs["credentials"] = credentials return cls(*args, **kwargs) from_service_account_json = from_service_account_file @@ -95,7 +93,7 @@ def from_service_account_file(cls, filename, *args, **kwargs): def location_path(cls, project, location): """Return a fully-qualified location string.""" return google.api_core.path_template.expand( - 'projects/{project}/locations/{location}', + "projects/{project}/locations/{location}", project=project, location=location, ) @@ -104,18 +102,20 @@ def location_path(cls, project, location): def instance_path(cls, project, location, instance): """Return a fully-qualified instance string.""" return google.api_core.path_template.expand( - 'projects/{project}/locations/{location}/instances/{instance}', + "projects/{project}/locations/{location}/instances/{instance}", project=project, location=location, instance=instance, ) - def __init__(self, - transport=None, - channel=None, - credentials=None, - client_config=None, - client_info=None): + def __init__( + self, + transport=None, + channel=None, + credentials=None, + client_config=None, + client_info=None, + ): """Constructor. Args: @@ -149,18 +149,19 @@ def __init__(self, # Raise deprecation warnings for things we want to go away. if client_config is not None: warnings.warn( - 'The `client_config` argument is deprecated.', + "The `client_config` argument is deprecated.", PendingDeprecationWarning, - stacklevel=2) + stacklevel=2, + ) else: client_config = cloud_redis_client_config.config if channel: warnings.warn( - 'The `channel` argument is deprecated; use ' - '`transport` instead.', + "The `channel` argument is deprecated; use " "`transport` instead.", PendingDeprecationWarning, - stacklevel=2) + stacklevel=2, + ) # Instantiate the transport. # The transport is responsible for handling serialization and @@ -169,25 +170,24 @@ def __init__(self, if callable(transport): self.transport = transport( credentials=credentials, - default_class=cloud_redis_grpc_transport. - CloudRedisGrpcTransport, + default_class=cloud_redis_grpc_transport.CloudRedisGrpcTransport, ) else: if credentials: raise ValueError( - 'Received both a transport instance and ' - 'credentials; these are mutually exclusive.') + "Received both a transport instance and " + "credentials; these are mutually exclusive." + ) self.transport = transport else: self.transport = cloud_redis_grpc_transport.CloudRedisGrpcTransport( - address=self.SERVICE_ADDRESS, - channel=channel, - credentials=credentials, + address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials ) if client_info is None: client_info = google.api_core.gapic_v1.client_info.ClientInfo( - gapic_version=_GAPIC_LIBRARY_VERSION, ) + gapic_version=_GAPIC_LIBRARY_VERSION + ) else: client_info.gapic_version = _GAPIC_LIBRARY_VERSION self._client_info = client_info @@ -197,7 +197,8 @@ def __init__(self, # (Ordinarily, these are the defaults specified in the `*_config.py` # file next to this one.) self._method_configs = google.api_core.gapic_v1.config.parse_method_configs( - client_config['interfaces'][self._INTERFACE_NAME], ) + client_config["interfaces"][self._INTERFACE_NAME] + ) # Save a dictionary of cached API call functions. # These are the actual callables which invoke the proper @@ -206,12 +207,14 @@ def __init__(self, self._inner_api_calls = {} # Service calls - def list_instances(self, - parent, - page_size=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def list_instances( + self, + parent, + page_size=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Lists all Redis instances owned by a project in either the specified location (region) or all locations. @@ -275,39 +278,41 @@ def list_instances(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'list_instances' not in self._inner_api_calls: + if "list_instances" not in self._inner_api_calls: self._inner_api_calls[ - 'list_instances'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.list_instances, - default_retry=self._method_configs['ListInstances'].retry, - default_timeout=self._method_configs['ListInstances']. - timeout, - client_info=self._client_info, - ) + "list_instances" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.list_instances, + default_retry=self._method_configs["ListInstances"].retry, + default_timeout=self._method_configs["ListInstances"].timeout, + client_info=self._client_info, + ) request = cloud_redis_pb2.ListInstancesRequest( - parent=parent, - page_size=page_size, + parent=parent, page_size=page_size ) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( - self._inner_api_calls['list_instances'], + self._inner_api_calls["list_instances"], retry=retry, timeout=timeout, - metadata=metadata), + metadata=metadata, + ), request=request, - items_field='instances', - request_token_field='page_token', - response_token_field='next_page_token', + items_field="instances", + request_token_field="page_token", + response_token_field="next_page_token", ) return iterator - def get_instance(self, - name, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def get_instance( + self, + name, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Gets the details of a specific Redis instance. @@ -344,27 +349,30 @@ def get_instance(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'get_instance' not in self._inner_api_calls: + if "get_instance" not in self._inner_api_calls: self._inner_api_calls[ - 'get_instance'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.get_instance, - default_retry=self._method_configs['GetInstance'].retry, - default_timeout=self._method_configs['GetInstance']. - timeout, - client_info=self._client_info, - ) + "get_instance" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.get_instance, + default_retry=self._method_configs["GetInstance"].retry, + default_timeout=self._method_configs["GetInstance"].timeout, + client_info=self._client_info, + ) - request = cloud_redis_pb2.GetInstanceRequest(name=name, ) - return self._inner_api_calls['get_instance']( - request, retry=retry, timeout=timeout, metadata=metadata) - - def create_instance(self, - parent, - instance_id, - instance, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + request = cloud_redis_pb2.GetInstanceRequest(name=name) + return self._inner_api_calls["get_instance"]( + request, retry=retry, timeout=timeout, metadata=metadata + ) + + def create_instance( + self, + parent, + instance_id, + instance, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Creates a Redis instance based on the specified tier and memory size. @@ -439,23 +447,22 @@ def create_instance(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'create_instance' not in self._inner_api_calls: + if "create_instance" not in self._inner_api_calls: self._inner_api_calls[ - 'create_instance'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.create_instance, - default_retry=self._method_configs['CreateInstance'].retry, - default_timeout=self._method_configs['CreateInstance']. - timeout, - client_info=self._client_info, - ) + "create_instance" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.create_instance, + default_retry=self._method_configs["CreateInstance"].retry, + default_timeout=self._method_configs["CreateInstance"].timeout, + client_info=self._client_info, + ) request = cloud_redis_pb2.CreateInstanceRequest( - parent=parent, - instance_id=instance_id, - instance=instance, + parent=parent, instance_id=instance_id, instance=instance + ) + operation = self._inner_api_calls["create_instance"]( + request, retry=retry, timeout=timeout, metadata=metadata ) - operation = self._inner_api_calls['create_instance']( - request, retry=retry, timeout=timeout, metadata=metadata) return google.api_core.operation.from_gapic( operation, self.transport._operations_client, @@ -463,12 +470,14 @@ def create_instance(self, metadata_type=cloud_redis_pb2.OperationMetadata, ) - def update_instance(self, - update_mask, - instance, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def update_instance( + self, + update_mask, + instance, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Updates the metadata and configuration of a specific Redis instance. @@ -537,22 +546,22 @@ def update_instance(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'update_instance' not in self._inner_api_calls: + if "update_instance" not in self._inner_api_calls: self._inner_api_calls[ - 'update_instance'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.update_instance, - default_retry=self._method_configs['UpdateInstance'].retry, - default_timeout=self._method_configs['UpdateInstance']. - timeout, - client_info=self._client_info, - ) + "update_instance" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.update_instance, + default_retry=self._method_configs["UpdateInstance"].retry, + default_timeout=self._method_configs["UpdateInstance"].timeout, + client_info=self._client_info, + ) request = cloud_redis_pb2.UpdateInstanceRequest( - update_mask=update_mask, - instance=instance, + update_mask=update_mask, instance=instance + ) + operation = self._inner_api_calls["update_instance"]( + request, retry=retry, timeout=timeout, metadata=metadata ) - operation = self._inner_api_calls['update_instance']( - request, retry=retry, timeout=timeout, metadata=metadata) return google.api_core.operation.from_gapic( operation, self.transport._operations_client, @@ -560,11 +569,13 @@ def update_instance(self, metadata_type=cloud_redis_pb2.OperationMetadata, ) - def delete_instance(self, - name, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def delete_instance( + self, + name, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Deletes a specific Redis instance. Instance stops serving and data is deleted. @@ -611,19 +622,20 @@ def delete_instance(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'delete_instance' not in self._inner_api_calls: + if "delete_instance" not in self._inner_api_calls: self._inner_api_calls[ - 'delete_instance'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.delete_instance, - default_retry=self._method_configs['DeleteInstance'].retry, - default_timeout=self._method_configs['DeleteInstance']. - timeout, - client_info=self._client_info, - ) + "delete_instance" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.delete_instance, + default_retry=self._method_configs["DeleteInstance"].retry, + default_timeout=self._method_configs["DeleteInstance"].timeout, + client_info=self._client_info, + ) - request = cloud_redis_pb2.DeleteInstanceRequest(name=name, ) - operation = self._inner_api_calls['delete_instance']( - request, retry=retry, timeout=timeout, metadata=metadata) + request = cloud_redis_pb2.DeleteInstanceRequest(name=name) + operation = self._inner_api_calls["delete_instance"]( + request, retry=retry, timeout=timeout, metadata=metadata + ) return google.api_core.operation.from_gapic( operation, self.transport._operations_client, diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/gapic/cloud_redis_client_config.py b/packages/google-cloud-redis/google/cloud/redis_v1/gapic/cloud_redis_client_config.py index ccf11e0a797d..9c2f466a13f8 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/gapic/cloud_redis_client_config.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/gapic/cloud_redis_client_config.py @@ -3,7 +3,7 @@ "google.cloud.redis.v1.CloudRedis": { "retry_codes": { "idempotent": ["DEADLINE_EXCEEDED", "UNAVAILABLE"], - "non_idempotent": [] + "non_idempotent": [], }, "retry_params": { "default": { @@ -13,36 +13,36 @@ "initial_rpc_timeout_millis": 20000, "rpc_timeout_multiplier": 1.0, "max_rpc_timeout_millis": 20000, - "total_timeout_millis": 600000 + "total_timeout_millis": 600000, } }, "methods": { "ListInstances": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "GetInstance": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "CreateInstance": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "UpdateInstance": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "DeleteInstance": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - } - } + "retry_params_name": "default", + }, + }, } } } diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/gapic/enums.py b/packages/google-cloud-redis/google/cloud/redis_v1/gapic/enums.py index 06a70f37c8df..3799b71aa958 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/gapic/enums.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/gapic/enums.py @@ -35,6 +35,7 @@ class State(enum.IntEnum): found in the ``status_message`` field. MAINTENANCE (int): Maintenance is being performed on this Redis instance. """ + STATE_UNSPECIFIED = 0 CREATING = 1 READY = 2 @@ -52,6 +53,7 @@ class Tier(enum.IntEnum): BASIC (int): BASIC tier: standalone instance STANDARD_HA (int): STANDARD\_HA tier: highly available primary/replica instances """ + TIER_UNSPECIFIED = 0 BASIC = 1 STANDARD_HA = 3 diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/gapic/transports/cloud_redis_grpc_transport.py b/packages/google-cloud-redis/google/cloud/redis_v1/gapic/transports/cloud_redis_grpc_transport.py index 49bac66b9df2..dcc01ed7b917 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/gapic/transports/cloud_redis_grpc_transport.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/gapic/transports/cloud_redis_grpc_transport.py @@ -28,14 +28,14 @@ class CloudRedisGrpcTransport(object): which can be used to take advantage of advanced features of gRPC. """ + # The scopes needed to make gRPC calls to all of the methods defined # in this service. - _OAUTH_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) + _OAUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) - def __init__(self, - channel=None, - credentials=None, - address='redis.googleapis.com:443'): + def __init__( + self, channel=None, credentials=None, address="redis.googleapis.com:443" + ): """Instantiate the transport class. Args: @@ -53,34 +53,28 @@ def __init__(self, # exception (channels come with credentials baked in already). if channel is not None and credentials is not None: raise ValueError( - 'The `channel` and `credentials` arguments are mutually ' - 'exclusive.', ) + "The `channel` and `credentials` arguments are mutually " "exclusive." + ) # Create the channel. if channel is None: - channel = self.create_channel( - address=address, - credentials=credentials, - ) + channel = self.create_channel(address=address, credentials=credentials) self._channel = channel # gRPC uses objects called "stubs" that are bound to the # channel and provide a basic method for each RPC. - self._stubs = { - 'cloud_redis_stub': cloud_redis_pb2_grpc.CloudRedisStub(channel), - } + self._stubs = {"cloud_redis_stub": cloud_redis_pb2_grpc.CloudRedisStub(channel)} # Because this API includes a method that returns a # long-running operation (proto: google.longrunning.Operation), # instantiate an LRO client. self._operations_client = google.api_core.operations_v1.OperationsClient( - channel) + channel + ) @classmethod - def create_channel(cls, - address='redis.googleapis.com:443', - credentials=None): + def create_channel(cls, address="redis.googleapis.com:443", credentials=None): """Create and return a gRPC channel object. Args: @@ -95,9 +89,7 @@ def create_channel(cls, grpc.Channel: A gRPC channel object. """ return google.api_core.grpc_helpers.create_channel( - address, - credentials=credentials, - scopes=cls._OAUTH_SCOPES, + address, credentials=credentials, scopes=cls._OAUTH_SCOPES ) @property @@ -127,7 +119,7 @@ def list_instances(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['cloud_redis_stub'].ListInstances + return self._stubs["cloud_redis_stub"].ListInstances @property def get_instance(self): @@ -140,7 +132,7 @@ def get_instance(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['cloud_redis_stub'].GetInstance + return self._stubs["cloud_redis_stub"].GetInstance @property def create_instance(self): @@ -165,7 +157,7 @@ def create_instance(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['cloud_redis_stub'].CreateInstance + return self._stubs["cloud_redis_stub"].CreateInstance @property def update_instance(self): @@ -182,7 +174,7 @@ def update_instance(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['cloud_redis_stub'].UpdateInstance + return self._stubs["cloud_redis_stub"].UpdateInstance @property def delete_instance(self): @@ -196,4 +188,4 @@ def delete_instance(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['cloud_redis_stub'].DeleteInstance + return self._stubs["cloud_redis_stub"].DeleteInstance diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/types.py b/packages/google-cloud-redis/google/cloud/redis_v1/types.py index 2b3d570a6614..8ba2e2e88738 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/types.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/types.py @@ -40,9 +40,7 @@ status_pb2, ] -_local_modules = [ - cloud_redis_pb2, -] +_local_modules = [cloud_redis_pb2] names = [] @@ -52,7 +50,7 @@ names.append(name) for module in _local_modules: for name, message in get_messages(module).items(): - message.__module__ = 'google.cloud.redis_v1.types' + message.__module__ = "google.cloud.redis_v1.types" setattr(sys.modules[__name__], name, message) names.append(name) diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/__init__.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/__init__.py index cbac83c2d838..61f1c6e0d7ff 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/__init__.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/__init__.py @@ -26,8 +26,4 @@ class CloudRedisClient(cloud_redis_client.CloudRedisClient): enums = enums -__all__ = ( - 'enums', - 'types', - 'CloudRedisClient', -) +__all__ = ("enums", "types", "CloudRedisClient") diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client.py index 7c30afa29013..76b95c7d093a 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client.py @@ -40,8 +40,7 @@ from google.protobuf import empty_pb2 from google.protobuf import field_mask_pb2 -_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution( - 'google-cloud-redis', ).version +_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution("google-cloud-redis").version class CloudRedisClient(object): @@ -64,12 +63,12 @@ class CloudRedisClient(object): ``projects/redpepper-1290/locations/us-central1/instances/my-redis`` """ - SERVICE_ADDRESS = 'redis.googleapis.com:443' + SERVICE_ADDRESS = "redis.googleapis.com:443" """The default address of the service.""" # The name of the interface for this client. This is the key used to # find the method configuration in the client_config dictionary. - _INTERFACE_NAME = 'google.cloud.redis.v1beta1.CloudRedis' + _INTERFACE_NAME = "google.cloud.redis.v1beta1.CloudRedis" @classmethod def from_service_account_file(cls, filename, *args, **kwargs): @@ -85,9 +84,8 @@ def from_service_account_file(cls, filename, *args, **kwargs): Returns: CloudRedisClient: The constructed client. """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs['credentials'] = credentials + credentials = service_account.Credentials.from_service_account_file(filename) + kwargs["credentials"] = credentials return cls(*args, **kwargs) from_service_account_json = from_service_account_file @@ -96,7 +94,7 @@ def from_service_account_file(cls, filename, *args, **kwargs): def location_path(cls, project, location): """Return a fully-qualified location string.""" return google.api_core.path_template.expand( - 'projects/{project}/locations/{location}', + "projects/{project}/locations/{location}", project=project, location=location, ) @@ -105,18 +103,20 @@ def location_path(cls, project, location): def instance_path(cls, project, location, instance): """Return a fully-qualified instance string.""" return google.api_core.path_template.expand( - 'projects/{project}/locations/{location}/instances/{instance}', + "projects/{project}/locations/{location}/instances/{instance}", project=project, location=location, instance=instance, ) - def __init__(self, - transport=None, - channel=None, - credentials=None, - client_config=None, - client_info=None): + def __init__( + self, + transport=None, + channel=None, + credentials=None, + client_config=None, + client_info=None, + ): """Constructor. Args: @@ -150,18 +150,19 @@ def __init__(self, # Raise deprecation warnings for things we want to go away. if client_config is not None: warnings.warn( - 'The `client_config` argument is deprecated.', + "The `client_config` argument is deprecated.", PendingDeprecationWarning, - stacklevel=2) + stacklevel=2, + ) else: client_config = cloud_redis_client_config.config if channel: warnings.warn( - 'The `channel` argument is deprecated; use ' - '`transport` instead.', + "The `channel` argument is deprecated; use " "`transport` instead.", PendingDeprecationWarning, - stacklevel=2) + stacklevel=2, + ) # Instantiate the transport. # The transport is responsible for handling serialization and @@ -170,25 +171,24 @@ def __init__(self, if callable(transport): self.transport = transport( credentials=credentials, - default_class=cloud_redis_grpc_transport. - CloudRedisGrpcTransport, + default_class=cloud_redis_grpc_transport.CloudRedisGrpcTransport, ) else: if credentials: raise ValueError( - 'Received both a transport instance and ' - 'credentials; these are mutually exclusive.') + "Received both a transport instance and " + "credentials; these are mutually exclusive." + ) self.transport = transport else: self.transport = cloud_redis_grpc_transport.CloudRedisGrpcTransport( - address=self.SERVICE_ADDRESS, - channel=channel, - credentials=credentials, + address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials ) if client_info is None: client_info = google.api_core.gapic_v1.client_info.ClientInfo( - gapic_version=_GAPIC_LIBRARY_VERSION, ) + gapic_version=_GAPIC_LIBRARY_VERSION + ) else: client_info.gapic_version = _GAPIC_LIBRARY_VERSION self._client_info = client_info @@ -198,7 +198,8 @@ def __init__(self, # (Ordinarily, these are the defaults specified in the `*_config.py` # file next to this one.) self._method_configs = google.api_core.gapic_v1.config.parse_method_configs( - client_config['interfaces'][self._INTERFACE_NAME], ) + client_config["interfaces"][self._INTERFACE_NAME] + ) # Save a dictionary of cached API call functions. # These are the actual callables which invoke the proper @@ -207,12 +208,14 @@ def __init__(self, self._inner_api_calls = {} # Service calls - def list_instances(self, - parent, - page_size=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def list_instances( + self, + parent, + page_size=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Lists all Redis instances owned by a project in either the specified location (region) or all locations. @@ -276,39 +279,41 @@ def list_instances(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'list_instances' not in self._inner_api_calls: + if "list_instances" not in self._inner_api_calls: self._inner_api_calls[ - 'list_instances'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.list_instances, - default_retry=self._method_configs['ListInstances'].retry, - default_timeout=self._method_configs['ListInstances']. - timeout, - client_info=self._client_info, - ) + "list_instances" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.list_instances, + default_retry=self._method_configs["ListInstances"].retry, + default_timeout=self._method_configs["ListInstances"].timeout, + client_info=self._client_info, + ) request = cloud_redis_pb2.ListInstancesRequest( - parent=parent, - page_size=page_size, + parent=parent, page_size=page_size ) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( - self._inner_api_calls['list_instances'], + self._inner_api_calls["list_instances"], retry=retry, timeout=timeout, - metadata=metadata), + metadata=metadata, + ), request=request, - items_field='instances', - request_token_field='page_token', - response_token_field='next_page_token', + items_field="instances", + request_token_field="page_token", + response_token_field="next_page_token", ) return iterator - def get_instance(self, - name, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def get_instance( + self, + name, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Gets the details of a specific Redis instance. @@ -345,27 +350,30 @@ def get_instance(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'get_instance' not in self._inner_api_calls: + if "get_instance" not in self._inner_api_calls: self._inner_api_calls[ - 'get_instance'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.get_instance, - default_retry=self._method_configs['GetInstance'].retry, - default_timeout=self._method_configs['GetInstance']. - timeout, - client_info=self._client_info, - ) + "get_instance" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.get_instance, + default_retry=self._method_configs["GetInstance"].retry, + default_timeout=self._method_configs["GetInstance"].timeout, + client_info=self._client_info, + ) - request = cloud_redis_pb2.GetInstanceRequest(name=name, ) - return self._inner_api_calls['get_instance']( - request, retry=retry, timeout=timeout, metadata=metadata) - - def create_instance(self, - parent, - instance_id, - instance, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + request = cloud_redis_pb2.GetInstanceRequest(name=name) + return self._inner_api_calls["get_instance"]( + request, retry=retry, timeout=timeout, metadata=metadata + ) + + def create_instance( + self, + parent, + instance_id, + instance, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Creates a Redis instance based on the specified tier and memory size. @@ -440,23 +448,22 @@ def create_instance(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'create_instance' not in self._inner_api_calls: + if "create_instance" not in self._inner_api_calls: self._inner_api_calls[ - 'create_instance'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.create_instance, - default_retry=self._method_configs['CreateInstance'].retry, - default_timeout=self._method_configs['CreateInstance']. - timeout, - client_info=self._client_info, - ) + "create_instance" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.create_instance, + default_retry=self._method_configs["CreateInstance"].retry, + default_timeout=self._method_configs["CreateInstance"].timeout, + client_info=self._client_info, + ) request = cloud_redis_pb2.CreateInstanceRequest( - parent=parent, - instance_id=instance_id, - instance=instance, + parent=parent, instance_id=instance_id, instance=instance + ) + operation = self._inner_api_calls["create_instance"]( + request, retry=retry, timeout=timeout, metadata=metadata ) - operation = self._inner_api_calls['create_instance']( - request, retry=retry, timeout=timeout, metadata=metadata) return google.api_core.operation.from_gapic( operation, self.transport._operations_client, @@ -464,12 +471,14 @@ def create_instance(self, metadata_type=any_pb2.Any, ) - def update_instance(self, - update_mask, - instance, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def update_instance( + self, + update_mask, + instance, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Updates the metadata and configuration of a specific Redis instance. @@ -534,22 +543,22 @@ def update_instance(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'update_instance' not in self._inner_api_calls: + if "update_instance" not in self._inner_api_calls: self._inner_api_calls[ - 'update_instance'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.update_instance, - default_retry=self._method_configs['UpdateInstance'].retry, - default_timeout=self._method_configs['UpdateInstance']. - timeout, - client_info=self._client_info, - ) + "update_instance" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.update_instance, + default_retry=self._method_configs["UpdateInstance"].retry, + default_timeout=self._method_configs["UpdateInstance"].timeout, + client_info=self._client_info, + ) request = cloud_redis_pb2.UpdateInstanceRequest( - update_mask=update_mask, - instance=instance, + update_mask=update_mask, instance=instance + ) + operation = self._inner_api_calls["update_instance"]( + request, retry=retry, timeout=timeout, metadata=metadata ) - operation = self._inner_api_calls['update_instance']( - request, retry=retry, timeout=timeout, metadata=metadata) return google.api_core.operation.from_gapic( operation, self.transport._operations_client, @@ -557,11 +566,13 @@ def update_instance(self, metadata_type=any_pb2.Any, ) - def delete_instance(self, - name, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def delete_instance( + self, + name, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Deletes a specific Redis instance. Instance stops serving and data is deleted. @@ -608,19 +619,20 @@ def delete_instance(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'delete_instance' not in self._inner_api_calls: + if "delete_instance" not in self._inner_api_calls: self._inner_api_calls[ - 'delete_instance'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.delete_instance, - default_retry=self._method_configs['DeleteInstance'].retry, - default_timeout=self._method_configs['DeleteInstance']. - timeout, - client_info=self._client_info, - ) + "delete_instance" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.delete_instance, + default_retry=self._method_configs["DeleteInstance"].retry, + default_timeout=self._method_configs["DeleteInstance"].timeout, + client_info=self._client_info, + ) - request = cloud_redis_pb2.DeleteInstanceRequest(name=name, ) - operation = self._inner_api_calls['delete_instance']( - request, retry=retry, timeout=timeout, metadata=metadata) + request = cloud_redis_pb2.DeleteInstanceRequest(name=name) + operation = self._inner_api_calls["delete_instance"]( + request, retry=retry, timeout=timeout, metadata=metadata + ) return google.api_core.operation.from_gapic( operation, self.transport._operations_client, diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client_config.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client_config.py index 3af57fd0c972..863c124675fa 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client_config.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client_config.py @@ -3,7 +3,7 @@ "google.cloud.redis.v1beta1.CloudRedis": { "retry_codes": { "idempotent": ["DEADLINE_EXCEEDED", "UNAVAILABLE"], - "non_idempotent": [] + "non_idempotent": [], }, "retry_params": { "default": { @@ -13,36 +13,36 @@ "initial_rpc_timeout_millis": 20000, "rpc_timeout_multiplier": 1.0, "max_rpc_timeout_millis": 20000, - "total_timeout_millis": 600000 + "total_timeout_millis": 600000, } }, "methods": { "ListInstances": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "GetInstance": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "CreateInstance": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "UpdateInstance": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "DeleteInstance": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - } - } + "retry_params_name": "default", + }, + }, } } } diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/enums.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/enums.py index 06a70f37c8df..3799b71aa958 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/enums.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/enums.py @@ -35,6 +35,7 @@ class State(enum.IntEnum): found in the ``status_message`` field. MAINTENANCE (int): Maintenance is being performed on this Redis instance. """ + STATE_UNSPECIFIED = 0 CREATING = 1 READY = 2 @@ -52,6 +53,7 @@ class Tier(enum.IntEnum): BASIC (int): BASIC tier: standalone instance STANDARD_HA (int): STANDARD\_HA tier: highly available primary/replica instances """ + TIER_UNSPECIFIED = 0 BASIC = 1 STANDARD_HA = 3 diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/transports/cloud_redis_grpc_transport.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/transports/cloud_redis_grpc_transport.py index 12bfd3cdb9d4..943d9ba6f882 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/transports/cloud_redis_grpc_transport.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic/transports/cloud_redis_grpc_transport.py @@ -28,14 +28,14 @@ class CloudRedisGrpcTransport(object): which can be used to take advantage of advanced features of gRPC. """ + # The scopes needed to make gRPC calls to all of the methods defined # in this service. - _OAUTH_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) + _OAUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) - def __init__(self, - channel=None, - credentials=None, - address='redis.googleapis.com:443'): + def __init__( + self, channel=None, credentials=None, address="redis.googleapis.com:443" + ): """Instantiate the transport class. Args: @@ -53,34 +53,28 @@ def __init__(self, # exception (channels come with credentials baked in already). if channel is not None and credentials is not None: raise ValueError( - 'The `channel` and `credentials` arguments are mutually ' - 'exclusive.', ) + "The `channel` and `credentials` arguments are mutually " "exclusive." + ) # Create the channel. if channel is None: - channel = self.create_channel( - address=address, - credentials=credentials, - ) + channel = self.create_channel(address=address, credentials=credentials) self._channel = channel # gRPC uses objects called "stubs" that are bound to the # channel and provide a basic method for each RPC. - self._stubs = { - 'cloud_redis_stub': cloud_redis_pb2_grpc.CloudRedisStub(channel), - } + self._stubs = {"cloud_redis_stub": cloud_redis_pb2_grpc.CloudRedisStub(channel)} # Because this API includes a method that returns a # long-running operation (proto: google.longrunning.Operation), # instantiate an LRO client. self._operations_client = google.api_core.operations_v1.OperationsClient( - channel) + channel + ) @classmethod - def create_channel(cls, - address='redis.googleapis.com:443', - credentials=None): + def create_channel(cls, address="redis.googleapis.com:443", credentials=None): """Create and return a gRPC channel object. Args: @@ -95,9 +89,7 @@ def create_channel(cls, grpc.Channel: A gRPC channel object. """ return google.api_core.grpc_helpers.create_channel( - address, - credentials=credentials, - scopes=cls._OAUTH_SCOPES, + address, credentials=credentials, scopes=cls._OAUTH_SCOPES ) @property @@ -127,7 +119,7 @@ def list_instances(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['cloud_redis_stub'].ListInstances + return self._stubs["cloud_redis_stub"].ListInstances @property def get_instance(self): @@ -140,7 +132,7 @@ def get_instance(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['cloud_redis_stub'].GetInstance + return self._stubs["cloud_redis_stub"].GetInstance @property def create_instance(self): @@ -165,7 +157,7 @@ def create_instance(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['cloud_redis_stub'].CreateInstance + return self._stubs["cloud_redis_stub"].CreateInstance @property def update_instance(self): @@ -182,7 +174,7 @@ def update_instance(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['cloud_redis_stub'].UpdateInstance + return self._stubs["cloud_redis_stub"].UpdateInstance @property def delete_instance(self): @@ -196,4 +188,4 @@ def delete_instance(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['cloud_redis_stub'].DeleteInstance + return self._stubs["cloud_redis_stub"].DeleteInstance diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/types.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/types.py index d9af4f1dfc0d..f4900f213718 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/types.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/types.py @@ -40,9 +40,7 @@ status_pb2, ] -_local_modules = [ - cloud_redis_pb2, -] +_local_modules = [cloud_redis_pb2] names = [] @@ -52,7 +50,7 @@ names.append(name) for module in _local_modules: for name, message in get_messages(module).items(): - message.__module__ = 'google.cloud.redis_v1beta1.types' + message.__module__ = "google.cloud.redis_v1beta1.types" setattr(sys.modules[__name__], name, message) names.append(name) diff --git a/packages/google-cloud-redis/tests/unit/gapic/v1/test_cloud_redis_client_v1.py b/packages/google-cloud-redis/tests/unit/gapic/v1/test_cloud_redis_client_v1.py index 8242701be862..5f7a522bd932 100644 --- a/packages/google-cloud-redis/tests/unit/gapic/v1/test_cloud_redis_client_v1.py +++ b/packages/google-cloud-redis/tests/unit/gapic/v1/test_cloud_redis_client_v1.py @@ -56,10 +56,7 @@ def __init__(self, responses=[]): self.responses = responses self.requests = [] - def unary_unary(self, - method, - request_serializer=None, - response_deserializer=None): + def unary_unary(self, method, request_serializer=None, response_deserializer=None): return MultiCallableStub(method, self) @@ -70,25 +67,21 @@ class CustomException(Exception): class TestCloudRedisClient(object): def test_list_instances(self): # Setup Expected Response - next_page_token = '' + next_page_token = "" instances_element = {} instances = [instances_element] - expected_response = { - 'next_page_token': next_page_token, - 'instances': instances - } - expected_response = cloud_redis_pb2.ListInstancesResponse( - **expected_response) + expected_response = {"next_page_token": next_page_token, "instances": instances} + expected_response = cloud_redis_pb2.ListInstancesResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1.CloudRedisClient() # Setup Request - parent = client.location_path('[PROJECT]', '[LOCATION]') + parent = client.location_path("[PROJECT]", "[LOCATION]") paged_list_response = client.list_instances(parent) resources = list(paged_list_response) @@ -103,13 +96,13 @@ def test_list_instances(self): def test_list_instances_exception(self): channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1.CloudRedisClient() # Setup request - parent = client.location_path('[PROJECT]', '[LOCATION]') + parent = client.location_path("[PROJECT]", "[LOCATION]") paged_list_response = client.list_instances(parent) with pytest.raises(CustomException): @@ -117,43 +110,43 @@ def test_list_instances_exception(self): def test_get_instance(self): # Setup Expected Response - name_2 = 'name2-1052831874' - display_name = 'displayName1615086568' - location_id = 'locationId552319461' - alternative_location_id = 'alternativeLocationId-718920621' - redis_version = 'redisVersion-685310444' - reserved_ip_range = 'reservedIpRange-1082940580' - host = 'host3208616' + name_2 = "name2-1052831874" + display_name = "displayName1615086568" + location_id = "locationId552319461" + alternative_location_id = "alternativeLocationId-718920621" + redis_version = "redisVersion-685310444" + reserved_ip_range = "reservedIpRange-1082940580" + host = "host3208616" port = 3446913 - current_location_id = 'currentLocationId1312712735' - status_message = 'statusMessage-239442758' + current_location_id = "currentLocationId1312712735" + status_message = "statusMessage-239442758" memory_size_gb = 34199707 - authorized_network = 'authorizedNetwork-1733809270' + authorized_network = "authorizedNetwork-1733809270" expected_response = { - 'name': name_2, - 'display_name': display_name, - 'location_id': location_id, - 'alternative_location_id': alternative_location_id, - 'redis_version': redis_version, - 'reserved_ip_range': reserved_ip_range, - 'host': host, - 'port': port, - 'current_location_id': current_location_id, - 'status_message': status_message, - 'memory_size_gb': memory_size_gb, - 'authorized_network': authorized_network + "name": name_2, + "display_name": display_name, + "location_id": location_id, + "alternative_location_id": alternative_location_id, + "redis_version": redis_version, + "reserved_ip_range": reserved_ip_range, + "host": host, + "port": port, + "current_location_id": current_location_id, + "status_message": status_message, + "memory_size_gb": memory_size_gb, + "authorized_network": authorized_network, } expected_response = cloud_redis_pb2.Instance(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1.CloudRedisClient() # Setup Request - name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + name = client.instance_path("[PROJECT]", "[LOCATION]", "[INSTANCE]") response = client.get_instance(name) assert expected_response == response @@ -166,63 +159,64 @@ def test_get_instance(self): def test_get_instance_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1.CloudRedisClient() # Setup request - name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + name = client.instance_path("[PROJECT]", "[LOCATION]", "[INSTANCE]") with pytest.raises(CustomException): client.get_instance(name) def test_create_instance(self): # Setup Expected Response - name = 'name3373707' - display_name = 'displayName1615086568' - location_id = 'locationId552319461' - alternative_location_id = 'alternativeLocationId-718920621' - redis_version = 'redisVersion-685310444' - reserved_ip_range = 'reservedIpRange-1082940580' - host = 'host3208616' + name = "name3373707" + display_name = "displayName1615086568" + location_id = "locationId552319461" + alternative_location_id = "alternativeLocationId-718920621" + redis_version = "redisVersion-685310444" + reserved_ip_range = "reservedIpRange-1082940580" + host = "host3208616" port = 3446913 - current_location_id = 'currentLocationId1312712735' - status_message = 'statusMessage-239442758' + current_location_id = "currentLocationId1312712735" + status_message = "statusMessage-239442758" memory_size_gb_2 = 1493816946 - authorized_network = 'authorizedNetwork-1733809270' + authorized_network = "authorizedNetwork-1733809270" expected_response = { - 'name': name, - 'display_name': display_name, - 'location_id': location_id, - 'alternative_location_id': alternative_location_id, - 'redis_version': redis_version, - 'reserved_ip_range': reserved_ip_range, - 'host': host, - 'port': port, - 'current_location_id': current_location_id, - 'status_message': status_message, - 'memory_size_gb': memory_size_gb_2, - 'authorized_network': authorized_network + "name": name, + "display_name": display_name, + "location_id": location_id, + "alternative_location_id": alternative_location_id, + "redis_version": redis_version, + "reserved_ip_range": reserved_ip_range, + "host": host, + "port": port, + "current_location_id": current_location_id, + "status_message": status_message, + "memory_size_gb": memory_size_gb_2, + "authorized_network": authorized_network, } expected_response = cloud_redis_pb2.Instance(**expected_response) operation = operations_pb2.Operation( - name='operations/test_create_instance', done=True) + name="operations/test_create_instance", done=True + ) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1.CloudRedisClient() # Setup Request - parent = client.location_path('[PROJECT]', '[LOCATION]') - instance_id = 'test_instance' + parent = client.location_path("[PROJECT]", "[LOCATION]") + instance_id = "test_instance" tier = enums.Instance.Tier.BASIC memory_size_gb = 1 - instance = {'tier': tier, 'memory_size_gb': memory_size_gb} + instance = {"tier": tier, "memory_size_gb": memory_size_gb} response = client.create_instance(parent, instance_id, instance) result = response.result() @@ -230,7 +224,8 @@ def test_create_instance(self): assert len(channel.requests) == 1 expected_request = cloud_redis_pb2.CreateInstanceRequest( - parent=parent, instance_id=instance_id, instance=instance) + parent=parent, instance_id=instance_id, instance=instance + ) actual_request = channel.requests[0][1] assert expected_request == actual_request @@ -238,22 +233,23 @@ def test_create_instance_exception(self): # Setup Response error = status_pb2.Status() operation = operations_pb2.Operation( - name='operations/test_create_instance_exception', done=True) + name="operations/test_create_instance_exception", done=True + ) operation.error.CopyFrom(error) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1.CloudRedisClient() # Setup Request - parent = client.location_path('[PROJECT]', '[LOCATION]') - instance_id = 'test_instance' + parent = client.location_path("[PROJECT]", "[LOCATION]") + instance_id = "test_instance" tier = enums.Instance.Tier.BASIC memory_size_gb = 1 - instance = {'tier': tier, 'memory_size_gb': memory_size_gb} + instance = {"tier": tier, "memory_size_gb": memory_size_gb} response = client.create_instance(parent, instance_id, instance) exception = response.exception() @@ -261,55 +257,53 @@ def test_create_instance_exception(self): def test_update_instance(self): # Setup Expected Response - name = 'name3373707' - display_name_2 = 'displayName21615000987' - location_id = 'locationId552319461' - alternative_location_id = 'alternativeLocationId-718920621' - redis_version = 'redisVersion-685310444' - reserved_ip_range = 'reservedIpRange-1082940580' - host = 'host3208616' + name = "name3373707" + display_name_2 = "displayName21615000987" + location_id = "locationId552319461" + alternative_location_id = "alternativeLocationId-718920621" + redis_version = "redisVersion-685310444" + reserved_ip_range = "reservedIpRange-1082940580" + host = "host3208616" port = 3446913 - current_location_id = 'currentLocationId1312712735' - status_message = 'statusMessage-239442758' + current_location_id = "currentLocationId1312712735" + status_message = "statusMessage-239442758" memory_size_gb_2 = 1493816946 - authorized_network = 'authorizedNetwork-1733809270' + authorized_network = "authorizedNetwork-1733809270" expected_response = { - 'name': name, - 'display_name': display_name_2, - 'location_id': location_id, - 'alternative_location_id': alternative_location_id, - 'redis_version': redis_version, - 'reserved_ip_range': reserved_ip_range, - 'host': host, - 'port': port, - 'current_location_id': current_location_id, - 'status_message': status_message, - 'memory_size_gb': memory_size_gb_2, - 'authorized_network': authorized_network + "name": name, + "display_name": display_name_2, + "location_id": location_id, + "alternative_location_id": alternative_location_id, + "redis_version": redis_version, + "reserved_ip_range": reserved_ip_range, + "host": host, + "port": port, + "current_location_id": current_location_id, + "status_message": status_message, + "memory_size_gb": memory_size_gb_2, + "authorized_network": authorized_network, } expected_response = cloud_redis_pb2.Instance(**expected_response) operation = operations_pb2.Operation( - name='operations/test_update_instance', done=True) + name="operations/test_update_instance", done=True + ) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1.CloudRedisClient() # Setup Request - paths_element = 'display_name' - paths_element_2 = 'memory_size_gb' + paths_element = "display_name" + paths_element_2 = "memory_size_gb" paths = [paths_element, paths_element_2] - update_mask = {'paths': paths} - display_name = 'UpdatedDisplayName' + update_mask = {"paths": paths} + display_name = "UpdatedDisplayName" memory_size_gb = 4 - instance = { - 'display_name': display_name, - 'memory_size_gb': memory_size_gb - } + instance = {"display_name": display_name, "memory_size_gb": memory_size_gb} response = client.update_instance(update_mask, instance) result = response.result() @@ -317,7 +311,8 @@ def test_update_instance(self): assert len(channel.requests) == 1 expected_request = cloud_redis_pb2.UpdateInstanceRequest( - update_mask=update_mask, instance=instance) + update_mask=update_mask, instance=instance + ) actual_request = channel.requests[0][1] assert expected_request == actual_request @@ -325,27 +320,25 @@ def test_update_instance_exception(self): # Setup Response error = status_pb2.Status() operation = operations_pb2.Operation( - name='operations/test_update_instance_exception', done=True) + name="operations/test_update_instance_exception", done=True + ) operation.error.CopyFrom(error) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1.CloudRedisClient() # Setup Request - paths_element = 'display_name' - paths_element_2 = 'memory_size_gb' + paths_element = "display_name" + paths_element_2 = "memory_size_gb" paths = [paths_element, paths_element_2] - update_mask = {'paths': paths} - display_name = 'UpdatedDisplayName' + update_mask = {"paths": paths} + display_name = "UpdatedDisplayName" memory_size_gb = 4 - instance = { - 'display_name': display_name, - 'memory_size_gb': memory_size_gb - } + instance = {"display_name": display_name, "memory_size_gb": memory_size_gb} response = client.update_instance(update_mask, instance) exception = response.exception() @@ -356,18 +349,19 @@ def test_delete_instance(self): expected_response = {} expected_response = empty_pb2.Empty(**expected_response) operation = operations_pb2.Operation( - name='operations/test_delete_instance', done=True) + name="operations/test_delete_instance", done=True + ) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1.CloudRedisClient() # Setup Request - name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + name = client.instance_path("[PROJECT]", "[LOCATION]", "[INSTANCE]") response = client.delete_instance(name) result = response.result() @@ -382,18 +376,19 @@ def test_delete_instance_exception(self): # Setup Response error = status_pb2.Status() operation = operations_pb2.Operation( - name='operations/test_delete_instance_exception', done=True) + name="operations/test_delete_instance_exception", done=True + ) operation.error.CopyFrom(error) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1.CloudRedisClient() # Setup Request - name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + name = client.instance_path("[PROJECT]", "[LOCATION]", "[INSTANCE]") response = client.delete_instance(name) exception = response.exception() diff --git a/packages/google-cloud-redis/tests/unit/gapic/v1beta1/test_cloud_redis_client_v1beta1.py b/packages/google-cloud-redis/tests/unit/gapic/v1beta1/test_cloud_redis_client_v1beta1.py index a9e2f4c9aea6..03ff42f24288 100644 --- a/packages/google-cloud-redis/tests/unit/gapic/v1beta1/test_cloud_redis_client_v1beta1.py +++ b/packages/google-cloud-redis/tests/unit/gapic/v1beta1/test_cloud_redis_client_v1beta1.py @@ -56,10 +56,7 @@ def __init__(self, responses=[]): self.responses = responses self.requests = [] - def unary_unary(self, - method, - request_serializer=None, - response_deserializer=None): + def unary_unary(self, method, request_serializer=None, response_deserializer=None): return MultiCallableStub(method, self) @@ -70,25 +67,21 @@ class CustomException(Exception): class TestCloudRedisClient(object): def test_list_instances(self): # Setup Expected Response - next_page_token = '' + next_page_token = "" instances_element = {} instances = [instances_element] - expected_response = { - 'next_page_token': next_page_token, - 'instances': instances - } - expected_response = cloud_redis_pb2.ListInstancesResponse( - **expected_response) + expected_response = {"next_page_token": next_page_token, "instances": instances} + expected_response = cloud_redis_pb2.ListInstancesResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1beta1.CloudRedisClient() # Setup Request - parent = client.location_path('[PROJECT]', '[LOCATION]') + parent = client.location_path("[PROJECT]", "[LOCATION]") paged_list_response = client.list_instances(parent) resources = list(paged_list_response) @@ -103,13 +96,13 @@ def test_list_instances(self): def test_list_instances_exception(self): channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1beta1.CloudRedisClient() # Setup request - parent = client.location_path('[PROJECT]', '[LOCATION]') + parent = client.location_path("[PROJECT]", "[LOCATION]") paged_list_response = client.list_instances(parent) with pytest.raises(CustomException): @@ -117,43 +110,43 @@ def test_list_instances_exception(self): def test_get_instance(self): # Setup Expected Response - name_2 = 'name2-1052831874' - display_name = 'displayName1615086568' - location_id = 'locationId552319461' - alternative_location_id = 'alternativeLocationId-718920621' - redis_version = 'redisVersion-685310444' - reserved_ip_range = 'reservedIpRange-1082940580' - host = 'host3208616' + name_2 = "name2-1052831874" + display_name = "displayName1615086568" + location_id = "locationId552319461" + alternative_location_id = "alternativeLocationId-718920621" + redis_version = "redisVersion-685310444" + reserved_ip_range = "reservedIpRange-1082940580" + host = "host3208616" port = 3446913 - current_location_id = 'currentLocationId1312712735' - status_message = 'statusMessage-239442758' + current_location_id = "currentLocationId1312712735" + status_message = "statusMessage-239442758" memory_size_gb = 34199707 - authorized_network = 'authorizedNetwork-1733809270' + authorized_network = "authorizedNetwork-1733809270" expected_response = { - 'name': name_2, - 'display_name': display_name, - 'location_id': location_id, - 'alternative_location_id': alternative_location_id, - 'redis_version': redis_version, - 'reserved_ip_range': reserved_ip_range, - 'host': host, - 'port': port, - 'current_location_id': current_location_id, - 'status_message': status_message, - 'memory_size_gb': memory_size_gb, - 'authorized_network': authorized_network + "name": name_2, + "display_name": display_name, + "location_id": location_id, + "alternative_location_id": alternative_location_id, + "redis_version": redis_version, + "reserved_ip_range": reserved_ip_range, + "host": host, + "port": port, + "current_location_id": current_location_id, + "status_message": status_message, + "memory_size_gb": memory_size_gb, + "authorized_network": authorized_network, } expected_response = cloud_redis_pb2.Instance(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1beta1.CloudRedisClient() # Setup Request - name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + name = client.instance_path("[PROJECT]", "[LOCATION]", "[INSTANCE]") response = client.get_instance(name) assert expected_response == response @@ -166,63 +159,64 @@ def test_get_instance(self): def test_get_instance_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1beta1.CloudRedisClient() # Setup request - name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + name = client.instance_path("[PROJECT]", "[LOCATION]", "[INSTANCE]") with pytest.raises(CustomException): client.get_instance(name) def test_create_instance(self): # Setup Expected Response - name = 'name3373707' - display_name = 'displayName1615086568' - location_id = 'locationId552319461' - alternative_location_id = 'alternativeLocationId-718920621' - redis_version = 'redisVersion-685310444' - reserved_ip_range = 'reservedIpRange-1082940580' - host = 'host3208616' + name = "name3373707" + display_name = "displayName1615086568" + location_id = "locationId552319461" + alternative_location_id = "alternativeLocationId-718920621" + redis_version = "redisVersion-685310444" + reserved_ip_range = "reservedIpRange-1082940580" + host = "host3208616" port = 3446913 - current_location_id = 'currentLocationId1312712735' - status_message = 'statusMessage-239442758' + current_location_id = "currentLocationId1312712735" + status_message = "statusMessage-239442758" memory_size_gb_2 = 1493816946 - authorized_network = 'authorizedNetwork-1733809270' + authorized_network = "authorizedNetwork-1733809270" expected_response = { - 'name': name, - 'display_name': display_name, - 'location_id': location_id, - 'alternative_location_id': alternative_location_id, - 'redis_version': redis_version, - 'reserved_ip_range': reserved_ip_range, - 'host': host, - 'port': port, - 'current_location_id': current_location_id, - 'status_message': status_message, - 'memory_size_gb': memory_size_gb_2, - 'authorized_network': authorized_network + "name": name, + "display_name": display_name, + "location_id": location_id, + "alternative_location_id": alternative_location_id, + "redis_version": redis_version, + "reserved_ip_range": reserved_ip_range, + "host": host, + "port": port, + "current_location_id": current_location_id, + "status_message": status_message, + "memory_size_gb": memory_size_gb_2, + "authorized_network": authorized_network, } expected_response = cloud_redis_pb2.Instance(**expected_response) operation = operations_pb2.Operation( - name='operations/test_create_instance', done=True) + name="operations/test_create_instance", done=True + ) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1beta1.CloudRedisClient() # Setup Request - parent = client.location_path('[PROJECT]', '[LOCATION]') - instance_id = 'test_instance' + parent = client.location_path("[PROJECT]", "[LOCATION]") + instance_id = "test_instance" tier = enums.Instance.Tier.BASIC memory_size_gb = 1 - instance = {'tier': tier, 'memory_size_gb': memory_size_gb} + instance = {"tier": tier, "memory_size_gb": memory_size_gb} response = client.create_instance(parent, instance_id, instance) result = response.result() @@ -230,7 +224,8 @@ def test_create_instance(self): assert len(channel.requests) == 1 expected_request = cloud_redis_pb2.CreateInstanceRequest( - parent=parent, instance_id=instance_id, instance=instance) + parent=parent, instance_id=instance_id, instance=instance + ) actual_request = channel.requests[0][1] assert expected_request == actual_request @@ -238,22 +233,23 @@ def test_create_instance_exception(self): # Setup Response error = status_pb2.Status() operation = operations_pb2.Operation( - name='operations/test_create_instance_exception', done=True) + name="operations/test_create_instance_exception", done=True + ) operation.error.CopyFrom(error) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1beta1.CloudRedisClient() # Setup Request - parent = client.location_path('[PROJECT]', '[LOCATION]') - instance_id = 'test_instance' + parent = client.location_path("[PROJECT]", "[LOCATION]") + instance_id = "test_instance" tier = enums.Instance.Tier.BASIC memory_size_gb = 1 - instance = {'tier': tier, 'memory_size_gb': memory_size_gb} + instance = {"tier": tier, "memory_size_gb": memory_size_gb} response = client.create_instance(parent, instance_id, instance) exception = response.exception() @@ -261,55 +257,53 @@ def test_create_instance_exception(self): def test_update_instance(self): # Setup Expected Response - name = 'name3373707' - display_name_2 = 'displayName21615000987' - location_id = 'locationId552319461' - alternative_location_id = 'alternativeLocationId-718920621' - redis_version = 'redisVersion-685310444' - reserved_ip_range = 'reservedIpRange-1082940580' - host = 'host3208616' + name = "name3373707" + display_name_2 = "displayName21615000987" + location_id = "locationId552319461" + alternative_location_id = "alternativeLocationId-718920621" + redis_version = "redisVersion-685310444" + reserved_ip_range = "reservedIpRange-1082940580" + host = "host3208616" port = 3446913 - current_location_id = 'currentLocationId1312712735' - status_message = 'statusMessage-239442758' + current_location_id = "currentLocationId1312712735" + status_message = "statusMessage-239442758" memory_size_gb_2 = 1493816946 - authorized_network = 'authorizedNetwork-1733809270' + authorized_network = "authorizedNetwork-1733809270" expected_response = { - 'name': name, - 'display_name': display_name_2, - 'location_id': location_id, - 'alternative_location_id': alternative_location_id, - 'redis_version': redis_version, - 'reserved_ip_range': reserved_ip_range, - 'host': host, - 'port': port, - 'current_location_id': current_location_id, - 'status_message': status_message, - 'memory_size_gb': memory_size_gb_2, - 'authorized_network': authorized_network + "name": name, + "display_name": display_name_2, + "location_id": location_id, + "alternative_location_id": alternative_location_id, + "redis_version": redis_version, + "reserved_ip_range": reserved_ip_range, + "host": host, + "port": port, + "current_location_id": current_location_id, + "status_message": status_message, + "memory_size_gb": memory_size_gb_2, + "authorized_network": authorized_network, } expected_response = cloud_redis_pb2.Instance(**expected_response) operation = operations_pb2.Operation( - name='operations/test_update_instance', done=True) + name="operations/test_update_instance", done=True + ) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1beta1.CloudRedisClient() # Setup Request - paths_element = 'display_name' - paths_element_2 = 'memory_size_gb' + paths_element = "display_name" + paths_element_2 = "memory_size_gb" paths = [paths_element, paths_element_2] - update_mask = {'paths': paths} - display_name = 'UpdatedDisplayName' + update_mask = {"paths": paths} + display_name = "UpdatedDisplayName" memory_size_gb = 4 - instance = { - 'display_name': display_name, - 'memory_size_gb': memory_size_gb - } + instance = {"display_name": display_name, "memory_size_gb": memory_size_gb} response = client.update_instance(update_mask, instance) result = response.result() @@ -317,7 +311,8 @@ def test_update_instance(self): assert len(channel.requests) == 1 expected_request = cloud_redis_pb2.UpdateInstanceRequest( - update_mask=update_mask, instance=instance) + update_mask=update_mask, instance=instance + ) actual_request = channel.requests[0][1] assert expected_request == actual_request @@ -325,27 +320,25 @@ def test_update_instance_exception(self): # Setup Response error = status_pb2.Status() operation = operations_pb2.Operation( - name='operations/test_update_instance_exception', done=True) + name="operations/test_update_instance_exception", done=True + ) operation.error.CopyFrom(error) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1beta1.CloudRedisClient() # Setup Request - paths_element = 'display_name' - paths_element_2 = 'memory_size_gb' + paths_element = "display_name" + paths_element_2 = "memory_size_gb" paths = [paths_element, paths_element_2] - update_mask = {'paths': paths} - display_name = 'UpdatedDisplayName' + update_mask = {"paths": paths} + display_name = "UpdatedDisplayName" memory_size_gb = 4 - instance = { - 'display_name': display_name, - 'memory_size_gb': memory_size_gb - } + instance = {"display_name": display_name, "memory_size_gb": memory_size_gb} response = client.update_instance(update_mask, instance) exception = response.exception() @@ -356,18 +349,19 @@ def test_delete_instance(self): expected_response = {} expected_response = empty_pb2.Empty(**expected_response) operation = operations_pb2.Operation( - name='operations/test_delete_instance', done=True) + name="operations/test_delete_instance", done=True + ) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1beta1.CloudRedisClient() # Setup Request - name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + name = client.instance_path("[PROJECT]", "[LOCATION]", "[INSTANCE]") response = client.delete_instance(name) result = response.result() @@ -382,18 +376,19 @@ def test_delete_instance_exception(self): # Setup Response error = status_pb2.Status() operation = operations_pb2.Operation( - name='operations/test_delete_instance_exception', done=True) + name="operations/test_delete_instance_exception", done=True + ) operation.error.CopyFrom(error) # Mock the API response channel = ChannelStub(responses=[operation]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = redis_v1beta1.CloudRedisClient() # Setup Request - name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + name = client.instance_path("[PROJECT]", "[LOCATION]", "[INSTANCE]") response = client.delete_instance(name) exception = response.exception()