From ed2de3adcd9ad1d77ad016e3ad11dfc4a42b45ff Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 12 Apr 2022 19:38:48 -0400 Subject: [PATCH] chore: Use gapic-generator-python 0.65.0 (#104) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Use gapic-generator-python 0.65.0 PiperOrigin-RevId: 440970084 Source-Link: https://github.com/googleapis/googleapis/commit/5e0a3d57254ab9857ccac77fc6ffade7b69a2dc7 Source-Link: https://github.com/googleapis/googleapis-gen/commit/b0c628a3fade768f225d76992791ea1ba2a881be Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjBjNjI4YTNmYWRlNzY4ZjIyNWQ3Njk5Mjc5MWVhMWJhMmE4ODFiZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../connection_service/async_client.py | 6 +- .../services/connection_service/client.py | 3 +- .../connection_service/transports/base.py | 8 +- .../connection_service/transports/grpc.py | 4 + .../services/tether/async_client.py | 2 +- .../services/tether/client.py | 13 ++- .../services/tether/transports/base.py | 5 ++ .../services/tether/transports/grpc.py | 4 + .../test_connection_service.py | 85 ++++++++++++++----- .../gapic/apigeeconnect_v1/test_tether.py | 75 ++++++++++++---- 10 files changed, 158 insertions(+), 47 deletions(-) diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py index 9826656f3e6a..b0ec5838de64 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -216,7 +216,6 @@ async def list_connections( r"""Lists connections that are currently active for the given Apigee Connect endpoint. - .. code-block:: python from google.cloud import apigeeconnect_v1 @@ -289,8 +288,7 @@ def sample_list_connections(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - core_exceptions.Unknown, + core_exceptions.GoogleAPICallError, ), deadline=60.0, ), diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/client.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/client.py index 83bb8229c86c..0733562bdc38 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/client.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/client.py @@ -16,7 +16,7 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core import client_options as client_options_lib @@ -435,7 +435,6 @@ def list_connections( r"""Lists connections that are currently active for the given Apigee Connect endpoint. - .. code-block:: python from google.cloud import apigeeconnect_v1 diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py index f3da373c1383..fdf167b1d095 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py @@ -80,6 +80,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -127,8 +128,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - core_exceptions.Unknown, + core_exceptions.GoogleAPICallError, ), deadline=60.0, ), @@ -158,5 +158,9 @@ def list_connections( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("ConnectionServiceTransport",) diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py index 896135c85d69..ff42e465b023 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py @@ -260,5 +260,9 @@ def list_connections( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("ConnectionServiceGrpcTransport",) diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/async_client.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/async_client.py index 8be2c7e30cf7..366c0c177c56 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/async_client.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/async_client.py @@ -18,6 +18,7 @@ import re from typing import ( Dict, + Mapping, Optional, AsyncIterable, Awaitable, @@ -222,7 +223,6 @@ def egress( The listener streams http requests and the dialer streams http responses. - .. code-block:: python from google.cloud import apigeeconnect_v1 diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/client.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/client.py index 3193ba426fde..b2030feb33bd 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/client.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/client.py @@ -16,7 +16,17 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Iterable, Iterator, Sequence, Tuple, Type, Union +from typing import ( + Dict, + Mapping, + Optional, + Iterable, + Iterator, + Sequence, + Tuple, + Type, + Union, +) import pkg_resources from google.api_core import client_options as client_options_lib @@ -424,7 +434,6 @@ def egress( The listener streams http requests and the dialer streams http responses. - .. code-block:: python from google.cloud import apigeeconnect_v1 diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/base.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/base.py index e179733447f5..f3f20c644b08 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/base.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/base.py @@ -80,6 +80,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -145,5 +146,9 @@ def egress( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("TetherTransport",) diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py index 49c4c8a28b9c..3b5a9667d9b3 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py @@ -265,5 +265,9 @@ def egress(self) -> Callable[[tether.EgressResponse], tether.EgressRequest]: def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("TetherGrpcTransport",) diff --git a/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py b/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py index 1a40f1159769..12d25a6257d6 100644 --- a/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py +++ b/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py @@ -90,24 +90,26 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - ConnectionServiceClient, - ConnectionServiceAsyncClient, + (ConnectionServiceClient, "grpc"), + (ConnectionServiceAsyncClient, "grpc_asyncio"), ], ) -def test_connection_service_client_from_service_account_info(client_class): +def test_connection_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "apigeeconnect.googleapis.com:443" + assert client.transport._host == ("apigeeconnect.googleapis.com:443") @pytest.mark.parametrize( @@ -136,27 +138,33 @@ def test_connection_service_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - ConnectionServiceClient, - ConnectionServiceAsyncClient, + (ConnectionServiceClient, "grpc"), + (ConnectionServiceAsyncClient, "grpc_asyncio"), ], ) -def test_connection_service_client_from_service_account_file(client_class): +def test_connection_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "apigeeconnect.googleapis.com:443" + assert client.transport._host == ("apigeeconnect.googleapis.com:443") def test_connection_service_client_get_transport_class(): @@ -1022,7 +1030,7 @@ async def test_list_connections_async_pager(): ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1068,7 +1076,9 @@ async def test_list_connections_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_connections(request={})).pages: + async for page_ in ( + await client.list_connections(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -1165,6 +1175,19 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = ConnectionServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ConnectionServiceClient( @@ -1205,6 +1228,14 @@ def test_connection_service_base_transport(): with pytest.raises(NotImplementedError): transport.close() + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_connection_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -1350,24 +1381,40 @@ def test_connection_service_grpc_transport_client_cert_source_for_mtls(transport ) -def test_connection_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_connection_service_host_no_port(transport_name): client = ConnectionServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="apigeeconnect.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "apigeeconnect.googleapis.com:443" + assert client.transport._host == ("apigeeconnect.googleapis.com:443") -def test_connection_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_connection_service_host_with_port(transport_name): client = ConnectionServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="apigeeconnect.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "apigeeconnect.googleapis.com:8000" + assert client.transport._host == ("apigeeconnect.googleapis.com:8000") def test_connection_service_grpc_transport_channel(): diff --git a/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_tether.py b/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_tether.py index cb87807a7123..61b91401b1b0 100644 --- a/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_tether.py +++ b/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_tether.py @@ -81,24 +81,24 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - TetherClient, - TetherAsyncClient, + (TetherClient, "grpc"), + (TetherAsyncClient, "grpc_asyncio"), ], ) -def test_tether_client_from_service_account_info(client_class): +def test_tether_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "apigeeconnect.googleapis.com:443" + assert client.transport._host == ("apigeeconnect.googleapis.com:443") @pytest.mark.parametrize( @@ -125,27 +125,31 @@ def test_tether_client_service_account_always_use_jwt(transport_class, transport @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - TetherClient, - TetherAsyncClient, + (TetherClient, "grpc"), + (TetherAsyncClient, "grpc_asyncio"), ], ) -def test_tether_client_from_service_account_file(client_class): +def test_tether_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "apigeeconnect.googleapis.com:443" + assert client.transport._host == ("apigeeconnect.googleapis.com:443") def test_tether_client_get_transport_class(): @@ -760,6 +764,19 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = TetherClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = TetherClient( @@ -800,6 +817,14 @@ def test_tether_base_transport(): with pytest.raises(NotImplementedError): transport.close() + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_tether_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -942,24 +967,40 @@ def test_tether_grpc_transport_client_cert_source_for_mtls(transport_class): ) -def test_tether_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_tether_host_no_port(transport_name): client = TetherClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="apigeeconnect.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "apigeeconnect.googleapis.com:443" + assert client.transport._host == ("apigeeconnect.googleapis.com:443") -def test_tether_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_tether_host_with_port(transport_name): client = TetherClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="apigeeconnect.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "apigeeconnect.googleapis.com:8000" + assert client.transport._host == ("apigeeconnect.googleapis.com:8000") def test_tether_grpc_transport_channel():