From 194ece7c95c8a1bc13fda363a888f791ba873945 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 9 Apr 2022 18:55:32 -0400 Subject: [PATCH] test: add transport in tests (#190) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: fix type in docstring for map fields PiperOrigin-RevId: 440589618 Source-Link: https://github.com/googleapis/googleapis/commit/cef116753b4dd5f4f600b6dd0d0de5d54eeb384b Source-Link: https://github.com/googleapis/googleapis-gen/commit/0e0e2c965210466832326c8e5736da461054bca4 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMGUwZTJjOTY1MjEwNDY2ODMyMzI2YzhlNTczNmRhNDYxMDU0YmNhNCJ9 * 🦉 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 --- .../services/access_approval/async_client.py | 8 +++---- .../services/access_approval/client.py | 16 +++++++------- .../access_approval/transports/base.py | 11 +++++++--- .../access_approval/transports/grpc.py | 4 ++++ .../accessapproval_v1/test_access_approval.py | 21 +++++++++++++++++++ 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/async_client.py b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/async_client.py index 8e50a1974022..988a3ef2b51b 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/async_client.py +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/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 @@ -334,7 +334,7 @@ def sample_list_approval_requests(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -447,7 +447,7 @@ def sample_get_approval_request(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -713,7 +713,7 @@ def sample_get_access_approval_settings(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/client.py b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/client.py index 50ff2fe56850..7c298b7f3006 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/client.py +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/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 @@ -493,7 +493,7 @@ def list_approval_requests( .. code-block:: python - from google.cloud import accessapproval_v1 + from google.cloud import accessapproval_v1 def sample_list_approval_requests(): # Create a client @@ -603,7 +603,7 @@ def get_approval_request( .. code-block:: python - from google.cloud import accessapproval_v1 + from google.cloud import accessapproval_v1 def sample_get_approval_request(): # Create a client @@ -700,7 +700,7 @@ def approve_approval_request( .. code-block:: python - from google.cloud import accessapproval_v1 + from google.cloud import accessapproval_v1 def sample_approve_approval_request(): # Create a client @@ -783,7 +783,7 @@ def dismiss_approval_request( .. code-block:: python - from google.cloud import accessapproval_v1 + from google.cloud import accessapproval_v1 def sample_dismiss_approval_request(): # Create a client @@ -859,7 +859,7 @@ def get_access_approval_settings( .. code-block:: python - from google.cloud import accessapproval_v1 + from google.cloud import accessapproval_v1 def sample_get_access_approval_settings(): # Create a client @@ -961,7 +961,7 @@ def update_access_approval_settings( .. code-block:: python - from google.cloud import accessapproval_v1 + from google.cloud import accessapproval_v1 def sample_update_access_approval_settings(): # Create a client @@ -1084,7 +1084,7 @@ def delete_access_approval_settings( .. code-block:: python - from google.cloud import accessapproval_v1 + from google.cloud import accessapproval_v1 def sample_delete_access_approval_settings(): # Create a client diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/base.py b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/base.py index 008d2a13badb..d15c37fbce2d 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/base.py +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/base.py @@ -81,6 +81,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" @@ -128,7 +129,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -142,7 +143,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -166,7 +167,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -272,5 +273,9 @@ def delete_access_approval_settings( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("AccessApprovalTransport",) diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py index 793effc6c786..7dec9ce3f8a4 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py @@ -497,5 +497,9 @@ def delete_access_approval_settings( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("AccessApprovalGrpcTransport",) diff --git a/packages/google-cloud-access-approval/tests/unit/gapic/accessapproval_v1/test_access_approval.py b/packages/google-cloud-access-approval/tests/unit/gapic/accessapproval_v1/test_access_approval.py index 9e02b4cd0684..ae3ab3e4ebec 100644 --- a/packages/google-cloud-access-approval/tests/unit/gapic/accessapproval_v1/test_access_approval.py +++ b/packages/google-cloud-access-approval/tests/unit/gapic/accessapproval_v1/test_access_approval.py @@ -2528,6 +2528,19 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = AccessApprovalClient.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 = AccessApprovalClient( @@ -2576,6 +2589,14 @@ def test_access_approval_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_access_approval_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file