Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions google/cloud/shell_v1/services/cloud_shell_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
),
Expand Down Expand Up @@ -218,5 +218,9 @@ def remove_public_key(
]:
raise NotImplementedError()

@property
def kind(self) -> str:
raise NotImplementedError()


__all__ = ("CloudShellServiceTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,9 @@ def remove_public_key(
def close(self):
self.grpc_channel.close()

@property
def kind(self) -> str:
return "grpc"


__all__ = ("CloudShellServiceGrpcTransport",)
79 changes: 62 additions & 17 deletions tests/unit/gapic/shell_v1/test_cloud_shell_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down