From e761cfffccd416a4552ccdece2a6d6f1ae84cad8 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sun, 16 May 2021 10:22:01 +0000 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.46.3 (#76) PiperOrigin-RevId: 373649163 Source-Link: https://github.com/googleapis/googleapis/commit/7e1b14e6c7a9ab96d2db7e4a131981f162446d34 Source-Link: https://github.com/googleapis/googleapis-gen/commit/0a3c7d272d697796db75857bac73905c68e498c3 fix: add async client to %name_%version/init.py chore: add autogenerated snippets chore: remove auth, policy, and options from the reserved names list feat: support self-signed JWT flow for service accounts chore: enable GAPIC metadata generation chore: sort subpackages in %namespace/%name/init.py --- docs/accessapproval_v1/access_approval.rst | 1 - google/cloud/accessapproval/__init__.py | 14 +- google/cloud/accessapproval_v1/__init__.py | 9 +- .../accessapproval_v1/gapic_metadata.json | 93 +++ .../accessapproval_v1/services/__init__.py | 1 - .../services/access_approval/__init__.py | 2 - .../services/access_approval/async_client.py | 55 +- .../services/access_approval/client.py | 82 +-- .../services/access_approval/pagers.py | 4 +- .../access_approval/transports/__init__.py | 2 - .../access_approval/transports/base.py | 155 +++-- .../access_approval/transports/grpc.py | 30 +- .../transports/grpc_asyncio.py | 29 +- .../cloud/accessapproval_v1/types/__init__.py | 2 - .../accessapproval_v1/types/accessapproval.py | 103 ++-- scripts/fixup_accessapproval_v1_keywords.py | 19 +- tests/__init__.py | 15 + tests/unit/__init__.py | 15 + tests/unit/gapic/__init__.py | 15 + .../unit/gapic/accessapproval_v1/__init__.py | 1 - .../accessapproval_v1/test_access_approval.py | 570 +++++++++++------- 21 files changed, 746 insertions(+), 471 deletions(-) create mode 100644 google/cloud/accessapproval_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/accessapproval_v1/access_approval.rst b/docs/accessapproval_v1/access_approval.rst index 5b5d17d..35305db 100644 --- a/docs/accessapproval_v1/access_approval.rst +++ b/docs/accessapproval_v1/access_approval.rst @@ -5,7 +5,6 @@ AccessApproval :members: :inherited-members: - .. automodule:: google.cloud.accessapproval_v1.services.access_approval.pagers :members: :inherited-members: diff --git a/google/cloud/accessapproval/__init__.py b/google/cloud/accessapproval/__init__.py index b36f365..d634c6d 100644 --- a/google/cloud/accessapproval/__init__.py +++ b/google/cloud/accessapproval/__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.accessapproval_v1.services.access_approval.async_client import ( - AccessApprovalAsyncClient, -) from google.cloud.accessapproval_v1.services.access_approval.client import ( AccessApprovalClient, ) +from google.cloud.accessapproval_v1.services.access_approval.async_client import ( + AccessApprovalAsyncClient, +) + from google.cloud.accessapproval_v1.types.accessapproval import AccessApprovalSettings from google.cloud.accessapproval_v1.types.accessapproval import AccessLocations from google.cloud.accessapproval_v1.types.accessapproval import AccessReason @@ -37,7 +37,6 @@ ) from google.cloud.accessapproval_v1.types.accessapproval import DismissDecision from google.cloud.accessapproval_v1.types.accessapproval import EnrolledService -from google.cloud.accessapproval_v1.types.accessapproval import EnrollmentLevel from google.cloud.accessapproval_v1.types.accessapproval import ( GetAccessApprovalSettingsMessage, ) @@ -54,10 +53,11 @@ from google.cloud.accessapproval_v1.types.accessapproval import ( UpdateAccessApprovalSettingsMessage, ) +from google.cloud.accessapproval_v1.types.accessapproval import EnrollmentLevel __all__ = ( - "AccessApprovalAsyncClient", "AccessApprovalClient", + "AccessApprovalAsyncClient", "AccessApprovalSettings", "AccessLocations", "AccessReason", @@ -68,11 +68,11 @@ "DismissApprovalRequestMessage", "DismissDecision", "EnrolledService", - "EnrollmentLevel", "GetAccessApprovalSettingsMessage", "GetApprovalRequestMessage", "ListApprovalRequestsMessage", "ListApprovalRequestsResponse", "ResourceProperties", "UpdateAccessApprovalSettingsMessage", + "EnrollmentLevel", ) diff --git a/google/cloud/accessapproval_v1/__init__.py b/google/cloud/accessapproval_v1/__init__.py index 116022f..d31a69a 100644 --- a/google/cloud/accessapproval_v1/__init__.py +++ b/google/cloud/accessapproval_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.access_approval import AccessApprovalClient +from .services.access_approval import AccessApprovalAsyncClient + from .types.accessapproval import AccessApprovalSettings from .types.accessapproval import AccessLocations from .types.accessapproval import AccessReason @@ -26,16 +27,17 @@ from .types.accessapproval import DismissApprovalRequestMessage from .types.accessapproval import DismissDecision from .types.accessapproval import EnrolledService -from .types.accessapproval import EnrollmentLevel from .types.accessapproval import GetAccessApprovalSettingsMessage from .types.accessapproval import GetApprovalRequestMessage from .types.accessapproval import ListApprovalRequestsMessage from .types.accessapproval import ListApprovalRequestsResponse from .types.accessapproval import ResourceProperties from .types.accessapproval import UpdateAccessApprovalSettingsMessage - +from .types.accessapproval import EnrollmentLevel __all__ = ( + "AccessApprovalAsyncClient", + "AccessApprovalClient", "AccessApprovalSettings", "AccessLocations", "AccessReason", @@ -53,5 +55,4 @@ "ListApprovalRequestsResponse", "ResourceProperties", "UpdateAccessApprovalSettingsMessage", - "AccessApprovalClient", ) diff --git a/google/cloud/accessapproval_v1/gapic_metadata.json b/google/cloud/accessapproval_v1/gapic_metadata.json new file mode 100644 index 0000000..3d26923 --- /dev/null +++ b/google/cloud/accessapproval_v1/gapic_metadata.json @@ -0,0 +1,93 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.accessapproval_v1", + "protoPackage": "google.cloud.accessapproval.v1", + "schema": "1.0", + "services": { + "AccessApproval": { + "clients": { + "grpc": { + "libraryClient": "AccessApprovalClient", + "rpcs": { + "ApproveApprovalRequest": { + "methods": [ + "approve_approval_request" + ] + }, + "DeleteAccessApprovalSettings": { + "methods": [ + "delete_access_approval_settings" + ] + }, + "DismissApprovalRequest": { + "methods": [ + "dismiss_approval_request" + ] + }, + "GetAccessApprovalSettings": { + "methods": [ + "get_access_approval_settings" + ] + }, + "GetApprovalRequest": { + "methods": [ + "get_approval_request" + ] + }, + "ListApprovalRequests": { + "methods": [ + "list_approval_requests" + ] + }, + "UpdateAccessApprovalSettings": { + "methods": [ + "update_access_approval_settings" + ] + } + } + }, + "grpc-async": { + "libraryClient": "AccessApprovalAsyncClient", + "rpcs": { + "ApproveApprovalRequest": { + "methods": [ + "approve_approval_request" + ] + }, + "DeleteAccessApprovalSettings": { + "methods": [ + "delete_access_approval_settings" + ] + }, + "DismissApprovalRequest": { + "methods": [ + "dismiss_approval_request" + ] + }, + "GetAccessApprovalSettings": { + "methods": [ + "get_access_approval_settings" + ] + }, + "GetApprovalRequest": { + "methods": [ + "get_approval_request" + ] + }, + "ListApprovalRequests": { + "methods": [ + "list_approval_requests" + ] + }, + "UpdateAccessApprovalSettings": { + "methods": [ + "update_access_approval_settings" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/accessapproval_v1/services/__init__.py b/google/cloud/accessapproval_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/accessapproval_v1/services/__init__.py +++ b/google/cloud/accessapproval_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/accessapproval_v1/services/access_approval/__init__.py b/google/cloud/accessapproval_v1/services/access_approval/__init__.py index 7e1811d..e31ab89 100644 --- a/google/cloud/accessapproval_v1/services/access_approval/__init__.py +++ b/google/cloud/accessapproval_v1/services/access_approval/__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 AccessApprovalClient from .async_client import AccessApprovalAsyncClient diff --git a/google/cloud/accessapproval_v1/services/access_approval/async_client.py b/google/cloud/accessapproval_v1/services/access_approval/async_client.py index 3e8171e..2d9902c 100644 --- a/google/cloud/accessapproval_v1/services/access_approval/async_client.py +++ b/google/cloud/accessapproval_v1/services/access_approval/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,17 +20,16 @@ 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.accessapproval_v1.services.access_approval import pagers from google.cloud.accessapproval_v1.types import accessapproval -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import AccessApprovalTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import AccessApprovalGrpcAsyncIOTransport from .client import AccessApprovalClient @@ -87,24 +84,20 @@ class AccessApprovalAsyncClient: parse_common_billing_account_path = staticmethod( AccessApprovalClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(AccessApprovalClient.common_folder_path) parse_common_folder_path = staticmethod( AccessApprovalClient.parse_common_folder_path ) - common_organization_path = staticmethod( AccessApprovalClient.common_organization_path ) parse_common_organization_path = staticmethod( AccessApprovalClient.parse_common_organization_path ) - common_project_path = staticmethod(AccessApprovalClient.common_project_path) parse_common_project_path = staticmethod( AccessApprovalClient.parse_common_project_path ) - common_location_path = staticmethod(AccessApprovalClient.common_location_path) parse_common_location_path = staticmethod( AccessApprovalClient.parse_common_location_path @@ -112,7 +105,8 @@ class AccessApprovalAsyncClient: @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. @@ -127,7 +121,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 @@ -144,7 +138,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> AccessApprovalTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: AccessApprovalTransport: The transport used by the client instance. @@ -158,12 +152,12 @@ def transport(self) -> AccessApprovalTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, AccessApprovalTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the access approval client. + """Instantiates the access approval client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -195,7 +189,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = AccessApprovalClient( credentials=credentials, transport=transport, @@ -228,7 +221,6 @@ async def list_approval_requests( 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. @@ -258,7 +250,6 @@ async def list_approval_requests( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -270,7 +261,9 @@ async def list_approval_requests( initial=0.1, maximum=60.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=600.0, ), default_timeout=600.0, @@ -317,7 +310,6 @@ async def get_approval_request( 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. @@ -344,7 +336,6 @@ async def get_approval_request( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -356,7 +347,9 @@ async def get_approval_request( initial=0.1, maximum=60.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=600.0, ), default_timeout=600.0, @@ -393,7 +386,6 @@ async def approve_approval_request( request (:class:`google.cloud.accessapproval_v1.types.ApproveApprovalRequestMessage`): The request object. Request to approve an ApprovalRequest. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -407,7 +399,6 @@ async def approve_approval_request( """ # Create or coerce a protobuf request object. - request = accessapproval.ApproveApprovalRequestMessage(request) # Wrap the RPC method; this adds retry and timeout information, @@ -453,7 +444,6 @@ async def dismiss_approval_request( request (:class:`google.cloud.accessapproval_v1.types.DismissApprovalRequestMessage`): The request object. Request to dismiss an approval request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -467,7 +457,6 @@ async def dismiss_approval_request( """ # Create or coerce a protobuf request object. - request = accessapproval.DismissApprovalRequestMessage(request) # Wrap the RPC method; this adds retry and timeout information, @@ -513,7 +502,6 @@ async def get_access_approval_settings( 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. @@ -541,7 +529,6 @@ async def get_access_approval_settings( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -553,7 +540,9 @@ async def get_access_approval_settings( initial=0.1, maximum=60.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=600.0, ), default_timeout=600.0, @@ -577,7 +566,7 @@ async def update_access_approval_settings( request: accessapproval.UpdateAccessApprovalSettingsMessage = None, *, settings: accessapproval.AccessApprovalSettings = 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]] = (), @@ -611,7 +600,6 @@ async def update_access_approval_settings( 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. @@ -639,7 +627,6 @@ async def update_access_approval_settings( # If we have keyword arguments corresponding to fields on the # request, apply these. - if settings is not None: request.settings = settings if update_mask is not None: @@ -696,7 +683,6 @@ async def delete_access_approval_settings( 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. @@ -717,7 +703,6 @@ async def delete_access_approval_settings( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name diff --git a/google/cloud/accessapproval_v1/services/access_approval/client.py b/google/cloud/accessapproval_v1/services/access_approval/client.py index c5f2900..2d2b38f 100644 --- a/google/cloud/accessapproval_v1/services/access_approval/client.py +++ b/google/cloud/accessapproval_v1/services/access_approval/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 @@ -34,9 +32,8 @@ from google.cloud.accessapproval_v1.services.access_approval import pagers from google.cloud.accessapproval_v1.types import accessapproval -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import AccessApprovalTransport, DEFAULT_CLIENT_INFO from .transports.grpc import AccessApprovalGrpcTransport from .transports.grpc_asyncio import AccessApprovalGrpcAsyncIOTransport @@ -57,7 +54,7 @@ class AccessApprovalClientMeta(type): _transport_registry["grpc_asyncio"] = AccessApprovalGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[AccessApprovalTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -115,7 +112,8 @@ class AccessApprovalClient(metaclass=AccessApprovalClientMeta): @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: @@ -149,7 +147,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. @@ -166,7 +165,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 @@ -185,16 +184,17 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> AccessApprovalTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - AccessApprovalTransport: The transport used by the client instance. + AccessApprovalTransport: The transport used by the client + instance. """ return self._transport @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, ) @@ -207,7 +207,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 @@ -218,7 +218,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 @@ -229,7 +229,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 @@ -240,7 +240,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, ) @@ -254,12 +254,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, AccessApprovalTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the access approval client. + """Instantiates the access approval client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -314,9 +314,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: @@ -328,12 +329,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. @@ -348,8 +351,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -389,7 +392,6 @@ def list_approval_requests( This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -421,10 +423,8 @@ def list_approval_requests( # there are no flattened fields. if not isinstance(request, accessapproval.ListApprovalRequestsMessage): request = accessapproval.ListApprovalRequestsMessage(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -472,7 +472,6 @@ def get_approval_request( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -501,10 +500,8 @@ def get_approval_request( # there are no flattened fields. if not isinstance(request, accessapproval.GetApprovalRequestMessage): request = accessapproval.GetApprovalRequestMessage(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -542,7 +539,6 @@ def approve_approval_request( request (google.cloud.accessapproval_v1.types.ApproveApprovalRequestMessage): The request object. Request to approve an ApprovalRequest. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -556,7 +552,6 @@ def approve_approval_request( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a accessapproval.ApproveApprovalRequestMessage. # There's no risk of modifying the input as we've already verified @@ -603,7 +598,6 @@ def dismiss_approval_request( request (google.cloud.accessapproval_v1.types.DismissApprovalRequestMessage): The request object. Request to dismiss an approval request. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -617,7 +611,6 @@ def dismiss_approval_request( """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes # in a accessapproval.DismissApprovalRequestMessage. # There's no risk of modifying the input as we've already verified @@ -664,7 +657,6 @@ def get_access_approval_settings( 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. @@ -694,10 +686,8 @@ def get_access_approval_settings( # there are no flattened fields. if not isinstance(request, accessapproval.GetAccessApprovalSettingsMessage): request = accessapproval.GetAccessApprovalSettingsMessage(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -724,7 +714,7 @@ def update_access_approval_settings( request: accessapproval.UpdateAccessApprovalSettingsMessage = None, *, settings: accessapproval.AccessApprovalSettings = 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]] = (), @@ -758,7 +748,6 @@ def update_access_approval_settings( 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. @@ -788,10 +777,8 @@ def update_access_approval_settings( # there are no flattened fields. if not isinstance(request, accessapproval.UpdateAccessApprovalSettingsMessage): request = accessapproval.UpdateAccessApprovalSettingsMessage(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if settings is not None: request.settings = settings if update_mask is not None: @@ -846,7 +833,6 @@ def delete_access_approval_settings( 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. @@ -869,10 +855,8 @@ def delete_access_approval_settings( # there are no flattened fields. if not isinstance(request, accessapproval.DeleteAccessApprovalSettingsMessage): request = accessapproval.DeleteAccessApprovalSettingsMessage(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name diff --git a/google/cloud/accessapproval_v1/services/access_approval/pagers.py b/google/cloud/accessapproval_v1/services/access_approval/pagers.py index 965329e..f454990 100644 --- a/google/cloud/accessapproval_v1/services/access_approval/pagers.py +++ b/google/cloud/accessapproval_v1/services/access_approval/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/accessapproval_v1/services/access_approval/transports/__init__.py b/google/cloud/accessapproval_v1/services/access_approval/transports/__init__.py index d3ef506..6b64f0d 100644 --- a/google/cloud/accessapproval_v1/services/access_approval/transports/__init__.py +++ b/google/cloud/accessapproval_v1/services/access_approval/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/accessapproval_v1/services/access_approval/transports/base.py b/google/cloud/accessapproval_v1/services/access_approval/transports/base.py index 2511b7f..6f14ff5 100644 --- a/google/cloud/accessapproval_v1/services/access_approval/transports/base.py +++ b/google/cloud/accessapproval_v1/services/access_approval/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,20 +13,20 @@ # 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.accessapproval_v1.types import accessapproval -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -38,27 +37,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class AccessApprovalTransport(abc.ABC): """Abstract transport class for AccessApproval.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "accessapproval.googleapis.com" + def __init__( self, *, - host: str = "accessapproval.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 @@ -67,7 +80,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): @@ -81,29 +94,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 = { @@ -113,7 +173,9 @@ def _prep_wrapped_messages(self, client_info): initial=0.1, maximum=60.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=600.0, ), default_timeout=600.0, @@ -125,7 +187,9 @@ def _prep_wrapped_messages(self, client_info): initial=0.1, maximum=60.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=600.0, ), default_timeout=600.0, @@ -147,7 +211,9 @@ def _prep_wrapped_messages(self, client_info): initial=0.1, maximum=60.0, multiplier=1.3, - predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), deadline=600.0, ), default_timeout=600.0, @@ -168,11 +234,11 @@ def _prep_wrapped_messages(self, client_info): @property def list_approval_requests( self, - ) -> typing.Callable[ + ) -> Callable[ [accessapproval.ListApprovalRequestsMessage], - typing.Union[ + Union[ accessapproval.ListApprovalRequestsResponse, - typing.Awaitable[accessapproval.ListApprovalRequestsResponse], + Awaitable[accessapproval.ListApprovalRequestsResponse], ], ]: raise NotImplementedError() @@ -180,11 +246,10 @@ def list_approval_requests( @property def get_approval_request( self, - ) -> typing.Callable[ + ) -> Callable[ [accessapproval.GetApprovalRequestMessage], - typing.Union[ - accessapproval.ApprovalRequest, - typing.Awaitable[accessapproval.ApprovalRequest], + Union[ + accessapproval.ApprovalRequest, Awaitable[accessapproval.ApprovalRequest] ], ]: raise NotImplementedError() @@ -192,11 +257,10 @@ def get_approval_request( @property def approve_approval_request( self, - ) -> typing.Callable[ + ) -> Callable[ [accessapproval.ApproveApprovalRequestMessage], - typing.Union[ - accessapproval.ApprovalRequest, - typing.Awaitable[accessapproval.ApprovalRequest], + Union[ + accessapproval.ApprovalRequest, Awaitable[accessapproval.ApprovalRequest] ], ]: raise NotImplementedError() @@ -204,11 +268,10 @@ def approve_approval_request( @property def dismiss_approval_request( self, - ) -> typing.Callable[ + ) -> Callable[ [accessapproval.DismissApprovalRequestMessage], - typing.Union[ - accessapproval.ApprovalRequest, - typing.Awaitable[accessapproval.ApprovalRequest], + Union[ + accessapproval.ApprovalRequest, Awaitable[accessapproval.ApprovalRequest] ], ]: raise NotImplementedError() @@ -216,11 +279,11 @@ def dismiss_approval_request( @property def get_access_approval_settings( self, - ) -> typing.Callable[ + ) -> Callable[ [accessapproval.GetAccessApprovalSettingsMessage], - typing.Union[ + Union[ accessapproval.AccessApprovalSettings, - typing.Awaitable[accessapproval.AccessApprovalSettings], + Awaitable[accessapproval.AccessApprovalSettings], ], ]: raise NotImplementedError() @@ -228,11 +291,11 @@ def get_access_approval_settings( @property def update_access_approval_settings( self, - ) -> typing.Callable[ + ) -> Callable[ [accessapproval.UpdateAccessApprovalSettingsMessage], - typing.Union[ + Union[ accessapproval.AccessApprovalSettings, - typing.Awaitable[accessapproval.AccessApprovalSettings], + Awaitable[accessapproval.AccessApprovalSettings], ], ]: raise NotImplementedError() @@ -240,9 +303,9 @@ def update_access_approval_settings( @property def delete_access_approval_settings( self, - ) -> typing.Callable[ + ) -> Callable[ [accessapproval.DeleteAccessApprovalSettingsMessage], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], ]: raise NotImplementedError() diff --git a/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py b/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py index 3abe140..7c41ca8 100644 --- a/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py +++ b/google/cloud/accessapproval_v1/services/access_approval/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,21 +13,19 @@ # 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.accessapproval_v1.types import accessapproval -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import AccessApprovalTransport, DEFAULT_CLIENT_INFO @@ -85,7 +82,7 @@ def __init__( self, *, host: str = "accessapproval.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -99,7 +96,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 @@ -209,7 +207,7 @@ def __init__( def create_channel( cls, host: str = "accessapproval.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, @@ -240,13 +238,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, ) @@ -453,7 +453,9 @@ def update_access_approval_settings( @property def delete_access_approval_settings( self, - ) -> Callable[[accessapproval.DeleteAccessApprovalSettingsMessage], empty.Empty]: + ) -> Callable[ + [accessapproval.DeleteAccessApprovalSettingsMessage], empty_pb2.Empty + ]: r"""Return a callable for the delete access approval settings method over gRPC. @@ -482,7 +484,7 @@ def delete_access_approval_settings( ] = self.grpc_channel.unary_unary( "/google.cloud.accessapproval.v1.AccessApproval/DeleteAccessApprovalSettings", request_serializer=accessapproval.DeleteAccessApprovalSettingsMessage.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_access_approval_settings"] diff --git a/google/cloud/accessapproval_v1/services/access_approval/transports/grpc_asyncio.py b/google/cloud/accessapproval_v1/services/access_approval/transports/grpc_asyncio.py index 6a84315..2ad2048 100644 --- a/google/cloud/accessapproval_v1/services/access_approval/transports/grpc_asyncio.py +++ b/google/cloud/accessapproval_v1/services/access_approval/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,22 +13,20 @@ # 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.accessapproval_v1.types import accessapproval -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import AccessApprovalTransport, DEFAULT_CLIENT_INFO from .grpc import AccessApprovalGrpcTransport @@ -88,7 +85,7 @@ class AccessApprovalGrpcAsyncIOTransport(AccessApprovalTransport): def create_channel( cls, host: str = "accessapproval.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, @@ -115,13 +112,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, ) @@ -129,7 +128,7 @@ def __init__( self, *, host: str = "accessapproval.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, @@ -143,7 +142,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 @@ -201,7 +201,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 @@ -461,7 +460,7 @@ def update_access_approval_settings( def delete_access_approval_settings( self, ) -> Callable[ - [accessapproval.DeleteAccessApprovalSettingsMessage], Awaitable[empty.Empty] + [accessapproval.DeleteAccessApprovalSettingsMessage], Awaitable[empty_pb2.Empty] ]: r"""Return a callable for the delete access approval settings method over gRPC. @@ -491,7 +490,7 @@ def delete_access_approval_settings( ] = self.grpc_channel.unary_unary( "/google.cloud.accessapproval.v1.AccessApproval/DeleteAccessApprovalSettings", request_serializer=accessapproval.DeleteAccessApprovalSettingsMessage.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_access_approval_settings"] diff --git a/google/cloud/accessapproval_v1/types/__init__.py b/google/cloud/accessapproval_v1/types/__init__.py index f0fda5c..a1ff2e2 100644 --- a/google/cloud/accessapproval_v1/types/__init__.py +++ b/google/cloud/accessapproval_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 .accessapproval import ( AccessApprovalSettings, AccessLocations, diff --git a/google/cloud/accessapproval_v1/types/accessapproval.py b/google/cloud/accessapproval_v1/types/accessapproval.py index dddb7e6..1f5fe98 100644 --- a/google/cloud/accessapproval_v1/types/accessapproval.py +++ b/google/cloud/accessapproval_v1/types/accessapproval.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -56,7 +53,6 @@ class EnrollmentLevel(proto.Enum): class AccessLocations(proto.Message): r"""Home office and physical location of the principal. - Attributes: principal_office_country (str): The "home office" location of the principal. @@ -94,14 +90,12 @@ class AccessLocations(proto.Message): - ANY: Any location """ - principal_office_country = proto.Field(proto.STRING, number=1) - - principal_physical_location_country = proto.Field(proto.STRING, number=2) + principal_office_country = proto.Field(proto.STRING, number=1,) + principal_physical_location_country = proto.Field(proto.STRING, number=2,) class AccessReason(proto.Message): r""" - Attributes: type_ (google.cloud.accessapproval_v1.types.AccessReason.Type): Type of access justification. @@ -118,8 +112,7 @@ class Type(proto.Enum): GOOGLE_INITIATED_REVIEW = 3 type_ = proto.Field(proto.ENUM, number=1, enum=Type,) - - detail = proto.Field(proto.STRING, number=2) + detail = proto.Field(proto.STRING, number=2,) class ApproveDecision(proto.Message): @@ -133,38 +126,38 @@ class ApproveDecision(proto.Message): The time at which the approval expires. """ - approve_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) - - expire_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) + approve_time = proto.Field( + proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, + ) + expire_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) class DismissDecision(proto.Message): r"""A decision that has been made to dismiss an approval request. - Attributes: dismiss_time (google.protobuf.timestamp_pb2.Timestamp): The time at which the approval request was dismissed. """ - dismiss_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) + dismiss_time = proto.Field( + proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, + ) class ResourceProperties(proto.Message): r"""The properties associated with the resource of the request. - Attributes: excludes_descendants (bool): Whether an approval will exclude the descendants of the resource being requested. """ - excludes_descendants = proto.Field(proto.BOOL, number=1) + excludes_descendants = proto.Field(proto.BOOL, number=1,) class ApprovalRequest(proto.Message): r"""A request for the customer to approve access to a resource. - Attributes: name (str): The resource name of the request. Format is @@ -200,30 +193,24 @@ class ApprovalRequest(proto.Message): The request was dismissed. """ - name = proto.Field(proto.STRING, number=1) - - requested_resource_name = proto.Field(proto.STRING, number=2) - + name = proto.Field(proto.STRING, number=1,) + requested_resource_name = proto.Field(proto.STRING, number=2,) requested_resource_properties = proto.Field( proto.MESSAGE, number=9, message="ResourceProperties", ) - requested_reason = proto.Field(proto.MESSAGE, number=3, message="AccessReason",) - requested_locations = proto.Field( proto.MESSAGE, number=4, message="AccessLocations", ) - - request_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) - + request_time = proto.Field( + proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp, + ) requested_expiration = proto.Field( - proto.MESSAGE, number=6, message=timestamp.Timestamp, + proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp, ) - approve = proto.Field( proto.MESSAGE, number=7, oneof="decision", message="ApproveDecision", ) - dismiss = proto.Field( proto.MESSAGE, number=8, oneof="decision", message="DismissDecision", ) @@ -252,8 +239,7 @@ class EnrolledService(proto.Message): The enrollment level of the service. """ - cloud_product = proto.Field(proto.STRING, number=1) - + cloud_product = proto.Field(proto.STRING, number=1,) enrollment_level = proto.Field(proto.ENUM, number=2, enum="EnrollmentLevel",) @@ -300,20 +286,16 @@ class AccessApprovalSettings(proto.Message): ancestors). """ - name = proto.Field(proto.STRING, number=1) - - notification_emails = proto.RepeatedField(proto.STRING, number=2) - + name = proto.Field(proto.STRING, number=1,) + notification_emails = proto.RepeatedField(proto.STRING, number=2,) enrolled_services = proto.RepeatedField( proto.MESSAGE, number=3, message="EnrolledService", ) - - enrolled_ancestor = proto.Field(proto.BOOL, number=4) + enrolled_ancestor = proto.Field(proto.BOOL, number=4,) class ListApprovalRequestsMessage(proto.Message): r"""Request to list approval requests. - Attributes: parent (str): The parent resource. This may be "projects/{project_id}", @@ -335,18 +317,14 @@ class ListApprovalRequestsMessage(proto.Message): return. """ - parent = proto.Field(proto.STRING, number=1) - - filter = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) - - page_token = proto.Field(proto.STRING, number=4) + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) + page_token = proto.Field(proto.STRING, number=4,) class ListApprovalRequestsResponse(proto.Message): r"""Response to listing of ApprovalRequest objects. - Attributes: approval_requests (Sequence[google.cloud.accessapproval_v1.types.ApprovalRequest]): Approval request details. @@ -362,24 +340,21 @@ def raw_page(self): approval_requests = proto.RepeatedField( proto.MESSAGE, number=1, message="ApprovalRequest", ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class GetApprovalRequestMessage(proto.Message): r"""Request to get an approval request. - Attributes: name (str): Name of the approval request to retrieve. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ApproveApprovalRequestMessage(proto.Message): r"""Request to approve an ApprovalRequest. - Attributes: name (str): Name of the approval request to approve. @@ -387,37 +362,33 @@ class ApproveApprovalRequestMessage(proto.Message): The expiration time of this approval. """ - name = proto.Field(proto.STRING, number=1) - - expire_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) + name = proto.Field(proto.STRING, number=1,) + expire_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) class DismissApprovalRequestMessage(proto.Message): r"""Request to dismiss an approval request. - Attributes: name (str): Name of the ApprovalRequest to dismiss. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class GetAccessApprovalSettingsMessage(proto.Message): r"""Request to get access approval settings. - Attributes: name (str): Name of the AccessApprovalSettings to retrieve. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdateAccessApprovalSettingsMessage(proto.Message): r"""Request to update access approval settings. - Attributes: settings (google.cloud.accessapproval_v1.types.AccessApprovalSettings): The new AccessApprovalSettings. @@ -436,19 +407,19 @@ class UpdateAccessApprovalSettingsMessage(proto.Message): """ settings = proto.Field(proto.MESSAGE, number=1, message="AccessApprovalSettings",) - - update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) class DeleteAccessApprovalSettingsMessage(proto.Message): r"""Request to delete access approval settings. - Attributes: name (str): Name of the AccessApprovalSettings to delete. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/scripts/fixup_accessapproval_v1_keywords.py b/scripts/fixup_accessapproval_v1_keywords.py index 883d4a9..dc90ab1 100644 --- a/scripts/fixup_accessapproval_v1_keywords.py +++ b/scripts/fixup_accessapproval_v1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,14 +39,13 @@ def partition( class accessapprovalCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'approve_approval_request': ('name', 'expire_time', ), - 'delete_access_approval_settings': ('name', ), - 'dismiss_approval_request': ('name', ), - 'get_access_approval_settings': ('name', ), - 'get_approval_request': ('name', ), - 'list_approval_requests': ('parent', 'filter', 'page_size', 'page_token', ), - 'update_access_approval_settings': ('settings', 'update_mask', ), - + 'approve_approval_request': ('name', 'expire_time', ), + 'delete_access_approval_settings': ('name', ), + 'dismiss_approval_request': ('name', ), + 'get_access_approval_settings': ('name', ), + 'get_approval_request': ('name', ), + 'list_approval_requests': ('parent', 'filter', 'page_size', 'page_token', ), + 'update_access_approval_settings': ('settings', 'update_mask', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -79,7 +76,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/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/accessapproval_v1/__init__.py b/tests/unit/gapic/accessapproval_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/accessapproval_v1/__init__.py +++ b/tests/unit/gapic/accessapproval_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/accessapproval_v1/test_access_approval.py b/tests/unit/gapic/accessapproval_v1/test_access_approval.py index 501bd4e..0a32df6 100644 --- a/tests/unit/gapic/accessapproval_v1/test_access_approval.py +++ b/tests/unit/gapic/accessapproval_v1/test_access_approval.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.accessapproval_v1.services.access_approval import ( AccessApprovalAsyncClient, @@ -38,10 +37,40 @@ from google.cloud.accessapproval_v1.services.access_approval import AccessApprovalClient from google.cloud.accessapproval_v1.services.access_approval import pagers from google.cloud.accessapproval_v1.services.access_approval import transports +from google.cloud.accessapproval_v1.services.access_approval.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.accessapproval_v1.services.access_approval.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.accessapproval_v1.types import accessapproval from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -92,7 +121,7 @@ def test__get_default_mtls_endpoint(): "client_class", [AccessApprovalClient, AccessApprovalAsyncClient,] ) def test_access_approval_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: @@ -109,7 +138,7 @@ def test_access_approval_client_from_service_account_info(client_class): "client_class", [AccessApprovalClient, AccessApprovalAsyncClient,] ) def test_access_approval_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: @@ -162,7 +191,7 @@ def test_access_approval_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(AccessApprovalClient, "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() @@ -450,7 +479,7 @@ def test_list_approval_requests( transport: str = "grpc", request_type=accessapproval.ListApprovalRequestsMessage ): client = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -465,19 +494,15 @@ def test_list_approval_requests( call.return_value = accessapproval.ListApprovalRequestsResponse( next_page_token="next_page_token_value", ) - response = client.list_approval_requests(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.ListApprovalRequestsMessage() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListApprovalRequestsPager) - assert response.next_page_token == "next_page_token_value" @@ -489,7 +514,7 @@ def test_list_approval_requests_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 = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -499,7 +524,6 @@ def test_list_approval_requests_empty_call(): client.list_approval_requests() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.ListApprovalRequestsMessage() @@ -509,7 +533,7 @@ async def test_list_approval_requests_async( request_type=accessapproval.ListApprovalRequestsMessage, ): client = AccessApprovalAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -526,18 +550,15 @@ async def test_list_approval_requests_async( next_page_token="next_page_token_value", ) ) - response = await client.list_approval_requests(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.ListApprovalRequestsMessage() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListApprovalRequestsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -547,11 +568,12 @@ async def test_list_approval_requests_async_from_dict(): def test_list_approval_requests_field_headers(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(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 = accessapproval.ListApprovalRequestsMessage() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -559,7 +581,6 @@ def test_list_approval_requests_field_headers(): type(client.transport.list_approval_requests), "__call__" ) as call: call.return_value = accessapproval.ListApprovalRequestsResponse() - client.list_approval_requests(request) # Establish that the underlying gRPC stub method was called. @@ -574,11 +595,14 @@ def test_list_approval_requests_field_headers(): @pytest.mark.asyncio async def test_list_approval_requests_field_headers_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + 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 = accessapproval.ListApprovalRequestsMessage() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -588,7 +612,6 @@ async def test_list_approval_requests_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( accessapproval.ListApprovalRequestsResponse() ) - await client.list_approval_requests(request) # Establish that the underlying gRPC stub method was called. @@ -602,7 +625,7 @@ async def test_list_approval_requests_field_headers_async(): def test_list_approval_requests_flattened(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -610,7 +633,6 @@ def test_list_approval_requests_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = accessapproval.ListApprovalRequestsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_approval_requests(parent="parent_value",) @@ -619,12 +641,11 @@ def test_list_approval_requests_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_approval_requests_flattened_error(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -636,7 +657,9 @@ def test_list_approval_requests_flattened_error(): @pytest.mark.asyncio async def test_list_approval_requests_flattened_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -656,13 +679,14 @@ async def test_list_approval_requests_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_approval_requests_flattened_error_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -673,7 +697,7 @@ async def test_list_approval_requests_flattened_error_async(): def test_list_approval_requests_pager(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials,) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -719,7 +743,7 @@ def test_list_approval_requests_pager(): def test_list_approval_requests_pages(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials,) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -757,7 +781,7 @@ def test_list_approval_requests_pages(): @pytest.mark.asyncio async def test_list_approval_requests_async_pager(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AccessApprovalAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -802,7 +826,7 @@ async def test_list_approval_requests_async_pager(): @pytest.mark.asyncio async def test_list_approval_requests_async_pages(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials,) + client = AccessApprovalAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -846,7 +870,7 @@ def test_get_approval_request( transport: str = "grpc", request_type=accessapproval.GetApprovalRequestMessage ): client = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -862,24 +886,19 @@ def test_get_approval_request( name="name_value", requested_resource_name="requested_resource_name_value", approve=accessapproval.ApproveDecision( - approve_time=timestamp.Timestamp(seconds=751) + approve_time=timestamp_pb2.Timestamp(seconds=751) ), ) - response = client.get_approval_request(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.GetApprovalRequestMessage() # Establish that the response is the type that we expect. - assert isinstance(response, accessapproval.ApprovalRequest) - assert response.name == "name_value" - assert response.requested_resource_name == "requested_resource_name_value" @@ -891,7 +910,7 @@ def test_get_approval_request_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 = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -901,7 +920,6 @@ def test_get_approval_request_empty_call(): client.get_approval_request() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.GetApprovalRequestMessage() @@ -911,7 +929,7 @@ async def test_get_approval_request_async( request_type=accessapproval.GetApprovalRequestMessage, ): client = AccessApprovalAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -929,20 +947,16 @@ async def test_get_approval_request_async( requested_resource_name="requested_resource_name_value", ) ) - response = await client.get_approval_request(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.GetApprovalRequestMessage() # Establish that the response is the type that we expect. assert isinstance(response, accessapproval.ApprovalRequest) - assert response.name == "name_value" - assert response.requested_resource_name == "requested_resource_name_value" @@ -952,11 +966,12 @@ async def test_get_approval_request_async_from_dict(): def test_get_approval_request_field_headers(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(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 = accessapproval.GetApprovalRequestMessage() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -964,7 +979,6 @@ def test_get_approval_request_field_headers(): type(client.transport.get_approval_request), "__call__" ) as call: call.return_value = accessapproval.ApprovalRequest() - client.get_approval_request(request) # Establish that the underlying gRPC stub method was called. @@ -979,11 +993,14 @@ def test_get_approval_request_field_headers(): @pytest.mark.asyncio async def test_get_approval_request_field_headers_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + 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 = accessapproval.GetApprovalRequestMessage() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -993,7 +1010,6 @@ async def test_get_approval_request_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( accessapproval.ApprovalRequest() ) - await client.get_approval_request(request) # Establish that the underlying gRPC stub method was called. @@ -1007,7 +1023,7 @@ async def test_get_approval_request_field_headers_async(): def test_get_approval_request_flattened(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1015,7 +1031,6 @@ def test_get_approval_request_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = accessapproval.ApprovalRequest() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_approval_request(name="name_value",) @@ -1024,12 +1039,11 @@ def test_get_approval_request_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_approval_request_flattened_error(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1041,7 +1055,9 @@ def test_get_approval_request_flattened_error(): @pytest.mark.asyncio async def test_get_approval_request_flattened_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1061,13 +1077,14 @@ async def test_get_approval_request_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_approval_request_flattened_error_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1081,7 +1098,7 @@ def test_approve_approval_request( transport: str = "grpc", request_type=accessapproval.ApproveApprovalRequestMessage ): client = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1097,24 +1114,19 @@ def test_approve_approval_request( name="name_value", requested_resource_name="requested_resource_name_value", approve=accessapproval.ApproveDecision( - approve_time=timestamp.Timestamp(seconds=751) + approve_time=timestamp_pb2.Timestamp(seconds=751) ), ) - response = client.approve_approval_request(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.ApproveApprovalRequestMessage() # Establish that the response is the type that we expect. - assert isinstance(response, accessapproval.ApprovalRequest) - assert response.name == "name_value" - assert response.requested_resource_name == "requested_resource_name_value" @@ -1126,7 +1138,7 @@ def test_approve_approval_request_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 = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1136,7 +1148,6 @@ def test_approve_approval_request_empty_call(): client.approve_approval_request() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.ApproveApprovalRequestMessage() @@ -1146,7 +1157,7 @@ async def test_approve_approval_request_async( request_type=accessapproval.ApproveApprovalRequestMessage, ): client = AccessApprovalAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1164,20 +1175,16 @@ async def test_approve_approval_request_async( requested_resource_name="requested_resource_name_value", ) ) - response = await client.approve_approval_request(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.ApproveApprovalRequestMessage() # Establish that the response is the type that we expect. assert isinstance(response, accessapproval.ApprovalRequest) - assert response.name == "name_value" - assert response.requested_resource_name == "requested_resource_name_value" @@ -1187,11 +1194,12 @@ async def test_approve_approval_request_async_from_dict(): def test_approve_approval_request_field_headers(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(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 = accessapproval.ApproveApprovalRequestMessage() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1199,7 +1207,6 @@ def test_approve_approval_request_field_headers(): type(client.transport.approve_approval_request), "__call__" ) as call: call.return_value = accessapproval.ApprovalRequest() - client.approve_approval_request(request) # Establish that the underlying gRPC stub method was called. @@ -1214,11 +1221,14 @@ def test_approve_approval_request_field_headers(): @pytest.mark.asyncio async def test_approve_approval_request_field_headers_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + 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 = accessapproval.ApproveApprovalRequestMessage() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1228,7 +1238,6 @@ async def test_approve_approval_request_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( accessapproval.ApprovalRequest() ) - await client.approve_approval_request(request) # Establish that the underlying gRPC stub method was called. @@ -1245,7 +1254,7 @@ def test_dismiss_approval_request( transport: str = "grpc", request_type=accessapproval.DismissApprovalRequestMessage ): client = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1261,24 +1270,19 @@ def test_dismiss_approval_request( name="name_value", requested_resource_name="requested_resource_name_value", approve=accessapproval.ApproveDecision( - approve_time=timestamp.Timestamp(seconds=751) + approve_time=timestamp_pb2.Timestamp(seconds=751) ), ) - response = client.dismiss_approval_request(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.DismissApprovalRequestMessage() # Establish that the response is the type that we expect. - assert isinstance(response, accessapproval.ApprovalRequest) - assert response.name == "name_value" - assert response.requested_resource_name == "requested_resource_name_value" @@ -1290,7 +1294,7 @@ def test_dismiss_approval_request_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 = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1300,7 +1304,6 @@ def test_dismiss_approval_request_empty_call(): client.dismiss_approval_request() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.DismissApprovalRequestMessage() @@ -1310,7 +1313,7 @@ async def test_dismiss_approval_request_async( request_type=accessapproval.DismissApprovalRequestMessage, ): client = AccessApprovalAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1328,20 +1331,16 @@ async def test_dismiss_approval_request_async( requested_resource_name="requested_resource_name_value", ) ) - response = await client.dismiss_approval_request(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.DismissApprovalRequestMessage() # Establish that the response is the type that we expect. assert isinstance(response, accessapproval.ApprovalRequest) - assert response.name == "name_value" - assert response.requested_resource_name == "requested_resource_name_value" @@ -1351,11 +1350,12 @@ async def test_dismiss_approval_request_async_from_dict(): def test_dismiss_approval_request_field_headers(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(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 = accessapproval.DismissApprovalRequestMessage() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1363,7 +1363,6 @@ def test_dismiss_approval_request_field_headers(): type(client.transport.dismiss_approval_request), "__call__" ) as call: call.return_value = accessapproval.ApprovalRequest() - client.dismiss_approval_request(request) # Establish that the underlying gRPC stub method was called. @@ -1378,11 +1377,14 @@ def test_dismiss_approval_request_field_headers(): @pytest.mark.asyncio async def test_dismiss_approval_request_field_headers_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + 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 = accessapproval.DismissApprovalRequestMessage() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1392,7 +1394,6 @@ async def test_dismiss_approval_request_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( accessapproval.ApprovalRequest() ) - await client.dismiss_approval_request(request) # Establish that the underlying gRPC stub method was called. @@ -1410,7 +1411,7 @@ def test_get_access_approval_settings( request_type=accessapproval.GetAccessApprovalSettingsMessage, ): client = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1427,23 +1428,17 @@ def test_get_access_approval_settings( notification_emails=["notification_emails_value"], enrolled_ancestor=True, ) - response = client.get_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.GetAccessApprovalSettingsMessage() # Establish that the response is the type that we expect. - assert isinstance(response, accessapproval.AccessApprovalSettings) - assert response.name == "name_value" - assert response.notification_emails == ["notification_emails_value"] - assert response.enrolled_ancestor is True @@ -1455,7 +1450,7 @@ def test_get_access_approval_settings_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 = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1465,7 +1460,6 @@ def test_get_access_approval_settings_empty_call(): client.get_access_approval_settings() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.GetAccessApprovalSettingsMessage() @@ -1475,7 +1469,7 @@ async def test_get_access_approval_settings_async( request_type=accessapproval.GetAccessApprovalSettingsMessage, ): client = AccessApprovalAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1494,22 +1488,17 @@ async def test_get_access_approval_settings_async( enrolled_ancestor=True, ) ) - response = await client.get_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.GetAccessApprovalSettingsMessage() # Establish that the response is the type that we expect. assert isinstance(response, accessapproval.AccessApprovalSettings) - assert response.name == "name_value" - assert response.notification_emails == ["notification_emails_value"] - assert response.enrolled_ancestor is True @@ -1519,11 +1508,12 @@ async def test_get_access_approval_settings_async_from_dict(): def test_get_access_approval_settings_field_headers(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(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 = accessapproval.GetAccessApprovalSettingsMessage() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1531,7 +1521,6 @@ def test_get_access_approval_settings_field_headers(): type(client.transport.get_access_approval_settings), "__call__" ) as call: call.return_value = accessapproval.AccessApprovalSettings() - client.get_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. @@ -1546,11 +1535,14 @@ def test_get_access_approval_settings_field_headers(): @pytest.mark.asyncio async def test_get_access_approval_settings_field_headers_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + 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 = accessapproval.GetAccessApprovalSettingsMessage() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1560,7 +1552,6 @@ async def test_get_access_approval_settings_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( accessapproval.AccessApprovalSettings() ) - await client.get_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. @@ -1574,7 +1565,7 @@ async def test_get_access_approval_settings_field_headers_async(): def test_get_access_approval_settings_flattened(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1582,7 +1573,6 @@ def test_get_access_approval_settings_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = accessapproval.AccessApprovalSettings() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_access_approval_settings(name="name_value",) @@ -1591,12 +1581,11 @@ def test_get_access_approval_settings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_access_approval_settings_flattened_error(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1608,7 +1597,9 @@ def test_get_access_approval_settings_flattened_error(): @pytest.mark.asyncio async def test_get_access_approval_settings_flattened_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1628,13 +1619,14 @@ async def test_get_access_approval_settings_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_access_approval_settings_flattened_error_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1649,7 +1641,7 @@ def test_update_access_approval_settings( request_type=accessapproval.UpdateAccessApprovalSettingsMessage, ): client = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1666,23 +1658,17 @@ def test_update_access_approval_settings( notification_emails=["notification_emails_value"], enrolled_ancestor=True, ) - response = client.update_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.UpdateAccessApprovalSettingsMessage() # Establish that the response is the type that we expect. - assert isinstance(response, accessapproval.AccessApprovalSettings) - assert response.name == "name_value" - assert response.notification_emails == ["notification_emails_value"] - assert response.enrolled_ancestor is True @@ -1694,7 +1680,7 @@ def test_update_access_approval_settings_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 = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1704,7 +1690,6 @@ def test_update_access_approval_settings_empty_call(): client.update_access_approval_settings() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.UpdateAccessApprovalSettingsMessage() @@ -1714,7 +1699,7 @@ async def test_update_access_approval_settings_async( request_type=accessapproval.UpdateAccessApprovalSettingsMessage, ): client = AccessApprovalAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1733,22 +1718,17 @@ async def test_update_access_approval_settings_async( enrolled_ancestor=True, ) ) - response = await client.update_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.UpdateAccessApprovalSettingsMessage() # Establish that the response is the type that we expect. assert isinstance(response, accessapproval.AccessApprovalSettings) - assert response.name == "name_value" - assert response.notification_emails == ["notification_emails_value"] - assert response.enrolled_ancestor is True @@ -1758,11 +1738,12 @@ async def test_update_access_approval_settings_async_from_dict(): def test_update_access_approval_settings_field_headers(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(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 = accessapproval.UpdateAccessApprovalSettingsMessage() + request.settings.name = "settings.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1770,7 +1751,6 @@ def test_update_access_approval_settings_field_headers(): type(client.transport.update_access_approval_settings), "__call__" ) as call: call.return_value = accessapproval.AccessApprovalSettings() - client.update_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. @@ -1787,11 +1767,14 @@ def test_update_access_approval_settings_field_headers(): @pytest.mark.asyncio async def test_update_access_approval_settings_field_headers_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + 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 = accessapproval.UpdateAccessApprovalSettingsMessage() + request.settings.name = "settings.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1801,7 +1784,6 @@ async def test_update_access_approval_settings_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( accessapproval.AccessApprovalSettings() ) - await client.update_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. @@ -1817,7 +1799,7 @@ async def test_update_access_approval_settings_field_headers_async(): def test_update_access_approval_settings_flattened(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1825,28 +1807,25 @@ def test_update_access_approval_settings_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = accessapproval.AccessApprovalSettings() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_access_approval_settings( settings=accessapproval.AccessApprovalSettings(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].settings == accessapproval.AccessApprovalSettings( 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_access_approval_settings_flattened_error(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1854,13 +1833,15 @@ def test_update_access_approval_settings_flattened_error(): client.update_access_approval_settings( accessapproval.UpdateAccessApprovalSettingsMessage(), settings=accessapproval.AccessApprovalSettings(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_access_approval_settings_flattened_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1876,24 +1857,24 @@ async def test_update_access_approval_settings_flattened_async(): # using the keyword arguments to the method. response = await client.update_access_approval_settings( settings=accessapproval.AccessApprovalSettings(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].settings == accessapproval.AccessApprovalSettings( 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_access_approval_settings_flattened_error_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1901,7 +1882,7 @@ async def test_update_access_approval_settings_flattened_error_async(): await client.update_access_approval_settings( accessapproval.UpdateAccessApprovalSettingsMessage(), settings=accessapproval.AccessApprovalSettings(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1910,7 +1891,7 @@ def test_delete_access_approval_settings( request_type=accessapproval.DeleteAccessApprovalSettingsMessage, ): client = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1923,13 +1904,11 @@ def test_delete_access_approval_settings( ) as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.DeleteAccessApprovalSettingsMessage() # Establish that the response is the type that we expect. @@ -1944,7 +1923,7 @@ def test_delete_access_approval_settings_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 = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1954,7 +1933,6 @@ def test_delete_access_approval_settings_empty_call(): client.delete_access_approval_settings() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.DeleteAccessApprovalSettingsMessage() @@ -1964,7 +1942,7 @@ async def test_delete_access_approval_settings_async( request_type=accessapproval.DeleteAccessApprovalSettingsMessage, ): client = AccessApprovalAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1977,13 +1955,11 @@ async def test_delete_access_approval_settings_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == accessapproval.DeleteAccessApprovalSettingsMessage() # Establish that the response is the type that we expect. @@ -1996,11 +1972,12 @@ async def test_delete_access_approval_settings_async_from_dict(): def test_delete_access_approval_settings_field_headers(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(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 = accessapproval.DeleteAccessApprovalSettingsMessage() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2008,7 +1985,6 @@ def test_delete_access_approval_settings_field_headers(): type(client.transport.delete_access_approval_settings), "__call__" ) as call: call.return_value = None - client.delete_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. @@ -2023,11 +1999,14 @@ def test_delete_access_approval_settings_field_headers(): @pytest.mark.asyncio async def test_delete_access_approval_settings_field_headers_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + 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 = accessapproval.DeleteAccessApprovalSettingsMessage() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2035,7 +2014,6 @@ async def test_delete_access_approval_settings_field_headers_async(): type(client.transport.delete_access_approval_settings), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_access_approval_settings(request) # Establish that the underlying gRPC stub method was called. @@ -2049,7 +2027,7 @@ async def test_delete_access_approval_settings_field_headers_async(): def test_delete_access_approval_settings_flattened(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2057,7 +2035,6 @@ def test_delete_access_approval_settings_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_access_approval_settings(name="name_value",) @@ -2066,12 +2043,11 @@ def test_delete_access_approval_settings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_access_approval_settings_flattened_error(): - client = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2083,7 +2059,9 @@ def test_delete_access_approval_settings_flattened_error(): @pytest.mark.asyncio async def test_delete_access_approval_settings_flattened_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2101,13 +2079,14 @@ async def test_delete_access_approval_settings_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_access_approval_settings_flattened_error_async(): - client = AccessApprovalAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2120,16 +2099,16 @@ async def test_delete_access_approval_settings_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AccessApprovalGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AccessApprovalClient( - 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.AccessApprovalGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AccessApprovalClient( @@ -2139,7 +2118,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.AccessApprovalGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = AccessApprovalClient( @@ -2150,7 +2129,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AccessApprovalGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = AccessApprovalClient(transport=transport) assert client.transport is transport @@ -2159,13 +2138,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AccessApprovalGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.AccessApprovalGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2180,23 +2159,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 = AccessApprovalClient(credentials=credentials.AnonymousCredentials(),) + client = AccessApprovalClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.AccessApprovalGrpcTransport,) def test_access_approval_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.AccessApprovalTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2208,7 +2187,7 @@ def test_access_approval_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AccessApprovalTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2227,15 +2206,37 @@ def test_access_approval_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_access_approval_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.accessapproval_v1.services.access_approval.transports.AccessApprovalTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.AccessApprovalTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_access_approval_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.accessapproval_v1.services.access_approval.transports.AccessApprovalTransport._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.AccessApprovalTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -2248,19 +2249,33 @@ def test_access_approval_base_transport_with_credentials_file(): def test_access_approval_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.accessapproval_v1.services.access_approval.transports.AccessApprovalTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AccessApprovalTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_access_approval_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) + AccessApprovalClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_access_approval_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) AccessApprovalClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -2268,20 +2283,156 @@ def test_access_approval_auth_adc(): ) -def test_access_approval_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.AccessApprovalGrpcTransport, + transports.AccessApprovalGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_access_approval_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.AccessApprovalGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.AccessApprovalGrpcTransport, + transports.AccessApprovalGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_access_approval_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.AccessApprovalGrpcTransport, grpc_helpers), + (transports.AccessApprovalGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_access_approval_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( + "accessapproval.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="accessapproval.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.AccessApprovalGrpcTransport, grpc_helpers), + (transports.AccessApprovalGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_access_approval_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( + "accessapproval.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.AccessApprovalGrpcTransport, grpc_helpers), + (transports.AccessApprovalGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_access_approval_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( + "accessapproval.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", [ @@ -2290,7 +2441,7 @@ def test_access_approval_transport_auth_adc(): ], ) def test_access_approval_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: @@ -2329,7 +2480,7 @@ def test_access_approval_grpc_transport_client_cert_source_for_mtls(transport_cl def test_access_approval_host_no_port(): client = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="accessapproval.googleapis.com" ), @@ -2339,7 +2490,7 @@ def test_access_approval_host_no_port(): def test_access_approval_host_with_port(): client = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="accessapproval.googleapis.com:8000" ), @@ -2395,9 +2546,9 @@ def test_access_approval_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", @@ -2473,7 +2624,6 @@ def test_access_approval_transport_channel_mtls_with_adc(transport_class): def test_common_billing_account_path(): billing_account = "squid" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2494,7 +2644,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) actual = AccessApprovalClient.common_folder_path(folder) assert expected == actual @@ -2513,7 +2662,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) actual = AccessApprovalClient.common_organization_path(organization) assert expected == actual @@ -2532,7 +2680,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "cuttlefish" - expected = "projects/{project}".format(project=project,) actual = AccessApprovalClient.common_project_path(project) assert expected == actual @@ -2552,7 +2699,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "winkle" location = "nautilus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -2579,7 +2725,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.AccessApprovalTransport, "_prep_wrapped_messages" ) as prep: client = AccessApprovalClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2588,6 +2734,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = AccessApprovalClient.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)