From 2f1db842b16cf2c3981c61b503482fa7df85bdfe 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:30:04 +0000 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.46.3 (#75) PiperOrigin-RevId: 373649163 Source-Link: https://github.com/googleapis/googleapis/commit/7e1b14e6c7a9ab96d2db7e4a131981f162446d34 Source-Link: https://github.com/googleapis/googleapis-gen/commit/0a3c7d272d697796db75857bac73905c68e498c3 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 --- .../connection_service.rst | 1 - google/cloud/bigquery_connection/__init__.py | 12 +- .../cloud/bigquery_connection_v1/__init__.py | 7 +- .../gapic_metadata.json | 103 +++ .../services/__init__.py | 1 - .../services/connection_service/__init__.py | 2 - .../connection_service/async_client.py | 81 +- .../services/connection_service/client.py | 115 ++- .../services/connection_service/pagers.py | 4 +- .../connection_service/transports/__init__.py | 2 - .../connection_service/transports/base.py | 161 ++-- .../connection_service/transports/grpc.py | 51 +- .../transports/grpc_asyncio.py | 53 +- .../bigquery_connection_v1/types/__init__.py | 2 - .../types/connection.py | 77 +- .../fixup_bigquery_connection_v1_keywords.py | 21 +- tests/__init__.py | 15 + tests/unit/__init__.py | 15 + tests/unit/gapic/__init__.py | 15 + .../gapic/bigquery_connection_v1/__init__.py | 1 - .../test_connection_service.py | 769 ++++++++++-------- 21 files changed, 861 insertions(+), 647 deletions(-) create mode 100644 google/cloud/bigquery_connection_v1/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/bigquery_connection_v1/connection_service.rst b/docs/bigquery_connection_v1/connection_service.rst index e4a4b8d..9059205 100644 --- a/docs/bigquery_connection_v1/connection_service.rst +++ b/docs/bigquery_connection_v1/connection_service.rst @@ -5,7 +5,6 @@ ConnectionService :members: :inherited-members: - .. automodule:: google.cloud.bigquery_connection_v1.services.connection_service.pagers :members: :inherited-members: diff --git a/google/cloud/bigquery_connection/__init__.py b/google/cloud/bigquery_connection/__init__.py index 591eaac..7e29fe8 100644 --- a/google/cloud/bigquery_connection/__init__.py +++ b/google/cloud/bigquery_connection/__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.bigquery_connection_v1.services.connection_service.async_client import ( - ConnectionServiceAsyncClient, -) from google.cloud.bigquery_connection_v1.services.connection_service.client import ( ConnectionServiceClient, ) +from google.cloud.bigquery_connection_v1.services.connection_service.async_client import ( + ConnectionServiceAsyncClient, +) + from google.cloud.bigquery_connection_v1.types.connection import AwsCrossAccountRole from google.cloud.bigquery_connection_v1.types.connection import AwsProperties from google.cloud.bigquery_connection_v1.types.connection import CloudSqlCredential @@ -34,13 +34,13 @@ from google.cloud.bigquery_connection_v1.types.connection import UpdateConnectionRequest __all__ = ( + "ConnectionServiceClient", + "ConnectionServiceAsyncClient", "AwsCrossAccountRole", "AwsProperties", "CloudSqlCredential", "CloudSqlProperties", "Connection", - "ConnectionServiceAsyncClient", - "ConnectionServiceClient", "CreateConnectionRequest", "DeleteConnectionRequest", "GetConnectionRequest", diff --git a/google/cloud/bigquery_connection_v1/__init__.py b/google/cloud/bigquery_connection_v1/__init__.py index c3ee8e4..bff96d6 100644 --- a/google/cloud/bigquery_connection_v1/__init__.py +++ b/google/cloud/bigquery_connection_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.connection_service import ConnectionServiceClient +from .services.connection_service import ConnectionServiceAsyncClient + from .types.connection import AwsCrossAccountRole from .types.connection import AwsProperties from .types.connection import CloudSqlCredential @@ -28,18 +29,18 @@ from .types.connection import ListConnectionsResponse from .types.connection import UpdateConnectionRequest - __all__ = ( + "ConnectionServiceAsyncClient", "AwsCrossAccountRole", "AwsProperties", "CloudSqlCredential", "CloudSqlProperties", "Connection", + "ConnectionServiceClient", "CreateConnectionRequest", "DeleteConnectionRequest", "GetConnectionRequest", "ListConnectionsRequest", "ListConnectionsResponse", "UpdateConnectionRequest", - "ConnectionServiceClient", ) diff --git a/google/cloud/bigquery_connection_v1/gapic_metadata.json b/google/cloud/bigquery_connection_v1/gapic_metadata.json new file mode 100644 index 0000000..c95fa6e --- /dev/null +++ b/google/cloud/bigquery_connection_v1/gapic_metadata.json @@ -0,0 +1,103 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.bigquery_connection_v1", + "protoPackage": "google.cloud.bigquery.connection.v1", + "schema": "1.0", + "services": { + "ConnectionService": { + "clients": { + "grpc": { + "libraryClient": "ConnectionServiceClient", + "rpcs": { + "CreateConnection": { + "methods": [ + "create_connection" + ] + }, + "DeleteConnection": { + "methods": [ + "delete_connection" + ] + }, + "GetConnection": { + "methods": [ + "get_connection" + ] + }, + "GetIamPolicy": { + "methods": [ + "get_iam_policy" + ] + }, + "ListConnections": { + "methods": [ + "list_connections" + ] + }, + "SetIamPolicy": { + "methods": [ + "set_iam_policy" + ] + }, + "TestIamPermissions": { + "methods": [ + "test_iam_permissions" + ] + }, + "UpdateConnection": { + "methods": [ + "update_connection" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ConnectionServiceAsyncClient", + "rpcs": { + "CreateConnection": { + "methods": [ + "create_connection" + ] + }, + "DeleteConnection": { + "methods": [ + "delete_connection" + ] + }, + "GetConnection": { + "methods": [ + "get_connection" + ] + }, + "GetIamPolicy": { + "methods": [ + "get_iam_policy" + ] + }, + "ListConnections": { + "methods": [ + "list_connections" + ] + }, + "SetIamPolicy": { + "methods": [ + "set_iam_policy" + ] + }, + "TestIamPermissions": { + "methods": [ + "test_iam_permissions" + ] + }, + "UpdateConnection": { + "methods": [ + "update_connection" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/bigquery_connection_v1/services/__init__.py b/google/cloud/bigquery_connection_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/bigquery_connection_v1/services/__init__.py +++ b/google/cloud/bigquery_connection_v1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/bigquery_connection_v1/services/connection_service/__init__.py b/google/cloud/bigquery_connection_v1/services/connection_service/__init__.py index c7becdb..9dc1368 100644 --- a/google/cloud/bigquery_connection_v1/services/connection_service/__init__.py +++ b/google/cloud/bigquery_connection_v1/services/connection_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 ConnectionServiceClient from .async_client import ConnectionServiceAsyncClient diff --git a/google/cloud/bigquery_connection_v1/services/connection_service/async_client.py b/google/cloud/bigquery_connection_v1/services/connection_service/async_client.py index 527b263..6a33f05 100644 --- a/google/cloud/bigquery_connection_v1/services/connection_service/async_client.py +++ b/google/cloud/bigquery_connection_v1/services/connection_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,19 +20,18 @@ 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.cloud.bigquery_connection_v1.services.connection_service import pagers from google.cloud.bigquery_connection_v1.types import connection from google.cloud.bigquery_connection_v1.types import connection as gcbc_connection -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore - +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from .transports.base import ConnectionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import ConnectionServiceGrpcAsyncIOTransport from .client import ConnectionServiceClient @@ -50,31 +47,26 @@ class ConnectionServiceAsyncClient: connection_path = staticmethod(ConnectionServiceClient.connection_path) parse_connection_path = staticmethod(ConnectionServiceClient.parse_connection_path) - common_billing_account_path = staticmethod( ConnectionServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( ConnectionServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(ConnectionServiceClient.common_folder_path) parse_common_folder_path = staticmethod( ConnectionServiceClient.parse_common_folder_path ) - common_organization_path = staticmethod( ConnectionServiceClient.common_organization_path ) parse_common_organization_path = staticmethod( ConnectionServiceClient.parse_common_organization_path ) - common_project_path = staticmethod(ConnectionServiceClient.common_project_path) parse_common_project_path = staticmethod( ConnectionServiceClient.parse_common_project_path ) - common_location_path = staticmethod(ConnectionServiceClient.common_location_path) parse_common_location_path = staticmethod( ConnectionServiceClient.parse_common_location_path @@ -82,7 +74,8 @@ class ConnectionServiceAsyncClient: @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. @@ -97,7 +90,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 @@ -114,7 +107,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ConnectionServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: ConnectionServiceTransport: The transport used by the client instance. @@ -128,12 +121,12 @@ def transport(self) -> ConnectionServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, ConnectionServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the connection service client. + """Instantiates the connection service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -165,7 +158,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = ConnectionServiceClient( credentials=credentials, transport=transport, @@ -209,7 +201,6 @@ async def create_connection( This corresponds to the ``connection_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -237,7 +228,6 @@ async def create_connection( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if connection is not None: @@ -287,7 +277,6 @@ async def get_connection( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -315,7 +304,6 @@ async def get_connection( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -328,7 +316,8 @@ async def get_connection( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=60.0, ), @@ -370,7 +359,6 @@ async def list_connections( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -400,7 +388,6 @@ async def list_connections( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -413,7 +400,8 @@ async def list_connections( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=60.0, ), @@ -445,7 +433,7 @@ async def update_connection( *, name: str = None, connection: gcbc_connection.Connection = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -479,7 +467,6 @@ async def update_connection( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -507,7 +494,6 @@ async def update_connection( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if connection is not None: @@ -557,7 +543,6 @@ async def delete_connection( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -578,7 +563,6 @@ async def delete_connection( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -591,7 +575,8 @@ async def delete_connection( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=60.0, ), @@ -612,13 +597,13 @@ async def delete_connection( async def get_iam_policy( self, - request: iam_policy.GetIamPolicyRequest = None, + request: iam_policy_pb2.GetIamPolicyRequest = None, *, resource: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> policy.Policy: + ) -> policy_pb2.Policy: r"""Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set. @@ -636,7 +621,6 @@ async def get_iam_policy( This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -715,10 +699,9 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if isinstance(request, dict): - request = iam_policy.GetIamPolicyRequest(**request) - + request = iam_policy_pb2.GetIamPolicyRequest(**request) elif not request: - request = iam_policy.GetIamPolicyRequest(resource=resource,) + request = iam_policy_pb2.GetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -742,13 +725,13 @@ async def get_iam_policy( async def set_iam_policy( self, - request: iam_policy.SetIamPolicyRequest = None, + request: iam_policy_pb2.SetIamPolicyRequest = None, *, resource: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> policy.Policy: + ) -> policy_pb2.Policy: r"""Sets the access control policy on the specified resource. Replaces any existing policy. @@ -768,7 +751,6 @@ async def set_iam_policy( This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -847,10 +829,9 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if isinstance(request, dict): - request = iam_policy.SetIamPolicyRequest(**request) - + request = iam_policy_pb2.SetIamPolicyRequest(**request) elif not request: - request = iam_policy.SetIamPolicyRequest(resource=resource,) + request = iam_policy_pb2.SetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -874,14 +855,14 @@ async def set_iam_policy( async def test_iam_permissions( self, - request: iam_policy.TestIamPermissionsRequest = None, + request: iam_policy_pb2.TestIamPermissionsRequest = None, *, resource: str = None, permissions: Sequence[str] = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> iam_policy.TestIamPermissionsResponse: + ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a ``NOT_FOUND`` error. @@ -913,7 +894,6 @@ async def test_iam_permissions( This corresponds to the ``permissions`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -937,10 +917,9 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if isinstance(request, dict): - request = iam_policy.TestIamPermissionsRequest(**request) - + request = iam_policy_pb2.TestIamPermissionsRequest(**request) elif not request: - request = iam_policy.TestIamPermissionsRequest( + request = iam_policy_pb2.TestIamPermissionsRequest( resource=resource, permissions=permissions, ) diff --git a/google/cloud/bigquery_connection_v1/services/connection_service/client.py b/google/cloud/bigquery_connection_v1/services/connection_service/client.py index ec70474..1e06e36 100644 --- a/google/cloud/bigquery_connection_v1/services/connection_service/client.py +++ b/google/cloud/bigquery_connection_v1/services/connection_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 @@ -35,10 +33,9 @@ from google.cloud.bigquery_connection_v1.services.connection_service import pagers from google.cloud.bigquery_connection_v1.types import connection from google.cloud.bigquery_connection_v1.types import connection as gcbc_connection -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore - +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from .transports.base import ConnectionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import ConnectionServiceGrpcTransport from .transports.grpc_asyncio import ConnectionServiceGrpcAsyncIOTransport @@ -61,7 +58,7 @@ class ConnectionServiceClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[ConnectionServiceTransport]: - """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 ConnectionServiceClient(metaclass=ConnectionServiceClientMeta): @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) -> ConnectionServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - ConnectionServiceTransport: The transport used by the client instance. + ConnectionServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def connection_path(project: str, location: str, connection: str,) -> str: - """Return a fully-qualified connection string.""" + """Returns a fully-qualified connection string.""" return "projects/{project}/locations/{location}/connections/{connection}".format( project=project, location=location, connection=connection, ) @staticmethod def parse_connection_path(path: str) -> Dict[str, str]: - """Parse a connection path into its component segments.""" + """Parses a connection path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/connections/(?P.+?)$", path, @@ -179,7 +179,7 @@ def parse_connection_path(path: str) -> Dict[str, str]: @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -192,7 +192,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 @@ -203,7 +203,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 @@ -214,7 +214,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 @@ -225,7 +225,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, ) @@ -239,12 +239,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, ConnectionServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the connection service client. + """Instantiates the connection service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -299,9 +299,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: @@ -313,12 +314,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. @@ -333,8 +336,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: @@ -385,7 +388,6 @@ def create_connection( This corresponds to the ``connection_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -415,10 +417,8 @@ def create_connection( # there are no flattened fields. if not isinstance(request, gcbc_connection.CreateConnectionRequest): request = gcbc_connection.CreateConnectionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if connection is not None: @@ -464,7 +464,6 @@ def get_connection( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -494,10 +493,8 @@ def get_connection( # there are no flattened fields. if not isinstance(request, connection.GetConnectionRequest): request = connection.GetConnectionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -539,7 +536,6 @@ def list_connections( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -571,10 +567,8 @@ def list_connections( # there are no flattened fields. if not isinstance(request, connection.ListConnectionsRequest): request = connection.ListConnectionsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -606,7 +600,7 @@ def update_connection( *, name: str = None, connection: gcbc_connection.Connection = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -640,7 +634,6 @@ def update_connection( This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -670,10 +663,8 @@ def update_connection( # there are no flattened fields. if not isinstance(request, gcbc_connection.UpdateConnectionRequest): request = gcbc_connection.UpdateConnectionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name if connection is not None: @@ -719,7 +710,6 @@ def delete_connection( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -742,10 +732,8 @@ def delete_connection( # there are no flattened fields. if not isinstance(request, connection.DeleteConnectionRequest): request = connection.DeleteConnectionRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -766,13 +754,13 @@ def delete_connection( def get_iam_policy( self, - request: iam_policy.GetIamPolicyRequest = None, + request: iam_policy_pb2.GetIamPolicyRequest = None, *, resource: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> policy.Policy: + ) -> policy_pb2.Policy: r"""Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set. @@ -790,7 +778,6 @@ def get_iam_policy( This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -869,11 +856,10 @@ def get_iam_policy( if isinstance(request, dict): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - request = iam_policy.GetIamPolicyRequest(**request) + request = iam_policy_pb2.GetIamPolicyRequest(**request) elif not request: # Null request, just make one. - request = iam_policy.GetIamPolicyRequest() - + request = iam_policy_pb2.GetIamPolicyRequest() if resource is not None: request.resource = resource @@ -895,13 +881,13 @@ def get_iam_policy( def set_iam_policy( self, - request: iam_policy.SetIamPolicyRequest = None, + request: iam_policy_pb2.SetIamPolicyRequest = None, *, resource: str = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> policy.Policy: + ) -> policy_pb2.Policy: r"""Sets the access control policy on the specified resource. Replaces any existing policy. @@ -921,7 +907,6 @@ def set_iam_policy( This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1000,11 +985,10 @@ def set_iam_policy( if isinstance(request, dict): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - request = iam_policy.SetIamPolicyRequest(**request) + request = iam_policy_pb2.SetIamPolicyRequest(**request) elif not request: # Null request, just make one. - request = iam_policy.SetIamPolicyRequest() - + request = iam_policy_pb2.SetIamPolicyRequest() if resource is not None: request.resource = resource @@ -1026,14 +1010,14 @@ def set_iam_policy( def test_iam_permissions( self, - request: iam_policy.TestIamPermissionsRequest = None, + request: iam_policy_pb2.TestIamPermissionsRequest = None, *, resource: str = None, permissions: Sequence[str] = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> iam_policy.TestIamPermissionsResponse: + ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a ``NOT_FOUND`` error. @@ -1065,7 +1049,6 @@ def test_iam_permissions( This corresponds to the ``permissions`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1089,14 +1072,12 @@ def test_iam_permissions( if isinstance(request, dict): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - request = iam_policy.TestIamPermissionsRequest(**request) + request = iam_policy_pb2.TestIamPermissionsRequest(**request) elif not request: # Null request, just make one. - request = iam_policy.TestIamPermissionsRequest() - + request = iam_policy_pb2.TestIamPermissionsRequest() if resource is not None: request.resource = resource - if permissions: request.permissions.extend(permissions) diff --git a/google/cloud/bigquery_connection_v1/services/connection_service/pagers.py b/google/cloud/bigquery_connection_v1/services/connection_service/pagers.py index ddb40fd..9706379 100644 --- a/google/cloud/bigquery_connection_v1/services/connection_service/pagers.py +++ b/google/cloud/bigquery_connection_v1/services/connection_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, @@ -117,7 +115,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/bigquery_connection_v1/services/connection_service/transports/__init__.py b/google/cloud/bigquery_connection_v1/services/connection_service/transports/__init__.py index 3835c8f..86df1ca 100644 --- a/google/cloud/bigquery_connection_v1/services/connection_service/transports/__init__.py +++ b/google/cloud/bigquery_connection_v1/services/connection_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/bigquery_connection_v1/services/connection_service/transports/base.py b/google/cloud/bigquery_connection_v1/services/connection_service/transports/base.py index 0bc2641..64a3a91 100644 --- a/google/cloud/bigquery_connection_v1/services/connection_service/transports/base.py +++ b/google/cloud/bigquery_connection_v1/services/connection_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.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.bigquery_connection_v1.types import connection from google.cloud.bigquery_connection_v1.types import connection as gcbc_connection -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -41,6 +40,17 @@ 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 ConnectionServiceTransport(abc.ABC): """Abstract transport class for ConnectionService.""" @@ -50,21 +60,24 @@ class ConnectionServiceTransport(abc.ABC): "https://www.googleapis.com/auth/cloud-platform", ) + DEFAULT_HOST: str = "bigqueryconnection.googleapis.com" + def __init__( self, *, - host: str = "bigqueryconnection.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 @@ -73,7 +86,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): @@ -87,29 +100,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 = { @@ -123,7 +183,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=60.0, ), @@ -137,7 +198,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=60.0, ), @@ -154,7 +216,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=60.0, ), @@ -177,31 +240,29 @@ def _prep_wrapped_messages(self, client_info): @property def create_connection( self, - ) -> typing.Callable[ + ) -> Callable[ [gcbc_connection.CreateConnectionRequest], - typing.Union[ - gcbc_connection.Connection, typing.Awaitable[gcbc_connection.Connection] - ], + Union[gcbc_connection.Connection, Awaitable[gcbc_connection.Connection]], ]: raise NotImplementedError() @property def get_connection( self, - ) -> typing.Callable[ + ) -> Callable[ [connection.GetConnectionRequest], - typing.Union[connection.Connection, typing.Awaitable[connection.Connection]], + Union[connection.Connection, Awaitable[connection.Connection]], ]: raise NotImplementedError() @property def list_connections( self, - ) -> typing.Callable[ + ) -> Callable[ [connection.ListConnectionsRequest], - typing.Union[ + Union[ connection.ListConnectionsResponse, - typing.Awaitable[connection.ListConnectionsResponse], + Awaitable[connection.ListConnectionsResponse], ], ]: raise NotImplementedError() @@ -209,49 +270,47 @@ def list_connections( @property def update_connection( self, - ) -> typing.Callable[ + ) -> Callable[ [gcbc_connection.UpdateConnectionRequest], - typing.Union[ - gcbc_connection.Connection, typing.Awaitable[gcbc_connection.Connection] - ], + Union[gcbc_connection.Connection, Awaitable[gcbc_connection.Connection]], ]: raise NotImplementedError() @property def delete_connection( self, - ) -> typing.Callable[ + ) -> Callable[ [connection.DeleteConnectionRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], ]: raise NotImplementedError() @property def get_iam_policy( self, - ) -> typing.Callable[ - [iam_policy.GetIamPolicyRequest], - typing.Union[policy.Policy, typing.Awaitable[policy.Policy]], + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], ]: raise NotImplementedError() @property def set_iam_policy( self, - ) -> typing.Callable[ - [iam_policy.SetIamPolicyRequest], - typing.Union[policy.Policy, typing.Awaitable[policy.Policy]], + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], ]: raise NotImplementedError() @property def test_iam_permissions( self, - ) -> typing.Callable[ - [iam_policy.TestIamPermissionsRequest], - typing.Union[ - iam_policy.TestIamPermissionsResponse, - typing.Awaitable[iam_policy.TestIamPermissionsResponse], + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], ], ]: raise NotImplementedError() diff --git a/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc.py b/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc.py index a0d691d..0b5f11f 100644 --- a/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc.py +++ b/google/cloud/bigquery_connection_v1/services/connection_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,24 +13,22 @@ # 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 gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.bigquery_connection_v1.types import connection from google.cloud.bigquery_connection_v1.types import connection as gcbc_connection -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore from .base import ConnectionServiceTransport, DEFAULT_CLIENT_INFO @@ -54,7 +51,7 @@ def __init__( self, *, host: str = "bigqueryconnection.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 @@ -178,7 +176,7 @@ def __init__( def create_channel( cls, host: str = "bigqueryconnection.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, @@ -209,13 +207,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, ) @@ -340,7 +340,7 @@ def update_connection( @property def delete_connection( self, - ) -> Callable[[connection.DeleteConnectionRequest], empty.Empty]: + ) -> Callable[[connection.DeleteConnectionRequest], empty_pb2.Empty]: r"""Return a callable for the delete connection method over gRPC. Deletes connection and associated credential. @@ -359,14 +359,14 @@ def delete_connection( self._stubs["delete_connection"] = self.grpc_channel.unary_unary( "/google.cloud.bigquery.connection.v1.ConnectionService/DeleteConnection", request_serializer=connection.DeleteConnectionRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_connection"] @property def get_iam_policy( self, - ) -> Callable[[iam_policy.GetIamPolicyRequest], policy.Policy]: + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: r"""Return a callable for the get iam policy method over gRPC. Gets the access control policy for a resource. @@ -386,15 +386,15 @@ def get_iam_policy( if "get_iam_policy" not in self._stubs: self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( "/google.cloud.bigquery.connection.v1.ConnectionService/GetIamPolicy", - request_serializer=iam_policy.GetIamPolicyRequest.SerializeToString, - response_deserializer=policy.Policy.FromString, + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, ) return self._stubs["get_iam_policy"] @property def set_iam_policy( self, - ) -> Callable[[iam_policy.SetIamPolicyRequest], policy.Policy]: + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: r"""Return a callable for the set iam policy method over gRPC. Sets the access control policy on the specified resource. @@ -416,8 +416,8 @@ def set_iam_policy( if "set_iam_policy" not in self._stubs: self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( "/google.cloud.bigquery.connection.v1.ConnectionService/SetIamPolicy", - request_serializer=iam_policy.SetIamPolicyRequest.SerializeToString, - response_deserializer=policy.Policy.FromString, + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, ) return self._stubs["set_iam_policy"] @@ -425,7 +425,8 @@ def set_iam_policy( def test_iam_permissions( self, ) -> Callable[ - [iam_policy.TestIamPermissionsRequest], iam_policy.TestIamPermissionsResponse + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, ]: r"""Return a callable for the test iam permissions method over gRPC. @@ -451,8 +452,8 @@ def test_iam_permissions( if "test_iam_permissions" not in self._stubs: self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( "/google.cloud.bigquery.connection.v1.ConnectionService/TestIamPermissions", - request_serializer=iam_policy.TestIamPermissionsRequest.SerializeToString, - response_deserializer=iam_policy.TestIamPermissionsResponse.FromString, + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, ) return self._stubs["test_iam_permissions"] diff --git a/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc_asyncio.py b/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc_asyncio.py index 39b7f84..018fec2 100644 --- a/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc_asyncio.py +++ b/google/cloud/bigquery_connection_v1/services/connection_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,25 +13,23 @@ # 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 import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.bigquery_connection_v1.types import connection from google.cloud.bigquery_connection_v1.types import connection as gcbc_connection -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore from .base import ConnectionServiceTransport, DEFAULT_CLIENT_INFO from .grpc import ConnectionServiceGrpcTransport @@ -57,7 +54,7 @@ class ConnectionServiceGrpcAsyncIOTransport(ConnectionServiceTransport): def create_channel( cls, host: str = "bigqueryconnection.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 = "bigqueryconnection.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 @@ -170,7 +170,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 @@ -345,7 +344,7 @@ def update_connection( @property def delete_connection( self, - ) -> Callable[[connection.DeleteConnectionRequest], Awaitable[empty.Empty]]: + ) -> Callable[[connection.DeleteConnectionRequest], Awaitable[empty_pb2.Empty]]: r"""Return a callable for the delete connection method over gRPC. Deletes connection and associated credential. @@ -364,14 +363,14 @@ def delete_connection( self._stubs["delete_connection"] = self.grpc_channel.unary_unary( "/google.cloud.bigquery.connection.v1.ConnectionService/DeleteConnection", request_serializer=connection.DeleteConnectionRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_connection"] @property def get_iam_policy( self, - ) -> Callable[[iam_policy.GetIamPolicyRequest], Awaitable[policy.Policy]]: + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], Awaitable[policy_pb2.Policy]]: r"""Return a callable for the get iam policy method over gRPC. Gets the access control policy for a resource. @@ -391,15 +390,15 @@ def get_iam_policy( if "get_iam_policy" not in self._stubs: self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( "/google.cloud.bigquery.connection.v1.ConnectionService/GetIamPolicy", - request_serializer=iam_policy.GetIamPolicyRequest.SerializeToString, - response_deserializer=policy.Policy.FromString, + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, ) return self._stubs["get_iam_policy"] @property def set_iam_policy( self, - ) -> Callable[[iam_policy.SetIamPolicyRequest], Awaitable[policy.Policy]]: + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], Awaitable[policy_pb2.Policy]]: r"""Return a callable for the set iam policy method over gRPC. Sets the access control policy on the specified resource. @@ -421,8 +420,8 @@ def set_iam_policy( if "set_iam_policy" not in self._stubs: self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( "/google.cloud.bigquery.connection.v1.ConnectionService/SetIamPolicy", - request_serializer=iam_policy.SetIamPolicyRequest.SerializeToString, - response_deserializer=policy.Policy.FromString, + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, ) return self._stubs["set_iam_policy"] @@ -430,8 +429,8 @@ def set_iam_policy( def test_iam_permissions( self, ) -> Callable[ - [iam_policy.TestIamPermissionsRequest], - Awaitable[iam_policy.TestIamPermissionsResponse], + [iam_policy_pb2.TestIamPermissionsRequest], + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], ]: r"""Return a callable for the test iam permissions method over gRPC. @@ -457,8 +456,8 @@ def test_iam_permissions( if "test_iam_permissions" not in self._stubs: self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( "/google.cloud.bigquery.connection.v1.ConnectionService/TestIamPermissions", - request_serializer=iam_policy.TestIamPermissionsRequest.SerializeToString, - response_deserializer=iam_policy.TestIamPermissionsResponse.FromString, + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, ) return self._stubs["test_iam_permissions"] diff --git a/google/cloud/bigquery_connection_v1/types/__init__.py b/google/cloud/bigquery_connection_v1/types/__init__.py index 75cf0ec..cfaf47a 100644 --- a/google/cloud/bigquery_connection_v1/types/__init__.py +++ b/google/cloud/bigquery_connection_v1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .connection import ( AwsCrossAccountRole, AwsProperties, diff --git a/google/cloud/bigquery_connection_v1/types/connection.py b/google/cloud/bigquery_connection_v1/types/connection.py index 0d92807..6e83042 100644 --- a/google/cloud/bigquery_connection_v1/types/connection.py +++ b/google/cloud/bigquery_connection_v1/types/connection.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 field_mask_pb2 as field_mask # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore __protobuf__ = proto.module( @@ -54,10 +51,8 @@ class CreateConnectionRequest(proto.Message): Required. Connection to create. """ - parent = proto.Field(proto.STRING, number=1) - - connection_id = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + connection_id = proto.Field(proto.STRING, number=2,) connection = proto.Field(proto.MESSAGE, number=3, message="Connection",) @@ -71,7 +66,7 @@ class GetConnectionRequest(proto.Message): ``projects/{project_id}/locations/{location_id}/connections/{connection_id}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ListConnectionsRequest(proto.Message): @@ -88,11 +83,9 @@ class ListConnectionsRequest(proto.Message): Page token. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=4) - - page_token = proto.Field(proto.STRING, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=4,) + page_token = proto.Field(proto.STRING, number=3,) class ListConnectionsResponse(proto.Message): @@ -110,8 +103,7 @@ class ListConnectionsResponse(proto.Message): def raw_page(self): return self - next_page_token = proto.Field(proto.STRING, number=1) - + next_page_token = proto.Field(proto.STRING, number=1,) connections = proto.RepeatedField(proto.MESSAGE, number=2, message="Connection",) @@ -131,23 +123,22 @@ class UpdateConnectionRequest(proto.Message): fields to be updated. """ - name = proto.Field(proto.STRING, number=1) - + name = proto.Field(proto.STRING, number=1,) connection = proto.Field(proto.MESSAGE, number=2, message="Connection",) - - update_mask = proto.Field(proto.MESSAGE, number=3, message=field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=3, message=field_mask_pb2.FieldMask, + ) class DeleteConnectionRequest(proto.Message): r"""The request for [ConnectionService.DeleteConnectionRequest][]. - Attributes: name (str): Required. Name of the deleted connection, for example: ``projects/{project_id}/locations/{location_id}/connections/{connection_id}`` """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class Connection(proto.Message): @@ -178,30 +169,22 @@ class Connection(proto.Message): configured for this connection. """ - name = proto.Field(proto.STRING, number=1) - - friendly_name = proto.Field(proto.STRING, number=2) - - description = proto.Field(proto.STRING, number=3) - + name = proto.Field(proto.STRING, number=1,) + friendly_name = proto.Field(proto.STRING, number=2,) + description = proto.Field(proto.STRING, number=3,) cloud_sql = proto.Field( proto.MESSAGE, number=4, oneof="properties", message="CloudSqlProperties", ) - aws = proto.Field( proto.MESSAGE, number=8, oneof="properties", message="AwsProperties", ) - - creation_time = proto.Field(proto.INT64, number=5) - - last_modified_time = proto.Field(proto.INT64, number=6) - - has_credential = proto.Field(proto.BOOL, number=7) + creation_time = proto.Field(proto.INT64, number=5,) + last_modified_time = proto.Field(proto.INT64, number=6,) + has_credential = proto.Field(proto.BOOL, number=7,) class CloudSqlProperties(proto.Message): r"""Connection properties specific to the Cloud SQL. - Attributes: instance_id (str): Cloud SQL instance ID in the form @@ -220,18 +203,14 @@ class DatabaseType(proto.Enum): POSTGRES = 1 MYSQL = 2 - instance_id = proto.Field(proto.STRING, number=1) - - database = proto.Field(proto.STRING, number=2) - + instance_id = proto.Field(proto.STRING, number=1,) + database = proto.Field(proto.STRING, number=2,) type_ = proto.Field(proto.ENUM, number=3, enum=DatabaseType,) - credential = proto.Field(proto.MESSAGE, number=4, message="CloudSqlCredential",) class CloudSqlCredential(proto.Message): r"""Credential info for the Cloud SQL. - Attributes: username (str): The username for the credential. @@ -239,14 +218,12 @@ class CloudSqlCredential(proto.Message): The password for the credential. """ - username = proto.Field(proto.STRING, number=1) - - password = proto.Field(proto.STRING, number=2) + username = proto.Field(proto.STRING, number=1,) + password = proto.Field(proto.STRING, number=2,) class AwsProperties(proto.Message): r"""Connection properties specific to Amazon Web Services (AWS). - Attributes: cross_account_role (google.cloud.bigquery_connection_v1.types.AwsCrossAccountRole): Authentication using Google owned AWS IAM @@ -281,11 +258,9 @@ class AwsCrossAccountRole(proto.Message): https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html """ - iam_role_id = proto.Field(proto.STRING, number=1) - - iam_user_id = proto.Field(proto.STRING, number=2) - - external_id = proto.Field(proto.STRING, number=3) + iam_role_id = proto.Field(proto.STRING, number=1,) + iam_user_id = proto.Field(proto.STRING, number=2,) + external_id = proto.Field(proto.STRING, number=3,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/scripts/fixup_bigquery_connection_v1_keywords.py b/scripts/fixup_bigquery_connection_v1_keywords.py index 64ee3d3..9276ace 100644 --- a/scripts/fixup_bigquery_connection_v1_keywords.py +++ b/scripts/fixup_bigquery_connection_v1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,15 +39,14 @@ def partition( class bigquery_connectionCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_connection': ('parent', 'connection', 'connection_id', ), - 'delete_connection': ('name', ), - 'get_connection': ('name', ), - 'get_iam_policy': ('resource', 'options', ), - 'list_connections': ('parent', 'page_size', 'page_token', ), - 'set_iam_policy': ('resource', 'policy', ), - 'test_iam_permissions': ('resource', 'permissions', ), - 'update_connection': ('name', 'connection', 'update_mask', ), - + 'create_connection': ('parent', 'connection', 'connection_id', ), + 'delete_connection': ('name', ), + 'get_connection': ('name', ), + 'get_iam_policy': ('resource', 'options', ), + 'list_connections': ('parent', 'page_size', 'page_token', ), + 'set_iam_policy': ('resource', 'policy', ), + 'test_iam_permissions': ('resource', 'permissions', ), + 'update_connection': ('name', 'connection', 'update_mask', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -80,7 +77,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/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/bigquery_connection_v1/__init__.py b/tests/unit/gapic/bigquery_connection_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/bigquery_connection_v1/__init__.py +++ b/tests/unit/gapic/bigquery_connection_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/bigquery_connection_v1/test_connection_service.py b/tests/unit/gapic/bigquery_connection_v1/test_connection_service.py index ebffef9..e066dfa 100644 --- a/tests/unit/gapic/bigquery_connection_v1/test_connection_service.py +++ b/tests/unit/gapic/bigquery_connection_v1/test_connection_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,13 +23,13 @@ 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 gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.bigquery_connection_v1.services.connection_service import ( ConnectionServiceAsyncClient, @@ -40,14 +39,44 @@ ) from google.cloud.bigquery_connection_v1.services.connection_service import pagers from google.cloud.bigquery_connection_v1.services.connection_service import transports +from google.cloud.bigquery_connection_v1.services.connection_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.bigquery_connection_v1.services.connection_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.bigquery_connection_v1.types import connection from google.cloud.bigquery_connection_v1.types import connection as gcbc_connection -from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore -from google.iam.v1 import options_pb2 as options # type: ignore -from google.iam.v1 import policy_pb2 as policy # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.type import expr_pb2 as expr # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.type import expr_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", [ConnectionServiceClient, ConnectionServiceAsyncClient,] ) def test_connection_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_connection_service_client_from_service_account_info(client_class): "client_class", [ConnectionServiceClient, ConnectionServiceAsyncClient,] ) def test_connection_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_connection_service_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ConnectionServiceClient, "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_create_connection( transport: str = "grpc", request_type=gcbc_connection.CreateConnectionRequest ): client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -490,29 +519,20 @@ def test_create_connection( instance_id="instance_id_value" ), ) - response = client.create_connection(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == gcbc_connection.CreateConnectionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcbc_connection.Connection) - assert response.name == "name_value" - assert response.friendly_name == "friendly_name_value" - assert response.description == "description_value" - assert response.creation_time == 1379 - assert response.last_modified_time == 1890 - assert response.has_credential is True @@ -524,7 +544,7 @@ def test_create_connection_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 = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -534,7 +554,6 @@ def test_create_connection_empty_call(): client.create_connection() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == gcbc_connection.CreateConnectionRequest() @@ -544,7 +563,7 @@ async def test_create_connection_async( request_type=gcbc_connection.CreateConnectionRequest, ): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -566,28 +585,20 @@ async def test_create_connection_async( has_credential=True, ) ) - response = await client.create_connection(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == gcbc_connection.CreateConnectionRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcbc_connection.Connection) - assert response.name == "name_value" - assert response.friendly_name == "friendly_name_value" - assert response.description == "description_value" - assert response.creation_time == 1379 - assert response.last_modified_time == 1890 - assert response.has_credential is True @@ -597,11 +608,12 @@ async def test_create_connection_async_from_dict(): def test_create_connection_field_headers(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(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 = gcbc_connection.CreateConnectionRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -609,7 +621,6 @@ def test_create_connection_field_headers(): type(client.transport.create_connection), "__call__" ) as call: call.return_value = gcbc_connection.Connection() - client.create_connection(request) # Establish that the underlying gRPC stub method was called. @@ -625,12 +636,13 @@ def test_create_connection_field_headers(): @pytest.mark.asyncio async def test_create_connection_field_headers_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + 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 = gcbc_connection.CreateConnectionRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -640,7 +652,6 @@ async def test_create_connection_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcbc_connection.Connection() ) - await client.create_connection(request) # Establish that the underlying gRPC stub method was called. @@ -654,7 +665,7 @@ async def test_create_connection_field_headers_async(): def test_create_connection_flattened(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -662,7 +673,6 @@ def test_create_connection_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = gcbc_connection.Connection() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_connection( @@ -675,16 +685,13 @@ def test_create_connection_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].connection == gcbc_connection.Connection(name="name_value") - assert args[0].connection_id == "connection_id_value" def test_create_connection_flattened_error(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -700,7 +707,7 @@ def test_create_connection_flattened_error(): @pytest.mark.asyncio async def test_create_connection_flattened_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -725,18 +732,15 @@ async def test_create_connection_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].connection == gcbc_connection.Connection(name="name_value") - assert args[0].connection_id == "connection_id_value" @pytest.mark.asyncio async def test_create_connection_flattened_error_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -754,7 +758,7 @@ def test_get_connection( transport: str = "grpc", request_type=connection.GetConnectionRequest ): client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -773,29 +777,20 @@ def test_get_connection( has_credential=True, cloud_sql=connection.CloudSqlProperties(instance_id="instance_id_value"), ) - response = client.get_connection(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == connection.GetConnectionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, connection.Connection) - assert response.name == "name_value" - assert response.friendly_name == "friendly_name_value" - assert response.description == "description_value" - assert response.creation_time == 1379 - assert response.last_modified_time == 1890 - assert response.has_credential is True @@ -807,7 +802,7 @@ def test_get_connection_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 = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -815,7 +810,6 @@ def test_get_connection_empty_call(): client.get_connection() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == connection.GetConnectionRequest() @@ -824,7 +818,7 @@ async def test_get_connection_async( transport: str = "grpc_asyncio", request_type=connection.GetConnectionRequest ): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -844,28 +838,20 @@ async def test_get_connection_async( has_credential=True, ) ) - response = await client.get_connection(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == connection.GetConnectionRequest() # Establish that the response is the type that we expect. assert isinstance(response, connection.Connection) - assert response.name == "name_value" - assert response.friendly_name == "friendly_name_value" - assert response.description == "description_value" - assert response.creation_time == 1379 - assert response.last_modified_time == 1890 - assert response.has_credential is True @@ -875,17 +861,17 @@ async def test_get_connection_async_from_dict(): def test_get_connection_field_headers(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(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 = connection.GetConnectionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_connection), "__call__") as call: call.return_value = connection.Connection() - client.get_connection(request) # Establish that the underlying gRPC stub method was called. @@ -901,12 +887,13 @@ def test_get_connection_field_headers(): @pytest.mark.asyncio async def test_get_connection_field_headers_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + 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 = connection.GetConnectionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -914,7 +901,6 @@ async def test_get_connection_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( connection.Connection() ) - await client.get_connection(request) # Establish that the underlying gRPC stub method was called. @@ -928,13 +914,12 @@ async def test_get_connection_field_headers_async(): def test_get_connection_flattened(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_connection), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = connection.Connection() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_connection(name="name_value",) @@ -943,12 +928,11 @@ def test_get_connection_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_connection_flattened_error(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -961,7 +945,7 @@ def test_get_connection_flattened_error(): @pytest.mark.asyncio async def test_get_connection_flattened_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -980,14 +964,13 @@ async def test_get_connection_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_connection_flattened_error_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1002,7 +985,7 @@ def test_list_connections( transport: str = "grpc", request_type=connection.ListConnectionsRequest ): client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1015,19 +998,15 @@ def test_list_connections( call.return_value = connection.ListConnectionsResponse( next_page_token="next_page_token_value", ) - response = client.list_connections(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == connection.ListConnectionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListConnectionsPager) - assert response.next_page_token == "next_page_token_value" @@ -1039,7 +1018,7 @@ def test_list_connections_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 = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1047,7 +1026,6 @@ def test_list_connections_empty_call(): client.list_connections() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == connection.ListConnectionsRequest() @@ -1056,7 +1034,7 @@ async def test_list_connections_async( transport: str = "grpc_asyncio", request_type=connection.ListConnectionsRequest ): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1069,18 +1047,15 @@ async def test_list_connections_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( connection.ListConnectionsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_connections(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == connection.ListConnectionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListConnectionsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -1090,17 +1065,17 @@ async def test_list_connections_async_from_dict(): def test_list_connections_field_headers(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(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 = connection.ListConnectionsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_connections), "__call__") as call: call.return_value = connection.ListConnectionsResponse() - client.list_connections(request) # Establish that the underlying gRPC stub method was called. @@ -1116,12 +1091,13 @@ def test_list_connections_field_headers(): @pytest.mark.asyncio async def test_list_connections_field_headers_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + 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 = connection.ListConnectionsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1129,7 +1105,6 @@ async def test_list_connections_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( connection.ListConnectionsResponse() ) - await client.list_connections(request) # Establish that the underlying gRPC stub method was called. @@ -1143,13 +1118,12 @@ async def test_list_connections_field_headers_async(): def test_list_connections_flattened(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_connections), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = connection.ListConnectionsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_connections(parent="parent_value",) @@ -1158,12 +1132,11 @@ def test_list_connections_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_connections_flattened_error(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1176,7 +1149,7 @@ def test_list_connections_flattened_error(): @pytest.mark.asyncio async def test_list_connections_flattened_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1195,14 +1168,13 @@ async def test_list_connections_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_connections_flattened_error_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1214,7 +1186,7 @@ async def test_list_connections_flattened_error_async(): def test_list_connections_pager(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials,) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_connections), "__call__") as call: @@ -1252,7 +1224,7 @@ def test_list_connections_pager(): def test_list_connections_pages(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials,) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_connections), "__call__") as call: @@ -1282,7 +1254,9 @@ def test_list_connections_pages(): @pytest.mark.asyncio async def test_list_connections_async_pager(): - client = ConnectionServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ConnectionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1319,7 +1293,9 @@ async def test_list_connections_async_pager(): @pytest.mark.asyncio async def test_list_connections_async_pages(): - client = ConnectionServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ConnectionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1355,7 +1331,7 @@ def test_update_connection( transport: str = "grpc", request_type=gcbc_connection.UpdateConnectionRequest ): client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1378,29 +1354,20 @@ def test_update_connection( instance_id="instance_id_value" ), ) - response = client.update_connection(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == gcbc_connection.UpdateConnectionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcbc_connection.Connection) - assert response.name == "name_value" - assert response.friendly_name == "friendly_name_value" - assert response.description == "description_value" - assert response.creation_time == 1379 - assert response.last_modified_time == 1890 - assert response.has_credential is True @@ -1412,7 +1379,7 @@ def test_update_connection_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 = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1422,7 +1389,6 @@ def test_update_connection_empty_call(): client.update_connection() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == gcbc_connection.UpdateConnectionRequest() @@ -1432,7 +1398,7 @@ async def test_update_connection_async( request_type=gcbc_connection.UpdateConnectionRequest, ): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1454,28 +1420,20 @@ async def test_update_connection_async( has_credential=True, ) ) - response = await client.update_connection(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == gcbc_connection.UpdateConnectionRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcbc_connection.Connection) - assert response.name == "name_value" - assert response.friendly_name == "friendly_name_value" - assert response.description == "description_value" - assert response.creation_time == 1379 - assert response.last_modified_time == 1890 - assert response.has_credential is True @@ -1485,11 +1443,12 @@ async def test_update_connection_async_from_dict(): def test_update_connection_field_headers(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(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 = gcbc_connection.UpdateConnectionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1497,7 +1456,6 @@ def test_update_connection_field_headers(): type(client.transport.update_connection), "__call__" ) as call: call.return_value = gcbc_connection.Connection() - client.update_connection(request) # Establish that the underlying gRPC stub method was called. @@ -1513,12 +1471,13 @@ def test_update_connection_field_headers(): @pytest.mark.asyncio async def test_update_connection_field_headers_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + 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 = gcbc_connection.UpdateConnectionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1528,7 +1487,6 @@ async def test_update_connection_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcbc_connection.Connection() ) - await client.update_connection(request) # Establish that the underlying gRPC stub method was called. @@ -1542,7 +1500,7 @@ async def test_update_connection_field_headers_async(): def test_update_connection_flattened(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1550,29 +1508,25 @@ def test_update_connection_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = gcbc_connection.Connection() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_connection( name="name_value", connection=gcbc_connection.Connection(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].connection == gcbc_connection.Connection(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_connection_flattened_error(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1581,14 +1535,14 @@ def test_update_connection_flattened_error(): gcbc_connection.UpdateConnectionRequest(), name="name_value", connection=gcbc_connection.Connection(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_connection_flattened_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1606,25 +1560,22 @@ async def test_update_connection_flattened_async(): response = await client.update_connection( name="name_value", connection=gcbc_connection.Connection(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].connection == gcbc_connection.Connection(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_connection_flattened_error_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1634,7 +1585,7 @@ async def test_update_connection_flattened_error_async(): gcbc_connection.UpdateConnectionRequest(), name="name_value", connection=gcbc_connection.Connection(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1642,7 +1593,7 @@ def test_delete_connection( transport: str = "grpc", request_type=connection.DeleteConnectionRequest ): client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1655,13 +1606,11 @@ def test_delete_connection( ) as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_connection(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == connection.DeleteConnectionRequest() # Establish that the response is the type that we expect. @@ -1676,7 +1625,7 @@ def test_delete_connection_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 = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1686,7 +1635,6 @@ def test_delete_connection_empty_call(): client.delete_connection() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == connection.DeleteConnectionRequest() @@ -1695,7 +1643,7 @@ async def test_delete_connection_async( transport: str = "grpc_asyncio", request_type=connection.DeleteConnectionRequest ): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1708,13 +1656,11 @@ async def test_delete_connection_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_connection(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == connection.DeleteConnectionRequest() # Establish that the response is the type that we expect. @@ -1727,11 +1673,12 @@ async def test_delete_connection_async_from_dict(): def test_delete_connection_field_headers(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(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 = connection.DeleteConnectionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1739,7 +1686,6 @@ def test_delete_connection_field_headers(): type(client.transport.delete_connection), "__call__" ) as call: call.return_value = None - client.delete_connection(request) # Establish that the underlying gRPC stub method was called. @@ -1755,12 +1701,13 @@ def test_delete_connection_field_headers(): @pytest.mark.asyncio async def test_delete_connection_field_headers_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + 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 = connection.DeleteConnectionRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1768,7 +1715,6 @@ async def test_delete_connection_field_headers_async(): type(client.transport.delete_connection), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_connection(request) # Establish that the underlying gRPC stub method was called. @@ -1782,7 +1728,7 @@ async def test_delete_connection_field_headers_async(): def test_delete_connection_flattened(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1790,7 +1736,6 @@ def test_delete_connection_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = None - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_connection(name="name_value",) @@ -1799,12 +1744,11 @@ def test_delete_connection_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_connection_flattened_error(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1817,7 +1761,7 @@ def test_delete_connection_flattened_error(): @pytest.mark.asyncio async def test_delete_connection_flattened_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1836,14 +1780,13 @@ async def test_delete_connection_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_connection_flattened_error_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1855,10 +1798,10 @@ async def test_delete_connection_flattened_error_async(): def test_get_iam_policy( - transport: str = "grpc", request_type=iam_policy.GetIamPolicyRequest + transport: str = "grpc", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1868,22 +1811,17 @@ def test_get_iam_policy( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy(version=774, etag=b"etag_blob",) - + call.return_value = policy_pb2.Policy(version=774, etag=b"etag_blob",) response = client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.GetIamPolicyRequest() + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() # Establish that the response is the type that we expect. - - assert isinstance(response, policy.Policy) - + assert isinstance(response, policy_pb2.Policy) assert response.version == 774 - assert response.etag == b"etag_blob" @@ -1895,7 +1833,7 @@ def test_get_iam_policy_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 = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1903,16 +1841,15 @@ def test_get_iam_policy_empty_call(): client.get_iam_policy() call.assert_called() _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.GetIamPolicyRequest() + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() @pytest.mark.asyncio async def test_get_iam_policy_async( - transport: str = "grpc_asyncio", request_type=iam_policy.GetIamPolicyRequest + transport: str = "grpc_asyncio", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1923,22 +1860,18 @@ async def test_get_iam_policy_async( with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - policy.Policy(version=774, etag=b"etag_blob",) + policy_pb2.Policy(version=774, etag=b"etag_blob",) ) - response = await client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.GetIamPolicyRequest() + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, policy.Policy) - + assert isinstance(response, policy_pb2.Policy) assert response.version == 774 - assert response.etag == b"etag_blob" @@ -1948,17 +1881,17 @@ async def test_get_iam_policy_async_from_dict(): def test_get_iam_policy_field_headers(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(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 = iam_policy.GetIamPolicyRequest() + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: - call.return_value = policy.Policy() - + call.return_value = policy_pb2.Policy() client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -1974,18 +1907,18 @@ def test_get_iam_policy_field_headers(): @pytest.mark.asyncio async def test_get_iam_policy_field_headers_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + 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 = iam_policy.GetIamPolicyRequest() + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) - + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) await client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -1999,29 +1932,27 @@ async def test_get_iam_policy_field_headers_async(): def test_get_iam_policy_from_dict_foreign(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy() - + call.return_value = policy_pb2.Policy() response = client.get_iam_policy( request={ "resource": "resource_value", - "options": options.GetPolicyOptions(requested_policy_version=2598), + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), } ) call.assert_called() def test_get_iam_policy_flattened(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy() - + call.return_value = policy_pb2.Policy() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_iam_policy(resource="resource_value",) @@ -2030,33 +1961,32 @@ def test_get_iam_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" def test_get_iam_policy_flattened_error(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_iam_policy( - iam_policy.GetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.GetIamPolicyRequest(), resource="resource_value", ) @pytest.mark.asyncio async def test_get_iam_policy_flattened_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy() + call.return_value = policy_pb2.Policy() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.get_iam_policy(resource="resource_value",) @@ -2065,29 +1995,28 @@ async def test_get_iam_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" @pytest.mark.asyncio async def test_get_iam_policy_flattened_error_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_iam_policy( - iam_policy.GetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.GetIamPolicyRequest(), resource="resource_value", ) def test_set_iam_policy( - transport: str = "grpc", request_type=iam_policy.SetIamPolicyRequest + transport: str = "grpc", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2097,22 +2026,17 @@ def test_set_iam_policy( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy(version=774, etag=b"etag_blob",) - + call.return_value = policy_pb2.Policy(version=774, etag=b"etag_blob",) response = client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.SetIamPolicyRequest() + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() # Establish that the response is the type that we expect. - - assert isinstance(response, policy.Policy) - + assert isinstance(response, policy_pb2.Policy) assert response.version == 774 - assert response.etag == b"etag_blob" @@ -2124,7 +2048,7 @@ def test_set_iam_policy_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 = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2132,16 +2056,15 @@ def test_set_iam_policy_empty_call(): client.set_iam_policy() call.assert_called() _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.SetIamPolicyRequest() + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() @pytest.mark.asyncio async def test_set_iam_policy_async( - transport: str = "grpc_asyncio", request_type=iam_policy.SetIamPolicyRequest + transport: str = "grpc_asyncio", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2152,22 +2075,18 @@ async def test_set_iam_policy_async( with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - policy.Policy(version=774, etag=b"etag_blob",) + policy_pb2.Policy(version=774, etag=b"etag_blob",) ) - response = await client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.SetIamPolicyRequest() + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, policy.Policy) - + assert isinstance(response, policy_pb2.Policy) assert response.version == 774 - assert response.etag == b"etag_blob" @@ -2177,17 +2096,17 @@ async def test_set_iam_policy_async_from_dict(): def test_set_iam_policy_field_headers(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(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 = iam_policy.SetIamPolicyRequest() + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: - call.return_value = policy.Policy() - + call.return_value = policy_pb2.Policy() client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -2203,18 +2122,18 @@ def test_set_iam_policy_field_headers(): @pytest.mark.asyncio async def test_set_iam_policy_field_headers_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + 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 = iam_policy.SetIamPolicyRequest() + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) - + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) await client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -2228,29 +2147,27 @@ async def test_set_iam_policy_field_headers_async(): def test_set_iam_policy_from_dict_foreign(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy() - + call.return_value = policy_pb2.Policy() response = client.set_iam_policy( request={ "resource": "resource_value", - "policy": policy.Policy(version=774), + "policy": policy_pb2.Policy(version=774), } ) call.assert_called() def test_set_iam_policy_flattened(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy() - + call.return_value = policy_pb2.Policy() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.set_iam_policy(resource="resource_value",) @@ -2259,33 +2176,32 @@ def test_set_iam_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" def test_set_iam_policy_flattened_error(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.set_iam_policy( - iam_policy.SetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.SetIamPolicyRequest(), resource="resource_value", ) @pytest.mark.asyncio async def test_set_iam_policy_flattened_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy.Policy() + call.return_value = policy_pb2.Policy() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.set_iam_policy(resource="resource_value",) @@ -2294,29 +2210,28 @@ async def test_set_iam_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" @pytest.mark.asyncio async def test_set_iam_policy_flattened_error_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.set_iam_policy( - iam_policy.SetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.SetIamPolicyRequest(), resource="resource_value", ) def test_test_iam_permissions( - transport: str = "grpc", request_type=iam_policy.TestIamPermissionsRequest + transport: str = "grpc", request_type=iam_policy_pb2.TestIamPermissionsRequest ): client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2328,22 +2243,18 @@ def test_test_iam_permissions( type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = iam_policy.TestIamPermissionsResponse( + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( permissions=["permissions_value"], ) - response = client.test_iam_permissions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.TestIamPermissionsRequest() + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() # Establish that the response is the type that we expect. - - assert isinstance(response, iam_policy.TestIamPermissionsResponse) - + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) assert response.permissions == ["permissions_value"] @@ -2355,7 +2266,7 @@ def test_test_iam_permissions_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 = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2365,16 +2276,16 @@ def test_test_iam_permissions_empty_call(): client.test_iam_permissions() call.assert_called() _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.TestIamPermissionsRequest() + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() @pytest.mark.asyncio async def test_test_iam_permissions_async( - transport: str = "grpc_asyncio", request_type=iam_policy.TestIamPermissionsRequest + transport: str = "grpc_asyncio", + request_type=iam_policy_pb2.TestIamPermissionsRequest, ): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2387,20 +2298,19 @@ async def test_test_iam_permissions_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - iam_policy.TestIamPermissionsResponse(permissions=["permissions_value"],) + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) ) - response = await client.test_iam_permissions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - - assert args[0] == iam_policy.TestIamPermissionsRequest() + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy.TestIamPermissionsResponse) - + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) assert response.permissions == ["permissions_value"] @@ -2410,19 +2320,19 @@ async def test_test_iam_permissions_async_from_dict(): def test_test_iam_permissions_field_headers(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(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 = iam_policy.TestIamPermissionsRequest() + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.test_iam_permissions), "__call__" ) as call: - call.return_value = iam_policy.TestIamPermissionsResponse() - + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() client.test_iam_permissions(request) # Establish that the underlying gRPC stub method was called. @@ -2438,12 +2348,13 @@ def test_test_iam_permissions_field_headers(): @pytest.mark.asyncio async def test_test_iam_permissions_field_headers_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + 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 = iam_policy.TestIamPermissionsRequest() + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2451,9 +2362,8 @@ async def test_test_iam_permissions_field_headers_async(): type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - iam_policy.TestIamPermissionsResponse() + iam_policy_pb2.TestIamPermissionsResponse() ) - await client.test_iam_permissions(request) # Establish that the underlying gRPC stub method was called. @@ -2467,14 +2377,13 @@ async def test_test_iam_permissions_field_headers_async(): def test_test_iam_permissions_from_dict_foreign(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = iam_policy.TestIamPermissionsResponse() - + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() response = client.test_iam_permissions( request={ "resource": "resource_value", @@ -2485,15 +2394,14 @@ def test_test_iam_permissions_from_dict_foreign(): def test_test_iam_permissions_flattened(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = iam_policy.TestIamPermissionsResponse() - + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.test_iam_permissions( @@ -2504,20 +2412,18 @@ def test_test_iam_permissions_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" - assert args[0].permissions == ["permissions_value"] def test_test_iam_permissions_flattened_error(): - client = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.test_iam_permissions( - iam_policy.TestIamPermissionsRequest(), + iam_policy_pb2.TestIamPermissionsRequest(), resource="resource_value", permissions=["permissions_value"], ) @@ -2526,7 +2432,7 @@ def test_test_iam_permissions_flattened_error(): @pytest.mark.asyncio async def test_test_iam_permissions_flattened_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2534,10 +2440,10 @@ async def test_test_iam_permissions_flattened_async(): type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = iam_policy.TestIamPermissionsResponse() + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - iam_policy.TestIamPermissionsResponse() + iam_policy_pb2.TestIamPermissionsResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. @@ -2549,23 +2455,21 @@ async def test_test_iam_permissions_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" - assert args[0].permissions == ["permissions_value"] @pytest.mark.asyncio async def test_test_iam_permissions_flattened_error_async(): client = ConnectionServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.test_iam_permissions( - iam_policy.TestIamPermissionsRequest(), + iam_policy_pb2.TestIamPermissionsRequest(), resource="resource_value", permissions=["permissions_value"], ) @@ -2574,16 +2478,16 @@ async def test_test_iam_permissions_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConnectionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ConnectionServiceClient( - 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.ConnectionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ConnectionServiceClient( @@ -2593,7 +2497,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.ConnectionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ConnectionServiceClient( @@ -2604,7 +2508,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ConnectionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = ConnectionServiceClient(transport=transport) assert client.transport is transport @@ -2613,13 +2517,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ConnectionServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.ConnectionServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2634,23 +2538,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 = ConnectionServiceClient(credentials=credentials.AnonymousCredentials(),) + client = ConnectionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.ConnectionServiceGrpcTransport,) def test_connection_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.ConnectionServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2662,7 +2566,7 @@ def test_connection_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ConnectionServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2682,15 +2586,40 @@ def test_connection_service_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_connection_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.bigquery_connection_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ConnectionServiceTransport( + 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/bigquery", + "https://www.googleapis.com/auth/cloud-platform", + ), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_connection_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.bigquery_connection_v1.services.connection_service.transports.ConnectionServiceTransport._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.ConnectionServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -2706,19 +2635,36 @@ def test_connection_service_base_transport_with_credentials_file(): def test_connection_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.bigquery_connection_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConnectionServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_connection_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) + ConnectionServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + "https://www.googleapis.com/auth/bigquery", + "https://www.googleapis.com/auth/cloud-platform", + ), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_connection_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) ConnectionServiceClient() adc.assert_called_once_with( scopes=( @@ -2729,14 +2675,44 @@ def test_connection_service_auth_adc(): ) -def test_connection_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.ConnectionServiceGrpcTransport, + transports.ConnectionServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_connection_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.ConnectionServiceGrpcTransport( - 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/bigquery", + "https://www.googleapis.com/auth/cloud-platform", + ), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ConnectionServiceGrpcTransport, + transports.ConnectionServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_connection_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/bigquery", @@ -2746,6 +2722,121 @@ def test_connection_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ConnectionServiceGrpcTransport, grpc_helpers), + (transports.ConnectionServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_connection_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( + "bigqueryconnection.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + "https://www.googleapis.com/auth/bigquery", + "https://www.googleapis.com/auth/cloud-platform", + ), + scopes=["1", "2"], + default_host="bigqueryconnection.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.ConnectionServiceGrpcTransport, grpc_helpers), + (transports.ConnectionServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_connection_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( + "bigqueryconnection.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=( + "https://www.googleapis.com/auth/bigquery", + "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.ConnectionServiceGrpcTransport, grpc_helpers), + (transports.ConnectionServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_connection_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( + "bigqueryconnection.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", [ @@ -2754,7 +2845,7 @@ def test_connection_service_transport_auth_adc(): ], ) def test_connection_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: @@ -2796,7 +2887,7 @@ def test_connection_service_grpc_transport_client_cert_source_for_mtls(transport def test_connection_service_host_no_port(): client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="bigqueryconnection.googleapis.com" ), @@ -2806,7 +2897,7 @@ def test_connection_service_host_no_port(): def test_connection_service_host_with_port(): client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="bigqueryconnection.googleapis.com:8000" ), @@ -2862,9 +2953,9 @@ def test_connection_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", @@ -2948,7 +3039,6 @@ def test_connection_path(): project = "squid" location = "clam" connection = "whelk" - expected = "projects/{project}/locations/{location}/connections/{connection}".format( project=project, location=location, connection=connection, ) @@ -2971,7 +3061,6 @@ def test_parse_connection_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2992,7 +3081,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = ConnectionServiceClient.common_folder_path(folder) assert expected == actual @@ -3011,7 +3099,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = ConnectionServiceClient.common_organization_path(organization) assert expected == actual @@ -3030,7 +3117,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = ConnectionServiceClient.common_project_path(project) assert expected == actual @@ -3050,7 +3136,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -3077,7 +3162,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.ConnectionServiceTransport, "_prep_wrapped_messages" ) as prep: client = ConnectionServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3086,6 +3171,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = ConnectionServiceClient.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)