From 4cd9ea7bd45e5a3410e6b1bde0a0ab629f75530d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 00:22:13 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#62) - [ ] Regenerate this pull request now. docs: list oneofs in docstring fix(deps): require google-api-core >= 1.28.0 fix(deps): drop packaging dependency committer: busunkim96@ PiperOrigin-RevId: 406468269 Source-Link: https://github.com/googleapis/googleapis/commit/83d81b0c8fc22291a13398d6d77f02dc97a5b6f4 Source-Link: https://github.com/googleapis/googleapis-gen/commit/2ff001fbacb9e77e71d734de5f955c05fdae8526 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9 --- .../connection_service/async_client.py | 10 +- .../services/connection_service/client.py | 4 +- .../connection_service/transports/base.py | 35 +------ .../transports/grpc_asyncio.py | 1 - .../services/tether/async_client.py | 6 +- .../services/tether/client.py | 4 +- .../services/tether/transports/base.py | 35 +------ .../tether/transports/grpc_asyncio.py | 1 - google/cloud/apigeeconnect_v1/types/tether.py | 10 ++ setup.py | 3 +- testing/constraints-3.6.txt | 4 +- .../test_connection_service.py | 91 ++----------------- .../gapic/apigeeconnect_v1/test_tether.py | 88 ++---------------- 13 files changed, 48 insertions(+), 244 deletions(-) diff --git a/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py b/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py index 7509b06..0cb2a4a 100644 --- a/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py +++ b/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # 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 as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.apigeeconnect_v1.services.connection_service import pagers from google.cloud.apigeeconnect_v1.types import connection from .transports.base import ConnectionServiceTransport, DEFAULT_CLIENT_INFO @@ -165,10 +167,10 @@ def __init__( async def list_connections( self, - request: connection.ListConnectionsRequest = None, + request: Union[connection.ListConnectionsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListConnectionsAsyncPager: @@ -176,7 +178,7 @@ async def list_connections( given Apigee Connect endpoint. Args: - request (:class:`google.cloud.apigeeconnect_v1.types.ListConnectionsRequest`): + request (Union[google.cloud.apigeeconnect_v1.types.ListConnectionsRequest, dict]): The request object. The request for [ListConnections][Management.ListConnections]. parent (:class:`str`): diff --git a/google/cloud/apigeeconnect_v1/services/connection_service/client.py b/google/cloud/apigeeconnect_v1/services/connection_service/client.py index 73ec1c8..81ed745 100644 --- a/google/cloud/apigeeconnect_v1/services/connection_service/client.py +++ b/google/cloud/apigeeconnect_v1/services/connection_service/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.apigeeconnect_v1.services.connection_service import pagers from google.cloud.apigeeconnect_v1.types import connection from .transports.base import ConnectionServiceTransport, DEFAULT_CLIENT_INFO @@ -353,7 +355,7 @@ def list_connections( request: Union[connection.ListConnectionsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListConnectionsPager: diff --git a/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py b/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py index d97e737..113013f 100644 --- a/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py +++ b/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -37,15 +36,6 @@ 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 - class ConnectionServiceTransport(abc.ABC): """Abstract transport class for ConnectionService.""" @@ -95,7 +85,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -128,29 +118,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is 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 - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py b/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py index 4bb8b5f..5f691cf 100644 --- a/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py +++ b/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # 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 diff --git a/google/cloud/apigeeconnect_v1/services/tether/async_client.py b/google/cloud/apigeeconnect_v1/services/tether/async_client.py index 2d0edd2..3d089f1 100644 --- a/google/cloud/apigeeconnect_v1/services/tether/async_client.py +++ b/google/cloud/apigeeconnect_v1/services/tether/async_client.py @@ -28,13 +28,15 @@ ) import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # 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 as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.apigeeconnect_v1.types import tether from google.protobuf import duration_pb2 # type: ignore from .transports.base import TetherTransport, DEFAULT_CLIENT_INFO @@ -166,7 +168,7 @@ def egress( self, requests: AsyncIterator[tether.EgressResponse] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[tether.EgressRequest]]: diff --git a/google/cloud/apigeeconnect_v1/services/tether/client.py b/google/cloud/apigeeconnect_v1/services/tether/client.py index 5a98d9e..ac10e0b 100644 --- a/google/cloud/apigeeconnect_v1/services/tether/client.py +++ b/google/cloud/apigeeconnect_v1/services/tether/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.apigeeconnect_v1.types import tether from google.protobuf import duration_pb2 # type: ignore from .transports.base import TetherTransport, DEFAULT_CLIENT_INFO @@ -337,7 +339,7 @@ def egress( self, requests: Iterator[tether.EgressResponse] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[tether.EgressRequest]: diff --git a/google/cloud/apigeeconnect_v1/services/tether/transports/base.py b/google/cloud/apigeeconnect_v1/services/tether/transports/base.py index 65ff8e1..bd53a11 100644 --- a/google/cloud/apigeeconnect_v1/services/tether/transports/base.py +++ b/google/cloud/apigeeconnect_v1/services/tether/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -37,15 +36,6 @@ 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 - class TetherTransport(abc.ABC): """Abstract transport class for Tether.""" @@ -95,7 +85,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -128,29 +118,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is 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 - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py b/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py index d453f47..d12cbbd 100644 --- a/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py +++ b/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # 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 diff --git a/google/cloud/apigeeconnect_v1/types/tether.py b/google/cloud/apigeeconnect_v1/types/tether.py index 1c4d7bc..7e42e19 100644 --- a/google/cloud/apigeeconnect_v1/types/tether.py +++ b/google/cloud/apigeeconnect_v1/types/tether.py @@ -87,13 +87,23 @@ class EgressRequest(proto.Message): class Payload(proto.Message): r"""Payload for EgressRequest. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: http_request (google.cloud.apigeeconnect_v1.types.HttpRequest): The HttpRequest proto. + This field is a member of `oneof`_ ``kind``. stream_info (google.cloud.apigeeconnect_v1.types.StreamInfo): The information of stream. + This field is a member of `oneof`_ ``kind``. action (google.cloud.apigeeconnect_v1.types.Action): The action taken by agent. + This field is a member of `oneof`_ ``kind``. """ http_request = proto.Field( diff --git a/setup.py b/setup.py index 585dfe2..05d3300 100644 --- a/setup.py +++ b/setup.py @@ -29,9 +29,8 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", "proto-plus >= 1.15.0", - "packaging >= 14.3", ] package_root = os.path.abspath(os.path.dirname(__file__)) diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 3b213fb..aff6bee 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,7 +5,5 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 proto-plus==1.15.0 -packaging==14.3 -google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is transitively required through google-auth \ No newline at end of file diff --git a/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py b/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py index 55ba3fd..d30f93f 100644 --- a/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py +++ b/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,28 +39,11 @@ ) from google.cloud.apigeeconnect_v1.services.connection_service import pagers from google.cloud.apigeeconnect_v1.services.connection_service import transports -from google.cloud.apigeeconnect_v1.services.connection_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.apigeeconnect_v1.types import connection from google.oauth2 import service_account import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the 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", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -219,7 +201,7 @@ def test_connection_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -236,7 +218,7 @@ def test_connection_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -253,7 +235,7 @@ def test_connection_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -282,7 +264,7 @@ def test_connection_service_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -351,7 +333,7 @@ def test_connection_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -393,7 +375,7 @@ def test_connection_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -415,7 +397,7 @@ def test_connection_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -446,7 +428,7 @@ def test_connection_service_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -477,7 +459,7 @@ def test_connection_service_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -961,7 +943,6 @@ def test_connection_service_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_connection_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -982,26 +963,6 @@ def test_connection_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_connection_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apigeeconnect_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ConnectionServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_connection_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1013,7 +974,6 @@ def test_connection_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_connection_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1026,18 +986,6 @@ def test_connection_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_connection_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - ConnectionServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1045,7 +993,6 @@ def test_connection_service_auth_adc_old_google_auth(): transports.ConnectionServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_connection_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1059,26 +1006,6 @@ def test_connection_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ConnectionServiceGrpcTransport, - transports.ConnectionServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_connection_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/apigeeconnect_v1/test_tether.py b/tests/unit/gapic/apigeeconnect_v1/test_tether.py index 7cd2271..0d720ca 100644 --- a/tests/unit/gapic/apigeeconnect_v1/test_tether.py +++ b/tests/unit/gapic/apigeeconnect_v1/test_tether.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -35,9 +34,6 @@ from google.cloud.apigeeconnect_v1.services.tether import TetherAsyncClient from google.cloud.apigeeconnect_v1.services.tether import TetherClient from google.cloud.apigeeconnect_v1.services.tether import transports -from google.cloud.apigeeconnect_v1.services.tether.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.apigeeconnect_v1.types import tether from google.oauth2 import service_account from google.protobuf import any_pb2 # type: ignore @@ -46,20 +42,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the 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", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -194,7 +176,7 @@ def test_tether_client_client_options(client_class, transport_class, transport_n options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -211,7 +193,7 @@ def test_tether_client_client_options(client_class, transport_class, transport_n with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -228,7 +210,7 @@ def test_tether_client_client_options(client_class, transport_class, transport_n with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -257,7 +239,7 @@ def test_tether_client_client_options(client_class, transport_class, transport_n options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -312,7 +294,7 @@ def test_tether_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -354,7 +336,7 @@ def test_tether_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -376,7 +358,7 @@ def test_tether_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -403,7 +385,7 @@ def test_tether_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -430,7 +412,7 @@ def test_tether_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -628,7 +610,6 @@ def test_tether_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_tether_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -649,26 +630,6 @@ def test_tether_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_tether_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.apigeeconnect_v1.services.tether.transports.TetherTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.TetherTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_tether_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -680,7 +641,6 @@ def test_tether_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_tether_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -693,23 +653,10 @@ def test_tether_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_tether_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) - TetherClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.TetherGrpcTransport, transports.TetherGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_tether_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -723,23 +670,6 @@ def test_tether_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.TetherGrpcTransport, transports.TetherGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_tether_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", [