diff --git a/google/cloud/shell_v1/services/cloud_shell_service/async_client.py b/google/cloud/shell_v1/services/cloud_shell_service/async_client.py index d126e4b..61232e4 100644 --- a/google/cloud/shell_v1/services/cloud_shell_service/async_client.py +++ b/google/cloud/shell_v1/services/cloud_shell_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 @@ -225,7 +225,6 @@ async def get_environment( r"""Gets an environment. Returns NOT_FOUND if the environment does not exist. - .. code-block:: python from google.cloud import shell_v1 @@ -301,8 +300,7 @@ def sample_get_environment(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - core_exceptions.Unknown, + core_exceptions.GoogleAPICallError, ), deadline=60.0, ), @@ -344,7 +342,6 @@ async def start_environment( connections, the operation will contain a StartEnvironmentResponse in its response field. - .. code-block:: python from google.cloud import shell_v1 @@ -436,7 +433,6 @@ async def authorize_environment( line tools without requiring the user to manually authenticate. - .. code-block:: python from google.cloud import shell_v1 @@ -526,7 +522,6 @@ async def add_public_key( SSH. If a key with the same content already exists, this will error with ALREADY_EXISTS. - .. code-block:: python from google.cloud import shell_v1 @@ -618,7 +613,6 @@ async def remove_public_key( corresponding private key. If a key with the same content is not present, this will error with NOT_FOUND. - .. code-block:: python from google.cloud import shell_v1 diff --git a/google/cloud/shell_v1/services/cloud_shell_service/client.py b/google/cloud/shell_v1/services/cloud_shell_service/client.py index 85fb173..4cfa0af 100644 --- a/google/cloud/shell_v1/services/cloud_shell_service/client.py +++ b/google/cloud/shell_v1/services/cloud_shell_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 @@ -442,7 +442,6 @@ def get_environment( r"""Gets an environment. Returns NOT_FOUND if the environment does not exist. - .. code-block:: python from google.cloud import shell_v1 @@ -551,7 +550,6 @@ def start_environment( connections, the operation will contain a StartEnvironmentResponse in its response field. - .. code-block:: python from google.cloud import shell_v1 @@ -644,7 +642,6 @@ def authorize_environment( line tools without requiring the user to manually authenticate. - .. code-block:: python from google.cloud import shell_v1 @@ -735,7 +732,6 @@ def add_public_key( SSH. If a key with the same content already exists, this will error with ALREADY_EXISTS. - .. code-block:: python from google.cloud import shell_v1 @@ -828,7 +824,6 @@ def remove_public_key( corresponding private key. If a key with the same content is not present, this will error with NOT_FOUND. - .. code-block:: python from google.cloud import shell_v1 diff --git a/google/cloud/shell_v1/services/cloud_shell_service/transports/base.py b/google/cloud/shell_v1/services/cloud_shell_service/transports/base.py index b474bcf..ce70e62 100644 --- a/google/cloud/shell_v1/services/cloud_shell_service/transports/base.py +++ b/google/cloud/shell_v1/services/cloud_shell_service/transports/base.py @@ -82,6 +82,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" @@ -129,8 +130,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, ), @@ -218,5 +218,9 @@ def remove_public_key( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("CloudShellServiceTransport",) diff --git a/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc.py b/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc.py index 9ba1ea6..f8cc39f 100644 --- a/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc.py +++ b/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc.py @@ -402,5 +402,9 @@ def remove_public_key( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("CloudShellServiceGrpcTransport",) diff --git a/tests/unit/gapic/shell_v1/test_cloud_shell_service.py b/tests/unit/gapic/shell_v1/test_cloud_shell_service.py index 992f939..88f2cb6 100644 --- a/tests/unit/gapic/shell_v1/test_cloud_shell_service.py +++ b/tests/unit/gapic/shell_v1/test_cloud_shell_service.py @@ -93,24 +93,26 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - CloudShellServiceClient, - CloudShellServiceAsyncClient, + (CloudShellServiceClient, "grpc"), + (CloudShellServiceAsyncClient, "grpc_asyncio"), ], ) -def test_cloud_shell_service_client_from_service_account_info(client_class): +def test_cloud_shell_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 == "cloudshell.googleapis.com:443" + assert client.transport._host == ("cloudshell.googleapis.com:443") @pytest.mark.parametrize( @@ -139,27 +141,33 @@ def test_cloud_shell_service_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - CloudShellServiceClient, - CloudShellServiceAsyncClient, + (CloudShellServiceClient, "grpc"), + (CloudShellServiceAsyncClient, "grpc_asyncio"), ], ) -def test_cloud_shell_service_client_from_service_account_file(client_class): +def test_cloud_shell_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 == "cloudshell.googleapis.com:443" + assert client.transport._host == ("cloudshell.googleapis.com:443") def test_cloud_shell_service_client_get_transport_class(): @@ -1620,6 +1628,19 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = CloudShellServiceClient.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 = CloudShellServiceClient( @@ -1671,6 +1692,14 @@ def test_cloud_shell_service_base_transport(): with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_cloud_shell_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -1818,24 +1847,40 @@ def test_cloud_shell_service_grpc_transport_client_cert_source_for_mtls( ) -def test_cloud_shell_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_cloud_shell_service_host_no_port(transport_name): client = CloudShellServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="cloudshell.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "cloudshell.googleapis.com:443" + assert client.transport._host == ("cloudshell.googleapis.com:443") -def test_cloud_shell_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_cloud_shell_service_host_with_port(transport_name): client = CloudShellServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="cloudshell.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "cloudshell.googleapis.com:8000" + assert client.transport._host == ("cloudshell.googleapis.com:8000") def test_cloud_shell_service_grpc_transport_channel():