From 7a84b3b9b8c206a0dc33ccc09821ffa8ee8c3ddd Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 14 May 2021 14:42:04 +0000 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.46.3 (#44) PiperOrigin-RevId: 373649163 Source-Link: https://github.com/googleapis/googleapis/commit/7e1b14e6c7a9ab96d2db7e4a131981f162446d34 Source-Link: https://github.com/googleapis/googleapis-gen/commit/0a3c7d272d697796db75857bac73905c68e498c3 fix: add async client to %name_%version/init.py chore: add autogenerated snippets chore: remove auth, policy, and options from the reserved names list feat: support self-signed JWT flow for service accounts chore: enable GAPIC metadata generation chore: sort subpackages in %namespace/%name/init.py --- docs/notebooks_v1beta1/notebook_service.rst | 1 - google/cloud/notebooks/__init__.py | 18 +- google/cloud/notebooks_v1beta1/__init__.py | 7 +- .../notebooks_v1beta1/gapic_metadata.json | 213 +++++ .../notebooks_v1beta1/services/__init__.py | 1 - .../services/notebook_service/__init__.py | 2 - .../services/notebook_service/async_client.py | 70 +- .../services/notebook_service/client.py | 111 +-- .../services/notebook_service/pagers.py | 6 +- .../notebook_service/transports/__init__.py | 2 - .../notebook_service/transports/base.py | 185 +++-- .../notebook_service/transports/grpc.py | 80 +- .../transports/grpc_asyncio.py | 93 ++- .../cloud/notebooks_v1beta1/types/__init__.py | 2 - .../notebooks_v1beta1/types/environment.py | 34 +- .../cloud/notebooks_v1beta1/types/instance.py | 79 +- .../cloud/notebooks_v1beta1/types/service.py | 150 ++-- tests/__init__.py | 15 + tests/unit/__init__.py | 15 + tests/unit/gapic/__init__.py | 15 + .../unit/gapic/notebooks_v1beta1/__init__.py | 1 - .../test_notebook_service.py | 782 ++++++++++-------- 22 files changed, 1050 insertions(+), 832 deletions(-) create mode 100644 google/cloud/notebooks_v1beta1/gapic_metadata.json create mode 100644 tests/__init__.py create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/gapic/__init__.py diff --git a/docs/notebooks_v1beta1/notebook_service.rst b/docs/notebooks_v1beta1/notebook_service.rst index 6f8cc21..79a8fea 100644 --- a/docs/notebooks_v1beta1/notebook_service.rst +++ b/docs/notebooks_v1beta1/notebook_service.rst @@ -5,7 +5,6 @@ NotebookService :members: :inherited-members: - .. automodule:: google.cloud.notebooks_v1beta1.services.notebook_service.pagers :members: :inherited-members: diff --git a/google/cloud/notebooks/__init__.py b/google/cloud/notebooks/__init__.py index 70533b4..2d3bf90 100644 --- a/google/cloud/notebooks/__init__.py +++ b/google/cloud/notebooks/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +14,13 @@ # limitations under the License. # -from google.cloud.notebooks_v1beta1.services.notebook_service.async_client import ( - NotebookServiceAsyncClient, -) from google.cloud.notebooks_v1beta1.services.notebook_service.client import ( NotebookServiceClient, ) +from google.cloud.notebooks_v1beta1.services.notebook_service.async_client import ( + NotebookServiceAsyncClient, +) + from google.cloud.notebooks_v1beta1.types.environment import ContainerImage from google.cloud.notebooks_v1beta1.types.environment import Environment from google.cloud.notebooks_v1beta1.types.environment import VmImage @@ -50,23 +50,24 @@ from google.cloud.notebooks_v1beta1.types.service import UpgradeInstanceRequest __all__ = ( + "NotebookServiceClient", + "NotebookServiceAsyncClient", "ContainerImage", + "Environment", + "VmImage", + "Instance", "CreateEnvironmentRequest", "CreateInstanceRequest", "DeleteEnvironmentRequest", "DeleteInstanceRequest", - "Environment", "GetEnvironmentRequest", "GetInstanceRequest", - "Instance", "IsInstanceUpgradeableRequest", "IsInstanceUpgradeableResponse", "ListEnvironmentsRequest", "ListEnvironmentsResponse", "ListInstancesRequest", "ListInstancesResponse", - "NotebookServiceAsyncClient", - "NotebookServiceClient", "OperationMetadata", "RegisterInstanceRequest", "ReportInstanceInfoRequest", @@ -78,5 +79,4 @@ "StopInstanceRequest", "UpgradeInstanceInternalRequest", "UpgradeInstanceRequest", - "VmImage", ) diff --git a/google/cloud/notebooks_v1beta1/__init__.py b/google/cloud/notebooks_v1beta1/__init__.py index 707961a..af872cb 100644 --- a/google/cloud/notebooks_v1beta1/__init__.py +++ b/google/cloud/notebooks_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.notebook_service import NotebookServiceClient +from .services.notebook_service import NotebookServiceAsyncClient + from .types.environment import ContainerImage from .types.environment import Environment from .types.environment import VmImage @@ -44,8 +45,8 @@ from .types.service import UpgradeInstanceInternalRequest from .types.service import UpgradeInstanceRequest - __all__ = ( + "NotebookServiceAsyncClient", "ContainerImage", "CreateEnvironmentRequest", "CreateInstanceRequest", @@ -61,6 +62,7 @@ "ListEnvironmentsResponse", "ListInstancesRequest", "ListInstancesResponse", + "NotebookServiceClient", "OperationMetadata", "RegisterInstanceRequest", "ReportInstanceInfoRequest", @@ -73,5 +75,4 @@ "UpgradeInstanceInternalRequest", "UpgradeInstanceRequest", "VmImage", - "NotebookServiceClient", ) diff --git a/google/cloud/notebooks_v1beta1/gapic_metadata.json b/google/cloud/notebooks_v1beta1/gapic_metadata.json new file mode 100644 index 0000000..b435e9c --- /dev/null +++ b/google/cloud/notebooks_v1beta1/gapic_metadata.json @@ -0,0 +1,213 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.notebooks_v1beta1", + "protoPackage": "google.cloud.notebooks.v1beta1", + "schema": "1.0", + "services": { + "NotebookService": { + "clients": { + "grpc": { + "libraryClient": "NotebookServiceClient", + "rpcs": { + "CreateEnvironment": { + "methods": [ + "create_environment" + ] + }, + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "DeleteEnvironment": { + "methods": [ + "delete_environment" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "GetEnvironment": { + "methods": [ + "get_environment" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "IsInstanceUpgradeable": { + "methods": [ + "is_instance_upgradeable" + ] + }, + "ListEnvironments": { + "methods": [ + "list_environments" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "RegisterInstance": { + "methods": [ + "register_instance" + ] + }, + "ReportInstanceInfo": { + "methods": [ + "report_instance_info" + ] + }, + "ResetInstance": { + "methods": [ + "reset_instance" + ] + }, + "SetInstanceAccelerator": { + "methods": [ + "set_instance_accelerator" + ] + }, + "SetInstanceLabels": { + "methods": [ + "set_instance_labels" + ] + }, + "SetInstanceMachineType": { + "methods": [ + "set_instance_machine_type" + ] + }, + "StartInstance": { + "methods": [ + "start_instance" + ] + }, + "StopInstance": { + "methods": [ + "stop_instance" + ] + }, + "UpgradeInstance": { + "methods": [ + "upgrade_instance" + ] + }, + "UpgradeInstanceInternal": { + "methods": [ + "upgrade_instance_internal" + ] + } + } + }, + "grpc-async": { + "libraryClient": "NotebookServiceAsyncClient", + "rpcs": { + "CreateEnvironment": { + "methods": [ + "create_environment" + ] + }, + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "DeleteEnvironment": { + "methods": [ + "delete_environment" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "GetEnvironment": { + "methods": [ + "get_environment" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "IsInstanceUpgradeable": { + "methods": [ + "is_instance_upgradeable" + ] + }, + "ListEnvironments": { + "methods": [ + "list_environments" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "RegisterInstance": { + "methods": [ + "register_instance" + ] + }, + "ReportInstanceInfo": { + "methods": [ + "report_instance_info" + ] + }, + "ResetInstance": { + "methods": [ + "reset_instance" + ] + }, + "SetInstanceAccelerator": { + "methods": [ + "set_instance_accelerator" + ] + }, + "SetInstanceLabels": { + "methods": [ + "set_instance_labels" + ] + }, + "SetInstanceMachineType": { + "methods": [ + "set_instance_machine_type" + ] + }, + "StartInstance": { + "methods": [ + "start_instance" + ] + }, + "StopInstance": { + "methods": [ + "stop_instance" + ] + }, + "UpgradeInstance": { + "methods": [ + "upgrade_instance" + ] + }, + "UpgradeInstanceInternal": { + "methods": [ + "upgrade_instance_internal" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/notebooks_v1beta1/services/__init__.py b/google/cloud/notebooks_v1beta1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/notebooks_v1beta1/services/__init__.py +++ b/google/cloud/notebooks_v1beta1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/__init__.py b/google/cloud/notebooks_v1beta1/services/notebook_service/__init__.py index 92c4e29..a17402b 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/__init__.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import NotebookServiceClient from .async_client import NotebookServiceAsyncClient diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/async_client.py b/google/cloud/notebooks_v1beta1/services/notebook_service/async_client.py index 98eb73d..18b6efd 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/async_client.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.api_core import operation # type: ignore @@ -34,9 +32,8 @@ from google.cloud.notebooks_v1beta1.types import environment from google.cloud.notebooks_v1beta1.types import instance from google.cloud.notebooks_v1beta1.types import service -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import NotebookServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import NotebookServiceGrpcAsyncIOTransport from .client import NotebookServiceClient @@ -54,31 +51,26 @@ class NotebookServiceAsyncClient: parse_environment_path = staticmethod(NotebookServiceClient.parse_environment_path) instance_path = staticmethod(NotebookServiceClient.instance_path) parse_instance_path = staticmethod(NotebookServiceClient.parse_instance_path) - common_billing_account_path = staticmethod( NotebookServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( NotebookServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(NotebookServiceClient.common_folder_path) parse_common_folder_path = staticmethod( NotebookServiceClient.parse_common_folder_path ) - common_organization_path = staticmethod( NotebookServiceClient.common_organization_path ) parse_common_organization_path = staticmethod( NotebookServiceClient.parse_common_organization_path ) - common_project_path = staticmethod(NotebookServiceClient.common_project_path) parse_common_project_path = staticmethod( NotebookServiceClient.parse_common_project_path ) - common_location_path = staticmethod(NotebookServiceClient.common_location_path) parse_common_location_path = staticmethod( NotebookServiceClient.parse_common_location_path @@ -86,7 +78,8 @@ class NotebookServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -101,7 +94,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -118,7 +111,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> NotebookServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: NotebookServiceTransport: The transport used by the client instance. @@ -132,12 +125,12 @@ def transport(self) -> NotebookServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, NotebookServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the notebook service client. + """Instantiates the notebook service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -169,7 +162,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = NotebookServiceClient( credentials=credentials, transport=transport, @@ -191,7 +183,6 @@ async def list_instances( request (:class:`google.cloud.notebooks_v1beta1.types.ListInstancesRequest`): The request object. Request for listing notebook instances. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -208,7 +199,6 @@ async def list_instances( """ # Create or coerce a protobuf request object. - request = service.ListInstancesRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -251,7 +241,6 @@ async def get_instance( request (:class:`google.cloud.notebooks_v1beta1.types.GetInstanceRequest`): The request object. Request for getting a notebook instance. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -265,7 +254,6 @@ async def get_instance( """ # Create or coerce a protobuf request object. - request = service.GetInstanceRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -303,7 +291,6 @@ async def create_instance( request (:class:`google.cloud.notebooks_v1beta1.types.CreateInstanceRequest`): The request object. Request for creating a notebook instance. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -320,7 +307,6 @@ async def create_instance( """ # Create or coerce a protobuf request object. - request = service.CreateInstanceRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -370,7 +356,6 @@ async def register_instance( request (:class:`google.cloud.notebooks_v1beta1.types.RegisterInstanceRequest`): The request object. Request for registering a notebook instance. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -387,7 +372,6 @@ async def register_instance( """ # Create or coerce a protobuf request object. - request = service.RegisterInstanceRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -432,7 +416,6 @@ async def set_instance_accelerator( request (:class:`google.cloud.notebooks_v1beta1.types.SetInstanceAcceleratorRequest`): The request object. Request for setting instance accelerator. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -449,7 +432,6 @@ async def set_instance_accelerator( """ # Create or coerce a protobuf request object. - request = service.SetInstanceAcceleratorRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -494,7 +476,6 @@ async def set_instance_machine_type( request (:class:`google.cloud.notebooks_v1beta1.types.SetInstanceMachineTypeRequest`): The request object. Request for setting instance machine type. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -511,7 +492,6 @@ async def set_instance_machine_type( """ # Create or coerce a protobuf request object. - request = service.SetInstanceMachineTypeRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -555,7 +535,6 @@ async def set_instance_labels( Args: request (:class:`google.cloud.notebooks_v1beta1.types.SetInstanceLabelsRequest`): The request object. Request for setting instance labels. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -572,7 +551,6 @@ async def set_instance_labels( """ # Create or coerce a protobuf request object. - request = service.SetInstanceLabelsRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -617,7 +595,6 @@ async def delete_instance( request (:class:`google.cloud.notebooks_v1beta1.types.DeleteInstanceRequest`): The request object. Request for deleting a notebook instance. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -644,7 +621,6 @@ async def delete_instance( """ # Create or coerce a protobuf request object. - request = service.DeleteInstanceRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -668,7 +644,7 @@ async def delete_instance( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=service.OperationMetadata, ) @@ -689,7 +665,6 @@ async def start_instance( request (:class:`google.cloud.notebooks_v1beta1.types.StartInstanceRequest`): The request object. Request for starting a notebook instance - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -706,7 +681,6 @@ async def start_instance( """ # Create or coerce a protobuf request object. - request = service.StartInstanceRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -751,7 +725,6 @@ async def stop_instance( request (:class:`google.cloud.notebooks_v1beta1.types.StopInstanceRequest`): The request object. Request for stopping a notebook instance - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -768,7 +741,6 @@ async def stop_instance( """ # Create or coerce a protobuf request object. - request = service.StopInstanceRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -813,7 +785,6 @@ async def reset_instance( request (:class:`google.cloud.notebooks_v1beta1.types.ResetInstanceRequest`): The request object. Request for reseting a notebook instance - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -830,7 +801,6 @@ async def reset_instance( """ # Create or coerce a protobuf request object. - request = service.ResetInstanceRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -879,7 +849,6 @@ async def report_instance_info( request (:class:`google.cloud.notebooks_v1beta1.types.ReportInstanceInfoRequest`): The request object. Request for notebook instances to report information to Notebooks API. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -896,7 +865,6 @@ async def report_instance_info( """ # Create or coerce a protobuf request object. - request = service.ReportInstanceInfoRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -941,7 +909,6 @@ async def is_instance_upgradeable( request (:class:`google.cloud.notebooks_v1beta1.types.IsInstanceUpgradeableRequest`): The request object. Request for checking if a notebook instance is upgradeable. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -955,7 +922,6 @@ async def is_instance_upgradeable( """ # Create or coerce a protobuf request object. - request = service.IsInstanceUpgradeableRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -994,7 +960,6 @@ async def upgrade_instance( request (:class:`google.cloud.notebooks_v1beta1.types.UpgradeInstanceRequest`): The request object. Request for upgrading a notebook instance - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1011,7 +976,6 @@ async def upgrade_instance( """ # Create or coerce a protobuf request object. - request = service.UpgradeInstanceRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -1058,7 +1022,6 @@ async def upgrade_instance_internal( request (:class:`google.cloud.notebooks_v1beta1.types.UpgradeInstanceInternalRequest`): The request object. Request for upgrading a notebook instance from within the VM - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1075,7 +1038,6 @@ async def upgrade_instance_internal( """ # Create or coerce a protobuf request object. - request = service.UpgradeInstanceInternalRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -1119,7 +1081,6 @@ async def list_environments( Args: request (:class:`google.cloud.notebooks_v1beta1.types.ListEnvironmentsRequest`): The request object. Request for listing environments. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1135,7 +1096,6 @@ async def list_environments( """ # Create or coerce a protobuf request object. - request = service.ListEnvironmentsRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -1178,7 +1138,6 @@ async def get_environment( request (:class:`google.cloud.notebooks_v1beta1.types.GetEnvironmentRequest`): The request object. Request for getting a notebook environment. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1193,7 +1152,6 @@ async def get_environment( """ # Create or coerce a protobuf request object. - request = service.GetEnvironmentRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -1230,7 +1188,6 @@ async def create_environment( request (:class:`google.cloud.notebooks_v1beta1.types.CreateEnvironmentRequest`): The request object. Request for creating a notebook environment. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1246,7 +1203,6 @@ async def create_environment( """ # Create or coerce a protobuf request object. - request = service.CreateEnvironmentRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -1291,7 +1247,6 @@ async def delete_environment( request (:class:`google.cloud.notebooks_v1beta1.types.DeleteEnvironmentRequest`): The request object. Request for deleting a notebook environment. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1318,7 +1273,6 @@ async def delete_environment( """ # Create or coerce a protobuf request object. - request = service.DeleteEnvironmentRequest(request) # Wrap the RPC method; this adds retry and timeout information, @@ -1342,7 +1296,7 @@ async def delete_environment( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=service.OperationMetadata, ) diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/client.py b/google/cloud/notebooks_v1beta1/services/notebook_service/client.py index 97acda4..3ab6f94 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/client.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -38,9 +36,8 @@ from google.cloud.notebooks_v1beta1.types import environment from google.cloud.notebooks_v1beta1.types import instance from google.cloud.notebooks_v1beta1.types import service -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import NotebookServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import NotebookServiceGrpcTransport from .transports.grpc_asyncio import NotebookServiceGrpcAsyncIOTransport @@ -61,7 +58,7 @@ class NotebookServiceClientMeta(type): _transport_registry["grpc_asyncio"] = NotebookServiceGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[NotebookServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -84,7 +81,8 @@ class NotebookServiceClient(metaclass=NotebookServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -118,7 +116,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -135,7 +134,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -154,23 +153,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> NotebookServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - NotebookServiceTransport: The transport used by the client instance. + NotebookServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def environment_path(project: str, environment: str,) -> str: - """Return a fully-qualified environment string.""" + """Returns a fully-qualified environment string.""" return "projects/{project}/environments/{environment}".format( project=project, environment=environment, ) @staticmethod def parse_environment_path(path: str) -> Dict[str, str]: - """Parse a environment path into its component segments.""" + """Parses a environment path into its component segments.""" m = re.match( r"^projects/(?P.+?)/environments/(?P.+?)$", path ) @@ -178,20 +178,20 @@ def parse_environment_path(path: str) -> Dict[str, str]: @staticmethod def instance_path(project: str, instance: str,) -> str: - """Return a fully-qualified instance string.""" + """Returns a fully-qualified instance string.""" return "projects/{project}/instances/{instance}".format( project=project, instance=instance, ) @staticmethod def parse_instance_path(path: str) -> Dict[str, str]: - """Parse a instance path into its component segments.""" + """Parses a instance path into its component segments.""" m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -204,7 +204,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -215,7 +215,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -226,7 +226,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -237,7 +237,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -251,12 +251,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, NotebookServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the notebook service client. + """Instantiates the notebook service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -311,9 +311,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -325,12 +326,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -345,8 +348,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -375,7 +378,6 @@ def list_instances( request (google.cloud.notebooks_v1beta1.types.ListInstancesRequest): The request object. Request for listing notebook instances. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -392,7 +394,6 @@ def list_instances( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.ListInstancesRequest. # There's no risk of modifying the input as we've already verified @@ -436,7 +437,6 @@ def get_instance( request (google.cloud.notebooks_v1beta1.types.GetInstanceRequest): The request object. Request for getting a notebook instance. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -450,7 +450,6 @@ def get_instance( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.GetInstanceRequest. # There's no risk of modifying the input as we've already verified @@ -489,7 +488,6 @@ def create_instance( request (google.cloud.notebooks_v1beta1.types.CreateInstanceRequest): The request object. Request for creating a notebook instance. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -506,7 +504,6 @@ def create_instance( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.CreateInstanceRequest. # There's no risk of modifying the input as we've already verified @@ -557,7 +554,6 @@ def register_instance( request (google.cloud.notebooks_v1beta1.types.RegisterInstanceRequest): The request object. Request for registering a notebook instance. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -574,7 +570,6 @@ def register_instance( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.RegisterInstanceRequest. # There's no risk of modifying the input as we've already verified @@ -620,7 +615,6 @@ def set_instance_accelerator( request (google.cloud.notebooks_v1beta1.types.SetInstanceAcceleratorRequest): The request object. Request for setting instance accelerator. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -637,7 +631,6 @@ def set_instance_accelerator( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.SetInstanceAcceleratorRequest. # There's no risk of modifying the input as we've already verified @@ -683,7 +676,6 @@ def set_instance_machine_type( request (google.cloud.notebooks_v1beta1.types.SetInstanceMachineTypeRequest): The request object. Request for setting instance machine type. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -700,7 +692,6 @@ def set_instance_machine_type( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.SetInstanceMachineTypeRequest. # There's no risk of modifying the input as we've already verified @@ -747,7 +738,6 @@ def set_instance_labels( Args: request (google.cloud.notebooks_v1beta1.types.SetInstanceLabelsRequest): The request object. Request for setting instance labels. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -764,7 +754,6 @@ def set_instance_labels( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.SetInstanceLabelsRequest. # There's no risk of modifying the input as we've already verified @@ -810,7 +799,6 @@ def delete_instance( request (google.cloud.notebooks_v1beta1.types.DeleteInstanceRequest): The request object. Request for deleting a notebook instance. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -837,7 +825,6 @@ def delete_instance( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.DeleteInstanceRequest. # There's no risk of modifying the input as we've already verified @@ -862,7 +849,7 @@ def delete_instance( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=service.OperationMetadata, ) @@ -883,7 +870,6 @@ def start_instance( request (google.cloud.notebooks_v1beta1.types.StartInstanceRequest): The request object. Request for starting a notebook instance - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -900,7 +886,6 @@ def start_instance( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.StartInstanceRequest. # There's no risk of modifying the input as we've already verified @@ -946,7 +931,6 @@ def stop_instance( request (google.cloud.notebooks_v1beta1.types.StopInstanceRequest): The request object. Request for stopping a notebook instance - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -963,7 +947,6 @@ def stop_instance( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.StopInstanceRequest. # There's no risk of modifying the input as we've already verified @@ -1009,7 +992,6 @@ def reset_instance( request (google.cloud.notebooks_v1beta1.types.ResetInstanceRequest): The request object. Request for reseting a notebook instance - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1026,7 +1008,6 @@ def reset_instance( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.ResetInstanceRequest. # There's no risk of modifying the input as we've already verified @@ -1076,7 +1057,6 @@ def report_instance_info( request (google.cloud.notebooks_v1beta1.types.ReportInstanceInfoRequest): The request object. Request for notebook instances to report information to Notebooks API. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1093,7 +1073,6 @@ def report_instance_info( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.ReportInstanceInfoRequest. # There's no risk of modifying the input as we've already verified @@ -1139,7 +1118,6 @@ def is_instance_upgradeable( request (google.cloud.notebooks_v1beta1.types.IsInstanceUpgradeableRequest): The request object. Request for checking if a notebook instance is upgradeable. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1153,7 +1131,6 @@ def is_instance_upgradeable( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.IsInstanceUpgradeableRequest. # There's no risk of modifying the input as we've already verified @@ -1193,7 +1170,6 @@ def upgrade_instance( request (google.cloud.notebooks_v1beta1.types.UpgradeInstanceRequest): The request object. Request for upgrading a notebook instance - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1210,7 +1186,6 @@ def upgrade_instance( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.UpgradeInstanceRequest. # There's no risk of modifying the input as we've already verified @@ -1258,7 +1233,6 @@ def upgrade_instance_internal( request (google.cloud.notebooks_v1beta1.types.UpgradeInstanceInternalRequest): The request object. Request for upgrading a notebook instance from within the VM - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1275,7 +1249,6 @@ def upgrade_instance_internal( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.UpgradeInstanceInternalRequest. # There's no risk of modifying the input as we've already verified @@ -1322,7 +1295,6 @@ def list_environments( Args: request (google.cloud.notebooks_v1beta1.types.ListEnvironmentsRequest): The request object. Request for listing environments. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1338,7 +1310,6 @@ def list_environments( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.ListEnvironmentsRequest. # There's no risk of modifying the input as we've already verified @@ -1382,7 +1353,6 @@ def get_environment( request (google.cloud.notebooks_v1beta1.types.GetEnvironmentRequest): The request object. Request for getting a notebook environment. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1397,7 +1367,6 @@ def get_environment( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.GetEnvironmentRequest. # There's no risk of modifying the input as we've already verified @@ -1435,7 +1404,6 @@ def create_environment( request (google.cloud.notebooks_v1beta1.types.CreateEnvironmentRequest): The request object. Request for creating a notebook environment. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1451,7 +1419,6 @@ def create_environment( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.CreateEnvironmentRequest. # There's no risk of modifying the input as we've already verified @@ -1497,7 +1464,6 @@ def delete_environment( request (google.cloud.notebooks_v1beta1.types.DeleteEnvironmentRequest): The request object. Request for deleting a notebook environment. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1524,7 +1490,6 @@ def delete_environment( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a service.DeleteEnvironmentRequest. # There's no risk of modifying the input as we've already verified @@ -1549,7 +1514,7 @@ def delete_environment( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=service.OperationMetadata, ) diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/pagers.py b/google/cloud/notebooks_v1beta1/services/notebook_service/pagers.py index ec305f6..d918331 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/pagers.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -119,7 +117,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -247,7 +245,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/__init__.py b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/__init__.py index bc1ba94..9c6f2a1 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/__init__.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/base.py b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/base.py index d72ee7b..affbf2d 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/base.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,23 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.notebooks_v1beta1.types import environment from google.cloud.notebooks_v1beta1.types import instance from google.cloud.notebooks_v1beta1.types import service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -39,27 +38,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class NotebookServiceTransport(abc.ABC): """Abstract transport class for NotebookService.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "notebooks.googleapis.com" + def __init__( self, *, - host: str = "notebooks.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -68,7 +81,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -82,29 +95,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -185,122 +245,119 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_instances( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListInstancesRequest], - typing.Union[ - service.ListInstancesResponse, - typing.Awaitable[service.ListInstancesResponse], - ], + Union[service.ListInstancesResponse, Awaitable[service.ListInstancesResponse]], ]: raise NotImplementedError() @property def get_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [service.GetInstanceRequest], - typing.Union[instance.Instance, typing.Awaitable[instance.Instance]], + Union[instance.Instance, Awaitable[instance.Instance]], ]: raise NotImplementedError() @property def create_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [service.CreateInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def register_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [service.RegisterInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def set_instance_accelerator( self, - ) -> typing.Callable[ + ) -> Callable[ [service.SetInstanceAcceleratorRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def set_instance_machine_type( self, - ) -> typing.Callable[ + ) -> Callable[ [service.SetInstanceMachineTypeRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def set_instance_labels( self, - ) -> typing.Callable[ + ) -> Callable[ [service.SetInstanceLabelsRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [service.DeleteInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def start_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [service.StartInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def stop_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [service.StopInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def reset_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ResetInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def report_instance_info( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ReportInstanceInfoRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def is_instance_upgradeable( self, - ) -> typing.Callable[ + ) -> Callable[ [service.IsInstanceUpgradeableRequest], - typing.Union[ + Union[ service.IsInstanceUpgradeableResponse, - typing.Awaitable[service.IsInstanceUpgradeableResponse], + Awaitable[service.IsInstanceUpgradeableResponse], ], ]: raise NotImplementedError() @@ -308,29 +365,29 @@ def is_instance_upgradeable( @property def upgrade_instance( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UpgradeInstanceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def upgrade_instance_internal( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UpgradeInstanceInternalRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def list_environments( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListEnvironmentsRequest], - typing.Union[ + Union[ service.ListEnvironmentsResponse, - typing.Awaitable[service.ListEnvironmentsResponse], + Awaitable[service.ListEnvironmentsResponse], ], ]: raise NotImplementedError() @@ -338,29 +395,27 @@ def list_environments( @property def get_environment( self, - ) -> typing.Callable[ + ) -> Callable[ [service.GetEnvironmentRequest], - typing.Union[ - environment.Environment, typing.Awaitable[environment.Environment] - ], + Union[environment.Environment, Awaitable[environment.Environment]], ]: raise NotImplementedError() @property def create_environment( self, - ) -> typing.Callable[ + ) -> Callable[ [service.CreateEnvironmentRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_environment( self, - ) -> typing.Callable[ + ) -> Callable[ [service.DeleteEnvironmentRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc.py b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc.py index 5aed906..fe6a527 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,15 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore @@ -30,8 +28,7 @@ from google.cloud.notebooks_v1beta1.types import environment from google.cloud.notebooks_v1beta1.types import instance from google.cloud.notebooks_v1beta1.types import service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import NotebookServiceTransport, DEFAULT_CLIENT_INFO @@ -54,7 +51,7 @@ def __init__( self, *, host: str = "notebooks.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -68,7 +65,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -179,7 +177,7 @@ def __init__( def create_channel( cls, host: str = "notebooks.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -210,13 +208,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -293,7 +293,7 @@ def get_instance(self) -> Callable[[service.GetInstanceRequest], instance.Instan @property def create_instance( self, - ) -> Callable[[service.CreateInstanceRequest], operations.Operation]: + ) -> Callable[[service.CreateInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the create instance method over gRPC. Creates a new Instance in a given project and @@ -313,14 +313,14 @@ def create_instance( self._stubs["create_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/CreateInstance", request_serializer=service.CreateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_instance"] @property def register_instance( self, - ) -> Callable[[service.RegisterInstanceRequest], operations.Operation]: + ) -> Callable[[service.RegisterInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the register instance method over gRPC. Registers an existing legacy notebook instance to the @@ -344,14 +344,14 @@ def register_instance( self._stubs["register_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/RegisterInstance", request_serializer=service.RegisterInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["register_instance"] @property def set_instance_accelerator( self, - ) -> Callable[[service.SetInstanceAcceleratorRequest], operations.Operation]: + ) -> Callable[[service.SetInstanceAcceleratorRequest], operations_pb2.Operation]: r"""Return a callable for the set instance accelerator method over gRPC. Updates the guest accelerators of a single Instance. @@ -370,14 +370,14 @@ def set_instance_accelerator( self._stubs["set_instance_accelerator"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/SetInstanceAccelerator", request_serializer=service.SetInstanceAcceleratorRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["set_instance_accelerator"] @property def set_instance_machine_type( self, - ) -> Callable[[service.SetInstanceMachineTypeRequest], operations.Operation]: + ) -> Callable[[service.SetInstanceMachineTypeRequest], operations_pb2.Operation]: r"""Return a callable for the set instance machine type method over gRPC. Updates the machine type of a single Instance. @@ -396,14 +396,14 @@ def set_instance_machine_type( self._stubs["set_instance_machine_type"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/SetInstanceMachineType", request_serializer=service.SetInstanceMachineTypeRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["set_instance_machine_type"] @property def set_instance_labels( self, - ) -> Callable[[service.SetInstanceLabelsRequest], operations.Operation]: + ) -> Callable[[service.SetInstanceLabelsRequest], operations_pb2.Operation]: r"""Return a callable for the set instance labels method over gRPC. Updates the labels of an Instance. @@ -422,14 +422,14 @@ def set_instance_labels( self._stubs["set_instance_labels"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/SetInstanceLabels", request_serializer=service.SetInstanceLabelsRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["set_instance_labels"] @property def delete_instance( self, - ) -> Callable[[service.DeleteInstanceRequest], operations.Operation]: + ) -> Callable[[service.DeleteInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the delete instance method over gRPC. Deletes a single Instance. @@ -448,14 +448,14 @@ def delete_instance( self._stubs["delete_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/DeleteInstance", request_serializer=service.DeleteInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_instance"] @property def start_instance( self, - ) -> Callable[[service.StartInstanceRequest], operations.Operation]: + ) -> Callable[[service.StartInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the start instance method over gRPC. Starts a notebook instance. @@ -474,14 +474,14 @@ def start_instance( self._stubs["start_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/StartInstance", request_serializer=service.StartInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["start_instance"] @property def stop_instance( self, - ) -> Callable[[service.StopInstanceRequest], operations.Operation]: + ) -> Callable[[service.StopInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the stop instance method over gRPC. Stops a notebook instance. @@ -500,14 +500,14 @@ def stop_instance( self._stubs["stop_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/StopInstance", request_serializer=service.StopInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["stop_instance"] @property def reset_instance( self, - ) -> Callable[[service.ResetInstanceRequest], operations.Operation]: + ) -> Callable[[service.ResetInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the reset instance method over gRPC. Resets a notebook instance. @@ -526,14 +526,14 @@ def reset_instance( self._stubs["reset_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/ResetInstance", request_serializer=service.ResetInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["reset_instance"] @property def report_instance_info( self, - ) -> Callable[[service.ReportInstanceInfoRequest], operations.Operation]: + ) -> Callable[[service.ReportInstanceInfoRequest], operations_pb2.Operation]: r"""Return a callable for the report instance info method over gRPC. Allows notebook instances to @@ -556,7 +556,7 @@ def report_instance_info( self._stubs["report_instance_info"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/ReportInstanceInfo", request_serializer=service.ReportInstanceInfoRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["report_instance_info"] @@ -591,7 +591,7 @@ def is_instance_upgradeable( @property def upgrade_instance( self, - ) -> Callable[[service.UpgradeInstanceRequest], operations.Operation]: + ) -> Callable[[service.UpgradeInstanceRequest], operations_pb2.Operation]: r"""Return a callable for the upgrade instance method over gRPC. Upgrades a notebook instance to the latest version. @@ -610,14 +610,14 @@ def upgrade_instance( self._stubs["upgrade_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/UpgradeInstance", request_serializer=service.UpgradeInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["upgrade_instance"] @property def upgrade_instance_internal( self, - ) -> Callable[[service.UpgradeInstanceInternalRequest], operations.Operation]: + ) -> Callable[[service.UpgradeInstanceInternalRequest], operations_pb2.Operation]: r"""Return a callable for the upgrade instance internal method over gRPC. Allows notebook instances to @@ -638,7 +638,7 @@ def upgrade_instance_internal( self._stubs["upgrade_instance_internal"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/UpgradeInstanceInternal", request_serializer=service.UpgradeInstanceInternalRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["upgrade_instance_internal"] @@ -697,7 +697,7 @@ def get_environment( @property def create_environment( self, - ) -> Callable[[service.CreateEnvironmentRequest], operations.Operation]: + ) -> Callable[[service.CreateEnvironmentRequest], operations_pb2.Operation]: r"""Return a callable for the create environment method over gRPC. Creates a new Environment. @@ -716,14 +716,14 @@ def create_environment( self._stubs["create_environment"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/CreateEnvironment", request_serializer=service.CreateEnvironmentRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_environment"] @property def delete_environment( self, - ) -> Callable[[service.DeleteEnvironmentRequest], operations.Operation]: + ) -> Callable[[service.DeleteEnvironmentRequest], operations_pb2.Operation]: r"""Return a callable for the delete environment method over gRPC. Deletes a single Environment. @@ -742,7 +742,7 @@ def delete_environment( self._stubs["delete_environment"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/DeleteEnvironment", request_serializer=service.DeleteEnvironmentRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_environment"] diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc_asyncio.py b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc_asyncio.py index 9cf81f5..a7b0fc3 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc_asyncio.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,16 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google.api_core import operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -31,8 +29,7 @@ from google.cloud.notebooks_v1beta1.types import environment from google.cloud.notebooks_v1beta1.types import instance from google.cloud.notebooks_v1beta1.types import service -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import NotebookServiceTransport, DEFAULT_CLIENT_INFO from .grpc import NotebookServiceGrpcTransport @@ -57,7 +54,7 @@ class NotebookServiceGrpcAsyncIOTransport(NotebookServiceTransport): def create_channel( cls, host: str = "notebooks.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -84,13 +81,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -98,7 +97,7 @@ def __init__( self, *, host: str = "notebooks.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -112,7 +111,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -171,7 +171,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -303,7 +302,7 @@ def get_instance( @property def create_instance( self, - ) -> Callable[[service.CreateInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.CreateInstanceRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the create instance method over gRPC. Creates a new Instance in a given project and @@ -323,14 +322,16 @@ def create_instance( self._stubs["create_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/CreateInstance", request_serializer=service.CreateInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_instance"] @property def register_instance( self, - ) -> Callable[[service.RegisterInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [service.RegisterInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the register instance method over gRPC. Registers an existing legacy notebook instance to the @@ -354,7 +355,7 @@ def register_instance( self._stubs["register_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/RegisterInstance", request_serializer=service.RegisterInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["register_instance"] @@ -362,7 +363,7 @@ def register_instance( def set_instance_accelerator( self, ) -> Callable[ - [service.SetInstanceAcceleratorRequest], Awaitable[operations.Operation] + [service.SetInstanceAcceleratorRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the set instance accelerator method over gRPC. @@ -382,7 +383,7 @@ def set_instance_accelerator( self._stubs["set_instance_accelerator"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/SetInstanceAccelerator", request_serializer=service.SetInstanceAcceleratorRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["set_instance_accelerator"] @@ -390,7 +391,7 @@ def set_instance_accelerator( def set_instance_machine_type( self, ) -> Callable[ - [service.SetInstanceMachineTypeRequest], Awaitable[operations.Operation] + [service.SetInstanceMachineTypeRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the set instance machine type method over gRPC. @@ -410,14 +411,16 @@ def set_instance_machine_type( self._stubs["set_instance_machine_type"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/SetInstanceMachineType", request_serializer=service.SetInstanceMachineTypeRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["set_instance_machine_type"] @property def set_instance_labels( self, - ) -> Callable[[service.SetInstanceLabelsRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [service.SetInstanceLabelsRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the set instance labels method over gRPC. Updates the labels of an Instance. @@ -436,14 +439,14 @@ def set_instance_labels( self._stubs["set_instance_labels"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/SetInstanceLabels", request_serializer=service.SetInstanceLabelsRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["set_instance_labels"] @property def delete_instance( self, - ) -> Callable[[service.DeleteInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.DeleteInstanceRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the delete instance method over gRPC. Deletes a single Instance. @@ -462,14 +465,14 @@ def delete_instance( self._stubs["delete_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/DeleteInstance", request_serializer=service.DeleteInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_instance"] @property def start_instance( self, - ) -> Callable[[service.StartInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.StartInstanceRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the start instance method over gRPC. Starts a notebook instance. @@ -488,14 +491,14 @@ def start_instance( self._stubs["start_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/StartInstance", request_serializer=service.StartInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["start_instance"] @property def stop_instance( self, - ) -> Callable[[service.StopInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.StopInstanceRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the stop instance method over gRPC. Stops a notebook instance. @@ -514,14 +517,14 @@ def stop_instance( self._stubs["stop_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/StopInstance", request_serializer=service.StopInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["stop_instance"] @property def reset_instance( self, - ) -> Callable[[service.ResetInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[[service.ResetInstanceRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the reset instance method over gRPC. Resets a notebook instance. @@ -540,14 +543,16 @@ def reset_instance( self._stubs["reset_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/ResetInstance", request_serializer=service.ResetInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["reset_instance"] @property def report_instance_info( self, - ) -> Callable[[service.ReportInstanceInfoRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [service.ReportInstanceInfoRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the report instance info method over gRPC. Allows notebook instances to @@ -570,7 +575,7 @@ def report_instance_info( self._stubs["report_instance_info"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/ReportInstanceInfo", request_serializer=service.ReportInstanceInfoRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["report_instance_info"] @@ -606,7 +611,9 @@ def is_instance_upgradeable( @property def upgrade_instance( self, - ) -> Callable[[service.UpgradeInstanceRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [service.UpgradeInstanceRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the upgrade instance method over gRPC. Upgrades a notebook instance to the latest version. @@ -625,7 +632,7 @@ def upgrade_instance( self._stubs["upgrade_instance"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/UpgradeInstance", request_serializer=service.UpgradeInstanceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["upgrade_instance"] @@ -633,7 +640,7 @@ def upgrade_instance( def upgrade_instance_internal( self, ) -> Callable[ - [service.UpgradeInstanceInternalRequest], Awaitable[operations.Operation] + [service.UpgradeInstanceInternalRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the upgrade instance internal method over gRPC. @@ -655,7 +662,7 @@ def upgrade_instance_internal( self._stubs["upgrade_instance_internal"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/UpgradeInstanceInternal", request_serializer=service.UpgradeInstanceInternalRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["upgrade_instance_internal"] @@ -716,7 +723,9 @@ def get_environment( @property def create_environment( self, - ) -> Callable[[service.CreateEnvironmentRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [service.CreateEnvironmentRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the create environment method over gRPC. Creates a new Environment. @@ -735,14 +744,16 @@ def create_environment( self._stubs["create_environment"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/CreateEnvironment", request_serializer=service.CreateEnvironmentRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_environment"] @property def delete_environment( self, - ) -> Callable[[service.DeleteEnvironmentRequest], Awaitable[operations.Operation]]: + ) -> Callable[ + [service.DeleteEnvironmentRequest], Awaitable[operations_pb2.Operation] + ]: r"""Return a callable for the delete environment method over gRPC. Deletes a single Environment. @@ -761,7 +772,7 @@ def delete_environment( self._stubs["delete_environment"] = self.grpc_channel.unary_unary( "/google.cloud.notebooks.v1beta1.NotebookService/DeleteEnvironment", request_serializer=service.DeleteEnvironmentRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_environment"] diff --git a/google/cloud/notebooks_v1beta1/types/__init__.py b/google/cloud/notebooks_v1beta1/types/__init__.py index 6b8325a..6982c3d 100644 --- a/google/cloud/notebooks_v1beta1/types/__init__.py +++ b/google/cloud/notebooks_v1beta1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .environment import ( ContainerImage, Environment, diff --git a/google/cloud/notebooks_v1beta1/types/environment.py b/google/cloud/notebooks_v1beta1/types/environment.py index 4e02c7e..5d2aeac 100644 --- a/google/cloud/notebooks_v1beta1/types/environment.py +++ b/google/cloud/notebooks_v1beta1/types/environment.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -55,23 +52,17 @@ class Environment(proto.Message): environment was created. """ - name = proto.Field(proto.STRING, number=1) - - display_name = proto.Field(proto.STRING, number=2) - - description = proto.Field(proto.STRING, number=3) - + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + description = proto.Field(proto.STRING, number=3,) vm_image = proto.Field( proto.MESSAGE, number=6, oneof="image_type", message="VmImage", ) - container_image = proto.Field( proto.MESSAGE, number=7, oneof="image_type", message="ContainerImage", ) - - post_startup_script = proto.Field(proto.STRING, number=8) - - create_time = proto.Field(proto.MESSAGE, number=9, message=timestamp.Timestamp,) + post_startup_script = proto.Field(proto.STRING, number=8,) + create_time = proto.Field(proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp,) class VmImage(proto.Message): @@ -90,11 +81,9 @@ class VmImage(proto.Message): the newest image in this family will be used. """ - project = proto.Field(proto.STRING, number=1) - - image_name = proto.Field(proto.STRING, number=2, oneof="image") - - image_family = proto.Field(proto.STRING, number=3, oneof="image") + project = proto.Field(proto.STRING, number=1,) + image_name = proto.Field(proto.STRING, number=2, oneof="image",) + image_family = proto.Field(proto.STRING, number=3, oneof="image",) class ContainerImage(proto.Message): @@ -110,9 +99,8 @@ class ContainerImage(proto.Message): specified, this defaults to the latest tag. """ - repository = proto.Field(proto.STRING, number=1) - - tag = proto.Field(proto.STRING, number=2) + repository = proto.Field(proto.STRING, number=1,) + tag = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/notebooks_v1beta1/types/instance.py b/google/cloud/notebooks_v1beta1/types/instance.py index 636825e..3f862be 100644 --- a/google/cloud/notebooks_v1beta1/types/instance.py +++ b/google/cloud/notebooks_v1beta1/types/instance.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.notebooks_v1beta1.types import environment -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -29,7 +26,6 @@ class Instance(proto.Message): r"""The definition of a notebook instance. - Attributes: name (str): Output only. The name of this notebook instance. Format: @@ -198,71 +194,48 @@ class AcceleratorConfig(proto.Message): """ type_ = proto.Field(proto.ENUM, number=1, enum="Instance.AcceleratorType",) + core_count = proto.Field(proto.INT64, number=2,) - core_count = proto.Field(proto.INT64, number=2) - - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) vm_image = proto.Field( proto.MESSAGE, number=2, oneof="environment", message=environment.VmImage, ) - container_image = proto.Field( proto.MESSAGE, number=3, oneof="environment", message=environment.ContainerImage, ) - - post_startup_script = proto.Field(proto.STRING, number=4) - - proxy_uri = proto.Field(proto.STRING, number=5) - - instance_owners = proto.RepeatedField(proto.STRING, number=6) - - service_account = proto.Field(proto.STRING, number=7) - - machine_type = proto.Field(proto.STRING, number=8) - + post_startup_script = proto.Field(proto.STRING, number=4,) + proxy_uri = proto.Field(proto.STRING, number=5,) + instance_owners = proto.RepeatedField(proto.STRING, number=6,) + service_account = proto.Field(proto.STRING, number=7,) + machine_type = proto.Field(proto.STRING, number=8,) accelerator_config = proto.Field( proto.MESSAGE, number=9, message=AcceleratorConfig, ) - state = proto.Field(proto.ENUM, number=10, enum=State,) - - install_gpu_driver = proto.Field(proto.BOOL, number=11) - - custom_gpu_driver_path = proto.Field(proto.STRING, number=12) - + install_gpu_driver = proto.Field(proto.BOOL, number=11,) + custom_gpu_driver_path = proto.Field(proto.STRING, number=12,) boot_disk_type = proto.Field(proto.ENUM, number=13, enum=DiskType,) - - boot_disk_size_gb = proto.Field(proto.INT64, number=14) - + boot_disk_size_gb = proto.Field(proto.INT64, number=14,) data_disk_type = proto.Field(proto.ENUM, number=25, enum=DiskType,) - - data_disk_size_gb = proto.Field(proto.INT64, number=26) - - no_remove_data_disk = proto.Field(proto.BOOL, number=27) - + data_disk_size_gb = proto.Field(proto.INT64, number=26,) + no_remove_data_disk = proto.Field(proto.BOOL, number=27,) disk_encryption = proto.Field(proto.ENUM, number=15, enum=DiskEncryption,) - - kms_key = proto.Field(proto.STRING, number=16) - - no_public_ip = proto.Field(proto.BOOL, number=17) - - no_proxy_access = proto.Field(proto.BOOL, number=18) - - network = proto.Field(proto.STRING, number=19) - - subnet = proto.Field(proto.STRING, number=20) - - labels = proto.MapField(proto.STRING, proto.STRING, number=21) - - metadata = proto.MapField(proto.STRING, proto.STRING, number=22) - - create_time = proto.Field(proto.MESSAGE, number=23, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=24, message=timestamp.Timestamp,) + kms_key = proto.Field(proto.STRING, number=16,) + no_public_ip = proto.Field(proto.BOOL, number=17,) + no_proxy_access = proto.Field(proto.BOOL, number=18,) + network = proto.Field(proto.STRING, number=19,) + subnet = proto.Field(proto.STRING, number=20,) + labels = proto.MapField(proto.STRING, proto.STRING, number=21,) + metadata = proto.MapField(proto.STRING, proto.STRING, number=22,) + create_time = proto.Field( + proto.MESSAGE, number=23, message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, number=24, message=timestamp_pb2.Timestamp, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/notebooks_v1beta1/types/service.py b/google/cloud/notebooks_v1beta1/types/service.py index ddabeea..e25802a 100644 --- a/google/cloud/notebooks_v1beta1/types/service.py +++ b/google/cloud/notebooks_v1beta1/types/service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.notebooks_v1beta1.types import environment as gcn_environment from google.cloud.notebooks_v1beta1.types import instance as gcn_instance -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -55,7 +52,6 @@ class OperationMetadata(proto.Message): r"""Represents the metadata of the long-running operation. - Attributes: create_time (google.protobuf.timestamp_pb2.Timestamp): The time the operation was created. @@ -81,26 +77,18 @@ class OperationMetadata(proto.Message): API endpoint name of this operation. """ - create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - target = proto.Field(proto.STRING, number=3) - - verb = proto.Field(proto.STRING, number=4) - - status_message = proto.Field(proto.STRING, number=5) - - requested_cancellation = proto.Field(proto.BOOL, number=6) - - api_version = proto.Field(proto.STRING, number=7) - - endpoint = proto.Field(proto.STRING, number=8) + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + target = proto.Field(proto.STRING, number=3,) + verb = proto.Field(proto.STRING, number=4,) + status_message = proto.Field(proto.STRING, number=5,) + requested_cancellation = proto.Field(proto.BOOL, number=6,) + api_version = proto.Field(proto.STRING, number=7,) + endpoint = proto.Field(proto.STRING, number=8,) class ListInstancesRequest(proto.Message): r"""Request for listing notebook instances. - Attributes: parent (str): Required. Format: @@ -112,16 +100,13 @@ class ListInstancesRequest(proto.Message): used to continue listing from the last result. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) class ListInstancesResponse(proto.Message): r"""Response for listing notebook instances. - Attributes: instances (Sequence[google.cloud.notebooks_v1beta1.types.Instance]): A list of returned instances. @@ -142,27 +127,23 @@ def raw_page(self): instances = proto.RepeatedField( proto.MESSAGE, number=1, message=gcn_instance.Instance, ) - - next_page_token = proto.Field(proto.STRING, number=2) - - unreachable = proto.RepeatedField(proto.STRING, number=3) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) class GetInstanceRequest(proto.Message): r"""Request for getting a notebook instance. - Attributes: name (str): Required. Format: ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CreateInstanceRequest(proto.Message): r"""Request for creating a notebook instance. - Attributes: parent (str): Required. Format: @@ -174,16 +155,13 @@ class CreateInstanceRequest(proto.Message): Required. The instance to be created. """ - parent = proto.Field(proto.STRING, number=1) - - instance_id = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + instance_id = proto.Field(proto.STRING, number=2,) instance = proto.Field(proto.MESSAGE, number=3, message=gcn_instance.Instance,) class RegisterInstanceRequest(proto.Message): r"""Request for registering a notebook instance. - Attributes: parent (str): Required. Format: @@ -196,14 +174,12 @@ class RegisterInstanceRequest(proto.Message): character cannot be a dash. """ - parent = proto.Field(proto.STRING, number=1) - - instance_id = proto.Field(proto.STRING, number=2) + parent = proto.Field(proto.STRING, number=1,) + instance_id = proto.Field(proto.STRING, number=2,) class SetInstanceAcceleratorRequest(proto.Message): r"""Request for setting instance accelerator. - Attributes: name (str): Required. Format: @@ -218,18 +194,15 @@ class SetInstanceAcceleratorRequest(proto.Message): to find a valid combination. TPUs are not supported. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) type_ = proto.Field( proto.ENUM, number=2, enum=gcn_instance.Instance.AcceleratorType, ) - - core_count = proto.Field(proto.INT64, number=3) + core_count = proto.Field(proto.INT64, number=3,) class SetInstanceMachineTypeRequest(proto.Message): r"""Request for setting instance machine type. - Attributes: name (str): Required. Format: @@ -239,14 +212,12 @@ class SetInstanceMachineTypeRequest(proto.Message): type `__. """ - name = proto.Field(proto.STRING, number=1) - - machine_type = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + machine_type = proto.Field(proto.STRING, number=2,) class SetInstanceLabelsRequest(proto.Message): r"""Request for setting instance labels. - Attributes: name (str): Required. Format: @@ -257,57 +228,52 @@ class SetInstanceLabelsRequest(proto.Message): method """ - name = proto.Field(proto.STRING, number=1) - - labels = proto.MapField(proto.STRING, proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + labels = proto.MapField(proto.STRING, proto.STRING, number=2,) class DeleteInstanceRequest(proto.Message): r"""Request for deleting a notebook instance. - Attributes: name (str): Required. Format: ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class StartInstanceRequest(proto.Message): r"""Request for starting a notebook instance - Attributes: name (str): Required. Format: ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class StopInstanceRequest(proto.Message): r"""Request for stopping a notebook instance - Attributes: name (str): Required. Format: ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ResetInstanceRequest(proto.Message): r"""Request for reseting a notebook instance - Attributes: name (str): Required. Format: ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ReportInstanceInfoRequest(proto.Message): @@ -328,28 +294,24 @@ class ReportInstanceInfoRequest(proto.Message): will be merged to the instance metadata store """ - name = proto.Field(proto.STRING, number=1) - - vm_id = proto.Field(proto.STRING, number=2) - - metadata = proto.MapField(proto.STRING, proto.STRING, number=3) + name = proto.Field(proto.STRING, number=1,) + vm_id = proto.Field(proto.STRING, number=2,) + metadata = proto.MapField(proto.STRING, proto.STRING, number=3,) class IsInstanceUpgradeableRequest(proto.Message): r"""Request for checking if a notebook instance is upgradeable. - Attributes: notebook_instance (str): Required. Format: ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - notebook_instance = proto.Field(proto.STRING, number=1) + notebook_instance = proto.Field(proto.STRING, number=1,) class IsInstanceUpgradeableResponse(proto.Message): r"""Response for checking if a notebook instance is upgradeable. - Attributes: upgradeable (bool): If an instance is upgradeable. @@ -361,28 +323,24 @@ class IsInstanceUpgradeableResponse(proto.Message): Additional information about upgrade. """ - upgradeable = proto.Field(proto.BOOL, number=1) - - upgrade_version = proto.Field(proto.STRING, number=2) - - upgrade_info = proto.Field(proto.STRING, number=3) + upgradeable = proto.Field(proto.BOOL, number=1,) + upgrade_version = proto.Field(proto.STRING, number=2,) + upgrade_info = proto.Field(proto.STRING, number=3,) class UpgradeInstanceRequest(proto.Message): r"""Request for upgrading a notebook instance - Attributes: name (str): Required. Format: ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpgradeInstanceInternalRequest(proto.Message): r"""Request for upgrading a notebook instance from within the VM - Attributes: name (str): Required. Format: @@ -394,14 +352,12 @@ class UpgradeInstanceInternalRequest(proto.Message): instance-identity """ - name = proto.Field(proto.STRING, number=1) - - vm_id = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + vm_id = proto.Field(proto.STRING, number=2,) class ListEnvironmentsRequest(proto.Message): r"""Request for listing environments. - Attributes: parent (str): Required. Format: @@ -413,16 +369,13 @@ class ListEnvironmentsRequest(proto.Message): used to continue listing from the last result. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) class ListEnvironmentsResponse(proto.Message): r"""Response for listing environments. - Attributes: environments (Sequence[google.cloud.notebooks_v1beta1.types.Environment]): A list of returned environments. @@ -441,27 +394,23 @@ def raw_page(self): environments = proto.RepeatedField( proto.MESSAGE, number=1, message=gcn_environment.Environment, ) - - next_page_token = proto.Field(proto.STRING, number=2) - - unreachable = proto.RepeatedField(proto.STRING, number=3) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) class GetEnvironmentRequest(proto.Message): r"""Request for getting a notebook environment. - Attributes: name (str): Required. Format: ``projects/{project_id}/locations/{location}/environments/{environment_id}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CreateEnvironmentRequest(proto.Message): r"""Request for creating a notebook environment. - Attributes: parent (str): Required. Format: @@ -476,10 +425,8 @@ class CreateEnvironmentRequest(proto.Message): Required. The environment to be created. """ - parent = proto.Field(proto.STRING, number=1) - - environment_id = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + environment_id = proto.Field(proto.STRING, number=2,) environment = proto.Field( proto.MESSAGE, number=3, message=gcn_environment.Environment, ) @@ -487,14 +434,13 @@ class CreateEnvironmentRequest(proto.Message): class DeleteEnvironmentRequest(proto.Message): r"""Request for deleting a notebook environment. - Attributes: name (str): Required. Format: ``projects/{project_id}/locations/{location}/environments/{environment_id}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/gapic/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/notebooks_v1beta1/__init__.py b/tests/unit/gapic/notebooks_v1beta1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/notebooks_v1beta1/__init__.py +++ b/tests/unit/gapic/notebooks_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/notebooks_v1beta1/test_notebook_service.py b/tests/unit/gapic/notebooks_v1beta1/test_notebook_service.py index 97a18c7..d09166d 100644 --- a/tests/unit/gapic/notebooks_v1beta1/test_notebook_service.py +++ b/tests/unit/gapic/notebooks_v1beta1/test_notebook_service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,16 +23,16 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import future from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.notebooks_v1beta1.services.notebook_service import ( NotebookServiceAsyncClient, @@ -43,12 +42,42 @@ ) from google.cloud.notebooks_v1beta1.services.notebook_service import pagers from google.cloud.notebooks_v1beta1.services.notebook_service import transports +from google.cloud.notebooks_v1beta1.services.notebook_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.notebooks_v1beta1.services.notebook_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.notebooks_v1beta1.types import environment from google.cloud.notebooks_v1beta1.types import instance from google.cloud.notebooks_v1beta1.types import service from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -99,7 +128,7 @@ def test__get_default_mtls_endpoint(): "client_class", [NotebookServiceClient, NotebookServiceAsyncClient,] ) def test_notebook_service_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -116,7 +145,7 @@ def test_notebook_service_client_from_service_account_info(client_class): "client_class", [NotebookServiceClient, NotebookServiceAsyncClient,] ) def test_notebook_service_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -169,7 +198,7 @@ def test_notebook_service_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(NotebookServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -467,7 +496,7 @@ def test_list_instances( transport: str = "grpc", request_type=service.ListInstancesRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -480,21 +509,16 @@ def test_list_instances( call.return_value = service.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] == service.ListInstancesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstancesPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -506,7 +530,7 @@ def test_list_instances_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -514,7 +538,6 @@ def test_list_instances_empty_call(): client.list_instances() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListInstancesRequest() @@ -523,7 +546,7 @@ async def test_list_instances_async( transport: str = "grpc_asyncio", request_type=service.ListInstancesRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -539,20 +562,16 @@ async def test_list_instances_async( unreachable=["unreachable_value"], ) ) - response = await client.list_instances(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListInstancesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListInstancesAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -562,17 +581,17 @@ async def test_list_instances_async_from_dict(): def test_list_instances_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListInstancesRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: call.return_value = service.ListInstancesResponse() - client.list_instances(request) # Establish that the underlying gRPC stub method was called. @@ -587,11 +606,14 @@ def test_list_instances_field_headers(): @pytest.mark.asyncio async def test_list_instances_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListInstancesRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -599,7 +621,6 @@ async def test_list_instances_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListInstancesResponse() ) - await client.list_instances(request) # Establish that the underlying gRPC stub method was called. @@ -613,7 +634,7 @@ async def test_list_instances_field_headers_async(): def test_list_instances_pager(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials,) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: @@ -651,7 +672,7 @@ def test_list_instances_pager(): def test_list_instances_pages(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials,) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: @@ -681,7 +702,9 @@ def test_list_instances_pages(): @pytest.mark.asyncio async def test_list_instances_async_pager(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -718,7 +741,9 @@ async def test_list_instances_async_pager(): @pytest.mark.asyncio async def test_list_instances_async_pages(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -752,7 +777,7 @@ async def test_list_instances_async_pages(): def test_get_instance(transport: str = "grpc", request_type=service.GetInstanceRequest): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -785,57 +810,34 @@ def test_get_instance(transport: str = "grpc", request_type=service.GetInstanceR subnet="subnet_value", vm_image=environment.VmImage(project="project_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] == service.GetInstanceRequest() # Establish that the response is the type that we expect. - assert isinstance(response, instance.Instance) - assert response.name == "name_value" - assert response.post_startup_script == "post_startup_script_value" - assert response.proxy_uri == "proxy_uri_value" - assert response.instance_owners == ["instance_owners_value"] - assert response.service_account == "service_account_value" - assert response.machine_type == "machine_type_value" - assert response.state == instance.Instance.State.STARTING - assert response.install_gpu_driver is True - assert response.custom_gpu_driver_path == "custom_gpu_driver_path_value" - assert response.boot_disk_type == instance.Instance.DiskType.PD_STANDARD - assert response.boot_disk_size_gb == 1792 - assert response.data_disk_type == instance.Instance.DiskType.PD_STANDARD - assert response.data_disk_size_gb == 1766 - assert response.no_remove_data_disk is True - assert response.disk_encryption == instance.Instance.DiskEncryption.GMEK - assert response.kms_key == "kms_key_value" - assert response.no_public_ip is True - assert response.no_proxy_access is True - assert response.network == "network_value" - assert response.subnet == "subnet_value" @@ -847,7 +849,7 @@ def test_get_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -855,7 +857,6 @@ def test_get_instance_empty_call(): client.get_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetInstanceRequest() @@ -864,7 +865,7 @@ async def test_get_instance_async( transport: str = "grpc_asyncio", request_type=service.GetInstanceRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -898,56 +899,34 @@ async def test_get_instance_async( subnet="subnet_value", ) ) - response = await client.get_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, instance.Instance) - assert response.name == "name_value" - assert response.post_startup_script == "post_startup_script_value" - assert response.proxy_uri == "proxy_uri_value" - assert response.instance_owners == ["instance_owners_value"] - assert response.service_account == "service_account_value" - assert response.machine_type == "machine_type_value" - assert response.state == instance.Instance.State.STARTING - assert response.install_gpu_driver is True - assert response.custom_gpu_driver_path == "custom_gpu_driver_path_value" - assert response.boot_disk_type == instance.Instance.DiskType.PD_STANDARD - assert response.boot_disk_size_gb == 1792 - assert response.data_disk_type == instance.Instance.DiskType.PD_STANDARD - assert response.data_disk_size_gb == 1766 - assert response.no_remove_data_disk is True - assert response.disk_encryption == instance.Instance.DiskEncryption.GMEK - assert response.kms_key == "kms_key_value" - assert response.no_public_ip is True - assert response.no_proxy_access is True - assert response.network == "network_value" - assert response.subnet == "subnet_value" @@ -957,17 +936,17 @@ async def test_get_instance_async_from_dict(): def test_get_instance_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_instance), "__call__") as call: call.return_value = instance.Instance() - client.get_instance(request) # Establish that the underlying gRPC stub method was called. @@ -982,17 +961,19 @@ def test_get_instance_field_headers(): @pytest.mark.asyncio async def test_get_instance_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(instance.Instance()) - await client.get_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1009,7 +990,7 @@ def test_create_instance( transport: str = "grpc", request_type=service.CreateInstanceRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1020,13 +1001,11 @@ def test_create_instance( with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateInstanceRequest() # Establish that the response is the type that we expect. @@ -1041,7 +1020,7 @@ def test_create_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1049,7 +1028,6 @@ def test_create_instance_empty_call(): client.create_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateInstanceRequest() @@ -1058,7 +1036,7 @@ async def test_create_instance_async( transport: str = "grpc_asyncio", request_type=service.CreateInstanceRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1071,13 +1049,11 @@ async def test_create_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateInstanceRequest() # Establish that the response is the type that we expect. @@ -1090,17 +1066,17 @@ async def test_create_instance_async_from_dict(): def test_create_instance_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateInstanceRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1115,11 +1091,14 @@ def test_create_instance_field_headers(): @pytest.mark.asyncio async def test_create_instance_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateInstanceRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1127,7 +1106,6 @@ async def test_create_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1144,7 +1122,7 @@ def test_register_instance( transport: str = "grpc", request_type=service.RegisterInstanceRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1157,13 +1135,11 @@ def test_register_instance( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.register_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] == service.RegisterInstanceRequest() # Establish that the response is the type that we expect. @@ -1178,7 +1154,7 @@ def test_register_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1188,7 +1164,6 @@ def test_register_instance_empty_call(): client.register_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.RegisterInstanceRequest() @@ -1197,7 +1172,7 @@ async def test_register_instance_async( transport: str = "grpc_asyncio", request_type=service.RegisterInstanceRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1212,13 +1187,11 @@ async def test_register_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.register_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.RegisterInstanceRequest() # Establish that the response is the type that we expect. @@ -1231,11 +1204,12 @@ async def test_register_instance_async_from_dict(): def test_register_instance_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.RegisterInstanceRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1243,7 +1217,6 @@ def test_register_instance_field_headers(): type(client.transport.register_instance), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.register_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1258,11 +1231,14 @@ def test_register_instance_field_headers(): @pytest.mark.asyncio async def test_register_instance_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.RegisterInstanceRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1272,7 +1248,6 @@ async def test_register_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.register_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1289,7 +1264,7 @@ def test_set_instance_accelerator( transport: str = "grpc", request_type=service.SetInstanceAcceleratorRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1302,13 +1277,11 @@ def test_set_instance_accelerator( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.set_instance_accelerator(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.SetInstanceAcceleratorRequest() # Establish that the response is the type that we expect. @@ -1323,7 +1296,7 @@ def test_set_instance_accelerator_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1333,7 +1306,6 @@ def test_set_instance_accelerator_empty_call(): client.set_instance_accelerator() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.SetInstanceAcceleratorRequest() @@ -1342,7 +1314,7 @@ async def test_set_instance_accelerator_async( transport: str = "grpc_asyncio", request_type=service.SetInstanceAcceleratorRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1357,13 +1329,11 @@ async def test_set_instance_accelerator_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.set_instance_accelerator(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.SetInstanceAcceleratorRequest() # Establish that the response is the type that we expect. @@ -1376,11 +1346,12 @@ async def test_set_instance_accelerator_async_from_dict(): def test_set_instance_accelerator_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.SetInstanceAcceleratorRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1388,7 +1359,6 @@ def test_set_instance_accelerator_field_headers(): type(client.transport.set_instance_accelerator), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.set_instance_accelerator(request) # Establish that the underlying gRPC stub method was called. @@ -1403,11 +1373,14 @@ def test_set_instance_accelerator_field_headers(): @pytest.mark.asyncio async def test_set_instance_accelerator_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.SetInstanceAcceleratorRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1417,7 +1390,6 @@ async def test_set_instance_accelerator_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.set_instance_accelerator(request) # Establish that the underlying gRPC stub method was called. @@ -1434,7 +1406,7 @@ def test_set_instance_machine_type( transport: str = "grpc", request_type=service.SetInstanceMachineTypeRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1447,13 +1419,11 @@ def test_set_instance_machine_type( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.set_instance_machine_type(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.SetInstanceMachineTypeRequest() # Establish that the response is the type that we expect. @@ -1468,7 +1438,7 @@ def test_set_instance_machine_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1478,7 +1448,6 @@ def test_set_instance_machine_type_empty_call(): client.set_instance_machine_type() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.SetInstanceMachineTypeRequest() @@ -1487,7 +1456,7 @@ async def test_set_instance_machine_type_async( transport: str = "grpc_asyncio", request_type=service.SetInstanceMachineTypeRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1502,13 +1471,11 @@ async def test_set_instance_machine_type_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.set_instance_machine_type(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.SetInstanceMachineTypeRequest() # Establish that the response is the type that we expect. @@ -1521,11 +1488,12 @@ async def test_set_instance_machine_type_async_from_dict(): def test_set_instance_machine_type_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.SetInstanceMachineTypeRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1533,7 +1501,6 @@ def test_set_instance_machine_type_field_headers(): type(client.transport.set_instance_machine_type), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.set_instance_machine_type(request) # Establish that the underlying gRPC stub method was called. @@ -1548,11 +1515,14 @@ def test_set_instance_machine_type_field_headers(): @pytest.mark.asyncio async def test_set_instance_machine_type_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.SetInstanceMachineTypeRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1562,7 +1532,6 @@ async def test_set_instance_machine_type_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.set_instance_machine_type(request) # Establish that the underlying gRPC stub method was called. @@ -1579,7 +1548,7 @@ def test_set_instance_labels( transport: str = "grpc", request_type=service.SetInstanceLabelsRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1592,13 +1561,11 @@ def test_set_instance_labels( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.set_instance_labels(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.SetInstanceLabelsRequest() # Establish that the response is the type that we expect. @@ -1613,7 +1580,7 @@ def test_set_instance_labels_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1623,7 +1590,6 @@ def test_set_instance_labels_empty_call(): client.set_instance_labels() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.SetInstanceLabelsRequest() @@ -1632,7 +1598,7 @@ async def test_set_instance_labels_async( transport: str = "grpc_asyncio", request_type=service.SetInstanceLabelsRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1647,13 +1613,11 @@ async def test_set_instance_labels_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.set_instance_labels(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.SetInstanceLabelsRequest() # Establish that the response is the type that we expect. @@ -1666,11 +1630,12 @@ async def test_set_instance_labels_async_from_dict(): def test_set_instance_labels_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.SetInstanceLabelsRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1678,7 +1643,6 @@ def test_set_instance_labels_field_headers(): type(client.transport.set_instance_labels), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.set_instance_labels(request) # Establish that the underlying gRPC stub method was called. @@ -1693,11 +1657,14 @@ def test_set_instance_labels_field_headers(): @pytest.mark.asyncio async def test_set_instance_labels_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.SetInstanceLabelsRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1707,7 +1674,6 @@ async def test_set_instance_labels_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.set_instance_labels(request) # Establish that the underlying gRPC stub method was called. @@ -1724,7 +1690,7 @@ def test_delete_instance( transport: str = "grpc", request_type=service.DeleteInstanceRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1735,13 +1701,11 @@ def test_delete_instance( with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteInstanceRequest() # Establish that the response is the type that we expect. @@ -1756,7 +1720,7 @@ def test_delete_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1764,7 +1728,6 @@ def test_delete_instance_empty_call(): client.delete_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteInstanceRequest() @@ -1773,7 +1736,7 @@ async def test_delete_instance_async( transport: str = "grpc_asyncio", request_type=service.DeleteInstanceRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1786,13 +1749,11 @@ async def test_delete_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteInstanceRequest() # Establish that the response is the type that we expect. @@ -1805,17 +1766,17 @@ async def test_delete_instance_async_from_dict(): def test_delete_instance_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1830,11 +1791,14 @@ def test_delete_instance_field_headers(): @pytest.mark.asyncio async def test_delete_instance_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1842,7 +1806,6 @@ async def test_delete_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1859,7 +1822,7 @@ def test_start_instance( transport: str = "grpc", request_type=service.StartInstanceRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1870,13 +1833,11 @@ def test_start_instance( with mock.patch.object(type(client.transport.start_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.start_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] == service.StartInstanceRequest() # Establish that the response is the type that we expect. @@ -1891,7 +1852,7 @@ def test_start_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1899,7 +1860,6 @@ def test_start_instance_empty_call(): client.start_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.StartInstanceRequest() @@ -1908,7 +1868,7 @@ async def test_start_instance_async( transport: str = "grpc_asyncio", request_type=service.StartInstanceRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1921,13 +1881,11 @@ async def test_start_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.start_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.StartInstanceRequest() # Establish that the response is the type that we expect. @@ -1940,17 +1898,17 @@ async def test_start_instance_async_from_dict(): def test_start_instance_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.StartInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.start_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.start_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1965,11 +1923,14 @@ def test_start_instance_field_headers(): @pytest.mark.asyncio async def test_start_instance_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.StartInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1977,7 +1938,6 @@ async def test_start_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.start_instance(request) # Establish that the underlying gRPC stub method was called. @@ -1994,7 +1954,7 @@ def test_stop_instance( transport: str = "grpc", request_type=service.StopInstanceRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2005,13 +1965,11 @@ def test_stop_instance( with mock.patch.object(type(client.transport.stop_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.stop_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] == service.StopInstanceRequest() # Establish that the response is the type that we expect. @@ -2026,7 +1984,7 @@ def test_stop_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2034,7 +1992,6 @@ def test_stop_instance_empty_call(): client.stop_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.StopInstanceRequest() @@ -2043,7 +2000,7 @@ async def test_stop_instance_async( transport: str = "grpc_asyncio", request_type=service.StopInstanceRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2056,13 +2013,11 @@ async def test_stop_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.stop_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.StopInstanceRequest() # Establish that the response is the type that we expect. @@ -2075,17 +2030,17 @@ async def test_stop_instance_async_from_dict(): def test_stop_instance_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.StopInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.stop_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2100,11 +2055,14 @@ def test_stop_instance_field_headers(): @pytest.mark.asyncio async def test_stop_instance_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.StopInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2112,7 +2070,6 @@ async def test_stop_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.stop_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2129,7 +2086,7 @@ def test_reset_instance( transport: str = "grpc", request_type=service.ResetInstanceRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2140,13 +2097,11 @@ def test_reset_instance( with mock.patch.object(type(client.transport.reset_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.reset_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] == service.ResetInstanceRequest() # Establish that the response is the type that we expect. @@ -2161,7 +2116,7 @@ def test_reset_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2169,7 +2124,6 @@ def test_reset_instance_empty_call(): client.reset_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ResetInstanceRequest() @@ -2178,7 +2132,7 @@ async def test_reset_instance_async( transport: str = "grpc_asyncio", request_type=service.ResetInstanceRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2191,13 +2145,11 @@ async def test_reset_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.reset_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ResetInstanceRequest() # Establish that the response is the type that we expect. @@ -2210,17 +2162,17 @@ async def test_reset_instance_async_from_dict(): def test_reset_instance_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ResetInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.reset_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.reset_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2235,11 +2187,14 @@ def test_reset_instance_field_headers(): @pytest.mark.asyncio async def test_reset_instance_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ResetInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2247,7 +2202,6 @@ async def test_reset_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.reset_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2264,7 +2218,7 @@ def test_report_instance_info( transport: str = "grpc", request_type=service.ReportInstanceInfoRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2277,13 +2231,11 @@ def test_report_instance_info( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.report_instance_info(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ReportInstanceInfoRequest() # Establish that the response is the type that we expect. @@ -2298,7 +2250,7 @@ def test_report_instance_info_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2308,7 +2260,6 @@ def test_report_instance_info_empty_call(): client.report_instance_info() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ReportInstanceInfoRequest() @@ -2317,7 +2268,7 @@ async def test_report_instance_info_async( transport: str = "grpc_asyncio", request_type=service.ReportInstanceInfoRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2332,13 +2283,11 @@ async def test_report_instance_info_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.report_instance_info(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ReportInstanceInfoRequest() # Establish that the response is the type that we expect. @@ -2351,11 +2300,12 @@ async def test_report_instance_info_async_from_dict(): def test_report_instance_info_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ReportInstanceInfoRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2363,7 +2313,6 @@ def test_report_instance_info_field_headers(): type(client.transport.report_instance_info), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.report_instance_info(request) # Establish that the underlying gRPC stub method was called. @@ -2378,11 +2327,14 @@ def test_report_instance_info_field_headers(): @pytest.mark.asyncio async def test_report_instance_info_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ReportInstanceInfoRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2392,7 +2344,6 @@ async def test_report_instance_info_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.report_instance_info(request) # Establish that the underlying gRPC stub method was called. @@ -2409,7 +2360,7 @@ def test_is_instance_upgradeable( transport: str = "grpc", request_type=service.IsInstanceUpgradeableRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2426,23 +2377,17 @@ def test_is_instance_upgradeable( upgrade_version="upgrade_version_value", upgrade_info="upgrade_info_value", ) - response = client.is_instance_upgradeable(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.IsInstanceUpgradeableRequest() # Establish that the response is the type that we expect. - assert isinstance(response, service.IsInstanceUpgradeableResponse) - assert response.upgradeable is True - assert response.upgrade_version == "upgrade_version_value" - assert response.upgrade_info == "upgrade_info_value" @@ -2454,7 +2399,7 @@ def test_is_instance_upgradeable_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2464,7 +2409,6 @@ def test_is_instance_upgradeable_empty_call(): client.is_instance_upgradeable() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.IsInstanceUpgradeableRequest() @@ -2473,7 +2417,7 @@ async def test_is_instance_upgradeable_async( transport: str = "grpc_asyncio", request_type=service.IsInstanceUpgradeableRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2492,22 +2436,17 @@ async def test_is_instance_upgradeable_async( upgrade_info="upgrade_info_value", ) ) - response = await client.is_instance_upgradeable(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.IsInstanceUpgradeableRequest() # Establish that the response is the type that we expect. assert isinstance(response, service.IsInstanceUpgradeableResponse) - assert response.upgradeable is True - assert response.upgrade_version == "upgrade_version_value" - assert response.upgrade_info == "upgrade_info_value" @@ -2517,11 +2456,12 @@ async def test_is_instance_upgradeable_async_from_dict(): def test_is_instance_upgradeable_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.IsInstanceUpgradeableRequest() + request.notebook_instance = "notebook_instance/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2529,7 +2469,6 @@ def test_is_instance_upgradeable_field_headers(): type(client.transport.is_instance_upgradeable), "__call__" ) as call: call.return_value = service.IsInstanceUpgradeableResponse() - client.is_instance_upgradeable(request) # Establish that the underlying gRPC stub method was called. @@ -2547,11 +2486,14 @@ def test_is_instance_upgradeable_field_headers(): @pytest.mark.asyncio async def test_is_instance_upgradeable_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.IsInstanceUpgradeableRequest() + request.notebook_instance = "notebook_instance/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2561,7 +2503,6 @@ async def test_is_instance_upgradeable_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.IsInstanceUpgradeableResponse() ) - await client.is_instance_upgradeable(request) # Establish that the underlying gRPC stub method was called. @@ -2581,7 +2522,7 @@ def test_upgrade_instance( transport: str = "grpc", request_type=service.UpgradeInstanceRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2592,13 +2533,11 @@ def test_upgrade_instance( with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpgradeInstanceRequest() # Establish that the response is the type that we expect. @@ -2613,7 +2552,7 @@ def test_upgrade_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2621,7 +2560,6 @@ def test_upgrade_instance_empty_call(): client.upgrade_instance() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpgradeInstanceRequest() @@ -2630,7 +2568,7 @@ async def test_upgrade_instance_async( transport: str = "grpc_asyncio", request_type=service.UpgradeInstanceRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2643,13 +2581,11 @@ async def test_upgrade_instance_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpgradeInstanceRequest() # Establish that the response is the type that we expect. @@ -2662,17 +2598,17 @@ async def test_upgrade_instance_async_from_dict(): def test_upgrade_instance_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpgradeInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2687,11 +2623,14 @@ def test_upgrade_instance_field_headers(): @pytest.mark.asyncio async def test_upgrade_instance_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpgradeInstanceRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2699,7 +2638,6 @@ async def test_upgrade_instance_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.upgrade_instance(request) # Establish that the underlying gRPC stub method was called. @@ -2716,7 +2654,7 @@ def test_upgrade_instance_internal( transport: str = "grpc", request_type=service.UpgradeInstanceInternalRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2729,13 +2667,11 @@ def test_upgrade_instance_internal( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.upgrade_instance_internal(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpgradeInstanceInternalRequest() # Establish that the response is the type that we expect. @@ -2750,7 +2686,7 @@ def test_upgrade_instance_internal_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2760,7 +2696,6 @@ def test_upgrade_instance_internal_empty_call(): client.upgrade_instance_internal() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpgradeInstanceInternalRequest() @@ -2769,7 +2704,7 @@ async def test_upgrade_instance_internal_async( transport: str = "grpc_asyncio", request_type=service.UpgradeInstanceInternalRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2784,13 +2719,11 @@ async def test_upgrade_instance_internal_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.upgrade_instance_internal(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpgradeInstanceInternalRequest() # Establish that the response is the type that we expect. @@ -2803,11 +2736,12 @@ async def test_upgrade_instance_internal_async_from_dict(): def test_upgrade_instance_internal_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpgradeInstanceInternalRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2815,7 +2749,6 @@ def test_upgrade_instance_internal_field_headers(): type(client.transport.upgrade_instance_internal), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.upgrade_instance_internal(request) # Establish that the underlying gRPC stub method was called. @@ -2830,11 +2763,14 @@ def test_upgrade_instance_internal_field_headers(): @pytest.mark.asyncio async def test_upgrade_instance_internal_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpgradeInstanceInternalRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2844,7 +2780,6 @@ async def test_upgrade_instance_internal_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.upgrade_instance_internal(request) # Establish that the underlying gRPC stub method was called. @@ -2861,7 +2796,7 @@ def test_list_environments( transport: str = "grpc", request_type=service.ListEnvironmentsRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2876,21 +2811,16 @@ def test_list_environments( call.return_value = service.ListEnvironmentsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) - response = client.list_environments(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListEnvironmentsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListEnvironmentsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -2902,7 +2832,7 @@ def test_list_environments_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2912,7 +2842,6 @@ def test_list_environments_empty_call(): client.list_environments() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListEnvironmentsRequest() @@ -2921,7 +2850,7 @@ async def test_list_environments_async( transport: str = "grpc_asyncio", request_type=service.ListEnvironmentsRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2939,20 +2868,16 @@ async def test_list_environments_async( unreachable=["unreachable_value"], ) ) - response = await client.list_environments(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListEnvironmentsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListEnvironmentsAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -2962,11 +2887,12 @@ async def test_list_environments_async_from_dict(): def test_list_environments_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListEnvironmentsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2974,7 +2900,6 @@ def test_list_environments_field_headers(): type(client.transport.list_environments), "__call__" ) as call: call.return_value = service.ListEnvironmentsResponse() - client.list_environments(request) # Establish that the underlying gRPC stub method was called. @@ -2989,11 +2914,14 @@ def test_list_environments_field_headers(): @pytest.mark.asyncio async def test_list_environments_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListEnvironmentsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3003,7 +2931,6 @@ async def test_list_environments_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListEnvironmentsResponse() ) - await client.list_environments(request) # Establish that the underlying gRPC stub method was called. @@ -3017,7 +2944,7 @@ async def test_list_environments_field_headers_async(): def test_list_environments_pager(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials,) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3057,7 +2984,7 @@ def test_list_environments_pager(): def test_list_environments_pages(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials,) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3089,7 +3016,9 @@ def test_list_environments_pages(): @pytest.mark.asyncio async def test_list_environments_async_pager(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3128,7 +3057,9 @@ async def test_list_environments_async_pager(): @pytest.mark.asyncio async def test_list_environments_async_pages(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3166,7 +3097,7 @@ def test_get_environment( transport: str = "grpc", request_type=service.GetEnvironmentRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3183,25 +3114,18 @@ def test_get_environment( post_startup_script="post_startup_script_value", vm_image=environment.VmImage(project="project_value"), ) - response = client.get_environment(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetEnvironmentRequest() # Establish that the response is the type that we expect. - assert isinstance(response, environment.Environment) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.post_startup_script == "post_startup_script_value" @@ -3213,7 +3137,7 @@ def test_get_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3221,7 +3145,6 @@ def test_get_environment_empty_call(): client.get_environment() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetEnvironmentRequest() @@ -3230,7 +3153,7 @@ async def test_get_environment_async( transport: str = "grpc_asyncio", request_type=service.GetEnvironmentRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3248,24 +3171,18 @@ async def test_get_environment_async( post_startup_script="post_startup_script_value", ) ) - response = await client.get_environment(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetEnvironmentRequest() # Establish that the response is the type that we expect. assert isinstance(response, environment.Environment) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.post_startup_script == "post_startup_script_value" @@ -3275,17 +3192,17 @@ async def test_get_environment_async_from_dict(): def test_get_environment_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetEnvironmentRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_environment), "__call__") as call: call.return_value = environment.Environment() - client.get_environment(request) # Establish that the underlying gRPC stub method was called. @@ -3300,11 +3217,14 @@ def test_get_environment_field_headers(): @pytest.mark.asyncio async def test_get_environment_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetEnvironmentRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3312,7 +3232,6 @@ async def test_get_environment_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( environment.Environment() ) - await client.get_environment(request) # Establish that the underlying gRPC stub method was called. @@ -3329,7 +3248,7 @@ def test_create_environment( transport: str = "grpc", request_type=service.CreateEnvironmentRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3342,13 +3261,11 @@ def test_create_environment( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_environment(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateEnvironmentRequest() # Establish that the response is the type that we expect. @@ -3363,7 +3280,7 @@ def test_create_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3373,7 +3290,6 @@ def test_create_environment_empty_call(): client.create_environment() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateEnvironmentRequest() @@ -3382,7 +3298,7 @@ async def test_create_environment_async( transport: str = "grpc_asyncio", request_type=service.CreateEnvironmentRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3397,13 +3313,11 @@ async def test_create_environment_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_environment(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateEnvironmentRequest() # Establish that the response is the type that we expect. @@ -3416,11 +3330,12 @@ async def test_create_environment_async_from_dict(): def test_create_environment_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateEnvironmentRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3428,7 +3343,6 @@ def test_create_environment_field_headers(): type(client.transport.create_environment), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_environment(request) # Establish that the underlying gRPC stub method was called. @@ -3443,11 +3357,14 @@ def test_create_environment_field_headers(): @pytest.mark.asyncio async def test_create_environment_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateEnvironmentRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3457,7 +3374,6 @@ async def test_create_environment_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_environment(request) # Establish that the underlying gRPC stub method was called. @@ -3474,7 +3390,7 @@ def test_delete_environment( transport: str = "grpc", request_type=service.DeleteEnvironmentRequest ): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3487,13 +3403,11 @@ def test_delete_environment( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_environment(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteEnvironmentRequest() # Establish that the response is the type that we expect. @@ -3508,7 +3422,7 @@ def test_delete_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3518,7 +3432,6 @@ def test_delete_environment_empty_call(): client.delete_environment() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteEnvironmentRequest() @@ -3527,7 +3440,7 @@ async def test_delete_environment_async( transport: str = "grpc_asyncio", request_type=service.DeleteEnvironmentRequest ): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3542,13 +3455,11 @@ async def test_delete_environment_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_environment(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteEnvironmentRequest() # Establish that the response is the type that we expect. @@ -3561,11 +3472,12 @@ async def test_delete_environment_async_from_dict(): def test_delete_environment_field_headers(): - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteEnvironmentRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3573,7 +3485,6 @@ def test_delete_environment_field_headers(): type(client.transport.delete_environment), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_environment(request) # Establish that the underlying gRPC stub method was called. @@ -3588,11 +3499,14 @@ def test_delete_environment_field_headers(): @pytest.mark.asyncio async def test_delete_environment_field_headers_async(): - client = NotebookServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteEnvironmentRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -3602,7 +3516,6 @@ async def test_delete_environment_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_environment(request) # Establish that the underlying gRPC stub method was called. @@ -3618,16 +3531,16 @@ async def test_delete_environment_field_headers_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.NotebookServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.NotebookServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = NotebookServiceClient( @@ -3637,7 +3550,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.NotebookServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = NotebookServiceClient( @@ -3648,7 +3561,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.NotebookServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = NotebookServiceClient(transport=transport) assert client.transport is transport @@ -3657,13 +3570,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.NotebookServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.NotebookServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -3678,23 +3591,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = NotebookServiceClient(credentials=credentials.AnonymousCredentials(),) + client = NotebookServiceClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.NotebookServiceGrpcTransport,) def test_notebook_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.NotebookServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -3706,7 +3619,7 @@ def test_notebook_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.NotebookServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -3742,15 +3655,37 @@ def test_notebook_service_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_notebook_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.notebooks_v1beta1.services.notebook_service.transports.NotebookServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.NotebookServiceTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_notebook_service_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.notebooks_v1beta1.services.notebook_service.transports.NotebookServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NotebookServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -3763,19 +3698,33 @@ def test_notebook_service_base_transport_with_credentials_file(): def test_notebook_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.notebooks_v1beta1.services.notebook_service.transports.NotebookServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NotebookServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_notebook_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + NotebookServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_notebook_service_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) NotebookServiceClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -3783,20 +3732,156 @@ def test_notebook_service_auth_adc(): ) -def test_notebook_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.NotebookServiceGrpcTransport, + transports.NotebookServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_notebook_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.NotebookServiceGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.NotebookServiceGrpcTransport, + transports.NotebookServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_notebook_service_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.NotebookServiceGrpcTransport, grpc_helpers), + (transports.NotebookServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_notebook_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "notebooks.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="notebooks.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.NotebookServiceGrpcTransport, grpc_helpers), + (transports.NotebookServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_notebook_service_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "notebooks.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.NotebookServiceGrpcTransport, grpc_helpers), + (transports.NotebookServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_notebook_service_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "notebooks.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [ @@ -3805,7 +3890,7 @@ def test_notebook_service_transport_auth_adc(): ], ) def test_notebook_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3844,7 +3929,7 @@ def test_notebook_service_grpc_transport_client_cert_source_for_mtls(transport_c def test_notebook_service_host_no_port(): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="notebooks.googleapis.com" ), @@ -3854,7 +3939,7 @@ def test_notebook_service_host_no_port(): def test_notebook_service_host_with_port(): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="notebooks.googleapis.com:8000" ), @@ -3910,9 +3995,9 @@ def test_notebook_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -3988,7 +4073,7 @@ def test_notebook_service_transport_channel_mtls_with_adc(transport_class): def test_notebook_service_grpc_lro_client(): client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -4001,7 +4086,7 @@ def test_notebook_service_grpc_lro_client(): def test_notebook_service_grpc_lro_async_client(): client = NotebookServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -4015,7 +4100,6 @@ def test_notebook_service_grpc_lro_async_client(): def test_environment_path(): project = "squid" environment = "clam" - expected = "projects/{project}/environments/{environment}".format( project=project, environment=environment, ) @@ -4038,7 +4122,6 @@ def test_parse_environment_path(): def test_instance_path(): project = "oyster" instance = "nudibranch" - expected = "projects/{project}/instances/{instance}".format( project=project, instance=instance, ) @@ -4060,7 +4143,6 @@ def test_parse_instance_path(): def test_common_billing_account_path(): billing_account = "winkle" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -4081,7 +4163,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "scallop" - expected = "folders/{folder}".format(folder=folder,) actual = NotebookServiceClient.common_folder_path(folder) assert expected == actual @@ -4100,7 +4181,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "squid" - expected = "organizations/{organization}".format(organization=organization,) actual = NotebookServiceClient.common_organization_path(organization) assert expected == actual @@ -4119,7 +4199,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "whelk" - expected = "projects/{project}".format(project=project,) actual = NotebookServiceClient.common_project_path(project) assert expected == actual @@ -4139,7 +4218,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "oyster" location = "nudibranch" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -4166,7 +4244,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.NotebookServiceTransport, "_prep_wrapped_messages" ) as prep: client = NotebookServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4175,6 +4253,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = NotebookServiceClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info)