From ed84bb127eac218e845468d5d07a476af410ce71 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Wed, 23 Dec 2020 08:24:02 -0800 Subject: [PATCH] feat: add common resource helpers, expose client transport, remove client side recv limit (#41) This PR was generated using Autosynth. :rainbow: Synth log will be available here: https://source.cloud.google.com/results/invocations/0ea0e0e1-c693-4704-a662-fcd1812ef49e/targets - [ ] To automatically regenerate this PR, check this box. PiperOrigin-RevId: 347055288 Source-Link: https://github.com/googleapis/googleapis/commit/dd372aa22ded7a8ba6f0e03a80e06358a3fa0907 PiperOrigin-RevId: 339292950 Source-Link: https://github.com/googleapis/googleapis/commit/07d41a7e5cade45aba6f0d277c89722b48f2c956 PiperOrigin-RevId: 338646463 Source-Link: https://github.com/googleapis/googleapis/commit/20b11dfe4538cd5da7b4c3dd7d2bf5b9922ff3ed --- docs/oslogin_v1/common/types.rst | 1 + docs/oslogin_v1/types.rst | 1 + .../cloud/oslogin_v1/common/types/__init__.py | 3 +- .../services/os_login_service/async_client.py | 60 +++- .../services/os_login_service/client.py | 87 ++++- .../os_login_service/transports/__init__.py | 1 - .../os_login_service/transports/grpc.py | 28 +- .../transports/grpc_asyncio.py | 12 + google/cloud/oslogin_v1/types/__init__.py | 1 - google/cloud/oslogin_v1/types/oslogin.py | 2 +- scripts/fixup_oslogin_v1_keywords.py | 1 + synth.metadata | 4 +- .../gapic/oslogin_v1/test_os_login_service.py | 309 ++++++++++++++---- 13 files changed, 419 insertions(+), 91 deletions(-) diff --git a/docs/oslogin_v1/common/types.rst b/docs/oslogin_v1/common/types.rst index c9c3df7..009e245 100644 --- a/docs/oslogin_v1/common/types.rst +++ b/docs/oslogin_v1/common/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Oslogin Common API .. automodule:: google.cloud.oslogin_v1.common :members: + :show-inheritance: diff --git a/docs/oslogin_v1/types.rst b/docs/oslogin_v1/types.rst index 759411d..ad7f7fe 100644 --- a/docs/oslogin_v1/types.rst +++ b/docs/oslogin_v1/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Oslogin v1 API .. automodule:: google.cloud.oslogin_v1.types :members: + :show-inheritance: diff --git a/google/cloud/oslogin_v1/common/types/__init__.py b/google/cloud/oslogin_v1/common/types/__init__.py index 1f648d3..0fefd31 100644 --- a/google/cloud/oslogin_v1/common/types/__init__.py +++ b/google/cloud/oslogin_v1/common/types/__init__.py @@ -18,10 +18,11 @@ from .common import ( PosixAccount, SshPublicKey, + OperatingSystemType, ) - __all__ = ( "PosixAccount", "SshPublicKey", + "OperatingSystemType", ) diff --git a/google/cloud/oslogin_v1/services/os_login_service/async_client.py b/google/cloud/oslogin_v1/services/os_login_service/async_client.py index 8afce3a..27335c9 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/async_client.py +++ b/google/cloud/oslogin_v1/services/os_login_service/async_client.py @@ -49,14 +49,56 @@ class OsLoginServiceAsyncClient: DEFAULT_ENDPOINT = OsLoginServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = OsLoginServiceClient.DEFAULT_MTLS_ENDPOINT + posix_account_path = staticmethod(OsLoginServiceClient.posix_account_path) + parse_posix_account_path = staticmethod( + OsLoginServiceClient.parse_posix_account_path + ) ssh_public_key_path = staticmethod(OsLoginServiceClient.ssh_public_key_path) parse_ssh_public_key_path = staticmethod( OsLoginServiceClient.parse_ssh_public_key_path ) + common_billing_account_path = staticmethod( + OsLoginServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + OsLoginServiceClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(OsLoginServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + OsLoginServiceClient.parse_common_folder_path + ) + + common_organization_path = staticmethod( + OsLoginServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + OsLoginServiceClient.parse_common_organization_path + ) + + common_project_path = staticmethod(OsLoginServiceClient.common_project_path) + parse_common_project_path = staticmethod( + OsLoginServiceClient.parse_common_project_path + ) + + common_location_path = staticmethod(OsLoginServiceClient.common_location_path) + parse_common_location_path = staticmethod( + OsLoginServiceClient.parse_common_location_path + ) + from_service_account_file = OsLoginServiceClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> OsLoginServiceTransport: + """Return the transport used by the client instance. + + Returns: + OsLoginServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(OsLoginServiceClient).get_transport_class, type(OsLoginServiceClient) ) @@ -142,7 +184,8 @@ async def delete_posix_account( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -216,7 +259,8 @@ async def delete_ssh_public_key( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -296,7 +340,8 @@ async def get_login_profile( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -377,7 +422,8 @@ async def get_ssh_public_key( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -473,7 +519,8 @@ async def import_ssh_public_key( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, ssh_public_key, project_id]): + has_flattened_params = any([parent, ssh_public_key, project_id]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -573,7 +620,8 @@ async def update_ssh_public_key( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name, ssh_public_key, update_mask]): + has_flattened_params = any([name, ssh_public_key, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." diff --git a/google/cloud/oslogin_v1/services/os_login_service/client.py b/google/cloud/oslogin_v1/services/os_login_service/client.py index ab59bfa..88ca09c 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/client.py +++ b/google/cloud/oslogin_v1/services/os_login_service/client.py @@ -135,6 +135,26 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> OsLoginServiceTransport: + """Return the transport used by the client instance. + + Returns: + OsLoginServiceTransport: The transport used by the client instance. + """ + return self._transport + + @staticmethod + def posix_account_path(user: str, project: str,) -> str: + """Return a fully-qualified posix_account string.""" + return "users/{user}/projects/{project}".format(user=user, project=project,) + + @staticmethod + def parse_posix_account_path(path: str) -> Dict[str, str]: + """Parse a posix_account path into its component segments.""" + m = re.match(r"^users/(?P.+?)/projects/(?P.+?)$", path) + return m.groupdict() if m else {} + @staticmethod def ssh_public_key_path(user: str, fingerprint: str,) -> str: """Return a fully-qualified ssh_public_key string.""" @@ -148,6 +168,65 @@ def parse_ssh_public_key_path(path: str) -> Dict[str, str]: m = re.match(r"^users/(?P.+?)/sshPublicKeys/(?P.+?)$", path) return m.groupdict() if m else {} + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, @@ -183,10 +262,10 @@ def __init__( not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: diff --git a/google/cloud/oslogin_v1/services/os_login_service/transports/__init__.py b/google/cloud/oslogin_v1/services/os_login_service/transports/__init__.py index 67d67c9..bd59d48 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/transports/__init__.py +++ b/google/cloud/oslogin_v1/services/os_login_service/transports/__init__.py @@ -28,7 +28,6 @@ _transport_registry["grpc"] = OsLoginServiceGrpcTransport _transport_registry["grpc_asyncio"] = OsLoginServiceGrpcAsyncIOTransport - __all__ = ( "OsLoginServiceTransport", "OsLoginServiceGrpcTransport", diff --git a/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py b/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py index 587a6c4..361718a 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py +++ b/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py @@ -94,10 +94,10 @@ def __init__( for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -106,6 +106,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -113,6 +115,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -148,7 +151,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -165,6 +173,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] @@ -191,7 +203,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -226,12 +238,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property diff --git a/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py b/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py index 63206d9..c1ab775 100644 --- a/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py +++ b/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py @@ -151,6 +151,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -158,6 +160,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -193,7 +196,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -210,6 +218,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. diff --git a/google/cloud/oslogin_v1/types/__init__.py b/google/cloud/oslogin_v1/types/__init__.py index c36dc46..e76149c 100644 --- a/google/cloud/oslogin_v1/types/__init__.py +++ b/google/cloud/oslogin_v1/types/__init__.py @@ -26,7 +26,6 @@ UpdateSshPublicKeyRequest, ) - __all__ = ( "LoginProfile", "DeletePosixAccountRequest", diff --git a/google/cloud/oslogin_v1/types/oslogin.py b/google/cloud/oslogin_v1/types/oslogin.py index f0e5fa3..360ee71 100644 --- a/google/cloud/oslogin_v1/types/oslogin.py +++ b/google/cloud/oslogin_v1/types/oslogin.py @@ -158,7 +158,7 @@ class ImportSshPublicKeyResponse(proto.Message): The login profile information for the user. """ - login_profile = proto.Field(proto.MESSAGE, number=1, message=LoginProfile,) + login_profile = proto.Field(proto.MESSAGE, number=1, message="LoginProfile",) class UpdateSshPublicKeyRequest(proto.Message): diff --git a/scripts/fixup_oslogin_v1_keywords.py b/scripts/fixup_oslogin_v1_keywords.py index 01ff867..be08c0e 100644 --- a/scripts/fixup_oslogin_v1_keywords.py +++ b/scripts/fixup_oslogin_v1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/synth.metadata b/synth.metadata index f132110..e6058ba 100644 --- a/synth.metadata +++ b/synth.metadata @@ -11,8 +11,8 @@ "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "7e837ae45f7b66519a36fd258fe72f08e71725d4", - "internalRef": "334927472" + "sha": "dd372aa22ded7a8ba6f0e03a80e06358a3fa0907", + "internalRef": "347055288" } }, { diff --git a/tests/unit/gapic/oslogin_v1/test_os_login_service.py b/tests/unit/gapic/oslogin_v1/test_os_login_service.py index bb077d5..435b0f6 100644 --- a/tests/unit/gapic/oslogin_v1/test_os_login_service.py +++ b/tests/unit/gapic/oslogin_v1/test_os_login_service.py @@ -95,12 +95,12 @@ def test_os_login_service_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "oslogin.googleapis.com:443" + assert client.transport._host == "oslogin.googleapis.com:443" def test_os_login_service_client_get_transport_class(): @@ -451,7 +451,7 @@ def test_delete_posix_account( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_posix_account), "__call__" + type(client.transport.delete_posix_account), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -473,18 +473,20 @@ def test_delete_posix_account_from_dict(): @pytest.mark.asyncio -async def test_delete_posix_account_async(transport: str = "grpc_asyncio"): +async def test_delete_posix_account_async( + transport: str = "grpc_asyncio", request_type=oslogin.DeletePosixAccountRequest +): client = OsLoginServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = oslogin.DeletePosixAccountRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_posix_account), "__call__" + type(client.transport.delete_posix_account), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -495,12 +497,17 @@ async def test_delete_posix_account_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == oslogin.DeletePosixAccountRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_posix_account_async_from_dict(): + await test_delete_posix_account_async(request_type=dict) + + def test_delete_posix_account_field_headers(): client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -511,7 +518,7 @@ def test_delete_posix_account_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_posix_account), "__call__" + type(client.transport.delete_posix_account), "__call__" ) as call: call.return_value = None @@ -538,7 +545,7 @@ async def test_delete_posix_account_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_posix_account), "__call__" + type(client.transport.delete_posix_account), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -559,7 +566,7 @@ def test_delete_posix_account_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_posix_account), "__call__" + type(client.transport.delete_posix_account), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -593,7 +600,7 @@ async def test_delete_posix_account_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_posix_account), "__call__" + type(client.transport.delete_posix_account), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -636,7 +643,7 @@ def test_delete_ssh_public_key( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_ssh_public_key), "__call__" + type(client.transport.delete_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -658,18 +665,20 @@ def test_delete_ssh_public_key_from_dict(): @pytest.mark.asyncio -async def test_delete_ssh_public_key_async(transport: str = "grpc_asyncio"): +async def test_delete_ssh_public_key_async( + transport: str = "grpc_asyncio", request_type=oslogin.DeleteSshPublicKeyRequest +): client = OsLoginServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = oslogin.DeleteSshPublicKeyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_ssh_public_key), "__call__" + type(client.transport.delete_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -680,12 +689,17 @@ async def test_delete_ssh_public_key_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == oslogin.DeleteSshPublicKeyRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_ssh_public_key_async_from_dict(): + await test_delete_ssh_public_key_async(request_type=dict) + + def test_delete_ssh_public_key_field_headers(): client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -696,7 +710,7 @@ def test_delete_ssh_public_key_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_ssh_public_key), "__call__" + type(client.transport.delete_ssh_public_key), "__call__" ) as call: call.return_value = None @@ -723,7 +737,7 @@ async def test_delete_ssh_public_key_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_ssh_public_key), "__call__" + type(client.transport.delete_ssh_public_key), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -744,7 +758,7 @@ def test_delete_ssh_public_key_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_ssh_public_key), "__call__" + type(client.transport.delete_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -778,7 +792,7 @@ async def test_delete_ssh_public_key_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_ssh_public_key), "__call__" + type(client.transport.delete_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -821,7 +835,7 @@ def test_get_login_profile( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_login_profile), "__call__" + type(client.transport.get_login_profile), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = oslogin.LoginProfile(name="name_value",) @@ -835,6 +849,7 @@ def test_get_login_profile( assert args[0] == oslogin.GetLoginProfileRequest() # Establish that the response is the type that we expect. + assert isinstance(response, oslogin.LoginProfile) assert response.name == "name_value" @@ -845,18 +860,20 @@ def test_get_login_profile_from_dict(): @pytest.mark.asyncio -async def test_get_login_profile_async(transport: str = "grpc_asyncio"): +async def test_get_login_profile_async( + transport: str = "grpc_asyncio", request_type=oslogin.GetLoginProfileRequest +): client = OsLoginServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = oslogin.GetLoginProfileRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_login_profile), "__call__" + type(client.transport.get_login_profile), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -869,7 +886,7 @@ async def test_get_login_profile_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == oslogin.GetLoginProfileRequest() # Establish that the response is the type that we expect. assert isinstance(response, oslogin.LoginProfile) @@ -877,6 +894,11 @@ async def test_get_login_profile_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_get_login_profile_async_from_dict(): + await test_get_login_profile_async(request_type=dict) + + def test_get_login_profile_field_headers(): client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -887,7 +909,7 @@ def test_get_login_profile_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_login_profile), "__call__" + type(client.transport.get_login_profile), "__call__" ) as call: call.return_value = oslogin.LoginProfile() @@ -914,7 +936,7 @@ async def test_get_login_profile_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_login_profile), "__call__" + type(client.transport.get_login_profile), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( oslogin.LoginProfile() @@ -937,7 +959,7 @@ def test_get_login_profile_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_login_profile), "__call__" + type(client.transport.get_login_profile), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = oslogin.LoginProfile() @@ -971,7 +993,7 @@ async def test_get_login_profile_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_login_profile), "__call__" + type(client.transport.get_login_profile), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = oslogin.LoginProfile() @@ -1016,7 +1038,7 @@ def test_get_ssh_public_key( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_ssh_public_key), "__call__" + type(client.transport.get_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = common.SshPublicKey( @@ -1035,6 +1057,7 @@ def test_get_ssh_public_key( assert args[0] == oslogin.GetSshPublicKeyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, common.SshPublicKey) assert response.key == "key_value" @@ -1051,18 +1074,20 @@ def test_get_ssh_public_key_from_dict(): @pytest.mark.asyncio -async def test_get_ssh_public_key_async(transport: str = "grpc_asyncio"): +async def test_get_ssh_public_key_async( + transport: str = "grpc_asyncio", request_type=oslogin.GetSshPublicKeyRequest +): client = OsLoginServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = oslogin.GetSshPublicKeyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_ssh_public_key), "__call__" + type(client.transport.get_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1080,7 +1105,7 @@ async def test_get_ssh_public_key_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == oslogin.GetSshPublicKeyRequest() # Establish that the response is the type that we expect. assert isinstance(response, common.SshPublicKey) @@ -1094,6 +1119,11 @@ async def test_get_ssh_public_key_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_get_ssh_public_key_async_from_dict(): + await test_get_ssh_public_key_async(request_type=dict) + + def test_get_ssh_public_key_field_headers(): client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1104,7 +1134,7 @@ def test_get_ssh_public_key_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_ssh_public_key), "__call__" + type(client.transport.get_ssh_public_key), "__call__" ) as call: call.return_value = common.SshPublicKey() @@ -1131,7 +1161,7 @@ async def test_get_ssh_public_key_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_ssh_public_key), "__call__" + type(client.transport.get_ssh_public_key), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.SshPublicKey()) @@ -1152,7 +1182,7 @@ def test_get_ssh_public_key_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_ssh_public_key), "__call__" + type(client.transport.get_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = common.SshPublicKey() @@ -1186,7 +1216,7 @@ async def test_get_ssh_public_key_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_ssh_public_key), "__call__" + type(client.transport.get_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = common.SshPublicKey() @@ -1229,7 +1259,7 @@ def test_import_ssh_public_key( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.import_ssh_public_key), "__call__" + type(client.transport.import_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = oslogin.ImportSshPublicKeyResponse() @@ -1243,6 +1273,7 @@ def test_import_ssh_public_key( assert args[0] == oslogin.ImportSshPublicKeyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, oslogin.ImportSshPublicKeyResponse) @@ -1251,18 +1282,20 @@ def test_import_ssh_public_key_from_dict(): @pytest.mark.asyncio -async def test_import_ssh_public_key_async(transport: str = "grpc_asyncio"): +async def test_import_ssh_public_key_async( + transport: str = "grpc_asyncio", request_type=oslogin.ImportSshPublicKeyRequest +): client = OsLoginServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = oslogin.ImportSshPublicKeyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.import_ssh_public_key), "__call__" + type(client.transport.import_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1275,12 +1308,17 @@ async def test_import_ssh_public_key_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == oslogin.ImportSshPublicKeyRequest() # Establish that the response is the type that we expect. assert isinstance(response, oslogin.ImportSshPublicKeyResponse) +@pytest.mark.asyncio +async def test_import_ssh_public_key_async_from_dict(): + await test_import_ssh_public_key_async(request_type=dict) + + def test_import_ssh_public_key_field_headers(): client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1291,7 +1329,7 @@ def test_import_ssh_public_key_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.import_ssh_public_key), "__call__" + type(client.transport.import_ssh_public_key), "__call__" ) as call: call.return_value = oslogin.ImportSshPublicKeyResponse() @@ -1318,7 +1356,7 @@ async def test_import_ssh_public_key_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.import_ssh_public_key), "__call__" + type(client.transport.import_ssh_public_key), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( oslogin.ImportSshPublicKeyResponse() @@ -1341,7 +1379,7 @@ def test_import_ssh_public_key_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.import_ssh_public_key), "__call__" + type(client.transport.import_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = oslogin.ImportSshPublicKeyResponse() @@ -1386,7 +1424,7 @@ async def test_import_ssh_public_key_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.import_ssh_public_key), "__call__" + type(client.transport.import_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = oslogin.ImportSshPublicKeyResponse() @@ -1442,7 +1480,7 @@ def test_update_ssh_public_key( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_ssh_public_key), "__call__" + type(client.transport.update_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = common.SshPublicKey( @@ -1461,6 +1499,7 @@ def test_update_ssh_public_key( assert args[0] == oslogin.UpdateSshPublicKeyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, common.SshPublicKey) assert response.key == "key_value" @@ -1477,18 +1516,20 @@ def test_update_ssh_public_key_from_dict(): @pytest.mark.asyncio -async def test_update_ssh_public_key_async(transport: str = "grpc_asyncio"): +async def test_update_ssh_public_key_async( + transport: str = "grpc_asyncio", request_type=oslogin.UpdateSshPublicKeyRequest +): client = OsLoginServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = oslogin.UpdateSshPublicKeyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_ssh_public_key), "__call__" + type(client.transport.update_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1506,7 +1547,7 @@ async def test_update_ssh_public_key_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == oslogin.UpdateSshPublicKeyRequest() # Establish that the response is the type that we expect. assert isinstance(response, common.SshPublicKey) @@ -1520,6 +1561,11 @@ async def test_update_ssh_public_key_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_update_ssh_public_key_async_from_dict(): + await test_update_ssh_public_key_async(request_type=dict) + + def test_update_ssh_public_key_field_headers(): client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1530,7 +1576,7 @@ def test_update_ssh_public_key_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_ssh_public_key), "__call__" + type(client.transport.update_ssh_public_key), "__call__" ) as call: call.return_value = common.SshPublicKey() @@ -1557,7 +1603,7 @@ async def test_update_ssh_public_key_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_ssh_public_key), "__call__" + type(client.transport.update_ssh_public_key), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(common.SshPublicKey()) @@ -1578,7 +1624,7 @@ def test_update_ssh_public_key_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_ssh_public_key), "__call__" + type(client.transport.update_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = common.SshPublicKey() @@ -1623,7 +1669,7 @@ async def test_update_ssh_public_key_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_ssh_public_key), "__call__" + type(client.transport.update_ssh_public_key), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = common.SshPublicKey() @@ -1700,7 +1746,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = OsLoginServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -1736,7 +1782,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = OsLoginServiceClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.OsLoginServiceGrpcTransport,) + assert isinstance(client.transport, transports.OsLoginServiceGrpcTransport,) def test_os_login_service_base_transport_error(): @@ -1844,7 +1890,7 @@ def test_os_login_service_host_no_port(): api_endpoint="oslogin.googleapis.com" ), ) - assert client._transport._host == "oslogin.googleapis.com:443" + assert client.transport._host == "oslogin.googleapis.com:443" def test_os_login_service_host_with_port(): @@ -1854,7 +1900,7 @@ def test_os_login_service_host_with_port(): api_endpoint="oslogin.googleapis.com:8000" ), ) - assert client._transport._host == "oslogin.googleapis.com:8000" + assert client.transport._host == "oslogin.googleapis.com:8000" def test_os_login_service_grpc_transport_channel(): @@ -1866,6 +1912,7 @@ def test_os_login_service_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_os_login_service_grpc_asyncio_transport_channel(): @@ -1877,6 +1924,7 @@ def test_os_login_service_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -1925,8 +1973,13 @@ def test_os_login_service_transport_channel_mtls_with_client_cert_source( ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -1968,13 +2021,38 @@ def test_os_login_service_transport_channel_mtls_with_adc(transport_class): ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel -def test_ssh_public_key_path(): +def test_posix_account_path(): user = "squid" - fingerprint = "clam" + project = "clam" + + expected = "users/{user}/projects/{project}".format(user=user, project=project,) + actual = OsLoginServiceClient.posix_account_path(user, project) + assert expected == actual + + +def test_parse_posix_account_path(): + expected = { + "user": "whelk", + "project": "octopus", + } + path = OsLoginServiceClient.posix_account_path(**expected) + + # Check that the path construction is reversible. + actual = OsLoginServiceClient.parse_posix_account_path(path) + assert expected == actual + + +def test_ssh_public_key_path(): + user = "oyster" + fingerprint = "nudibranch" expected = "users/{user}/sshPublicKeys/{fingerprint}".format( user=user, fingerprint=fingerprint, @@ -1985,8 +2063,8 @@ def test_ssh_public_key_path(): def test_parse_ssh_public_key_path(): expected = { - "user": "whelk", - "fingerprint": "octopus", + "user": "cuttlefish", + "fingerprint": "mussel", } path = OsLoginServiceClient.ssh_public_key_path(**expected) @@ -1995,6 +2073,107 @@ def test_parse_ssh_public_key_path(): assert expected == actual +def test_common_billing_account_path(): + billing_account = "winkle" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = OsLoginServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = OsLoginServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = OsLoginServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "scallop" + + expected = "folders/{folder}".format(folder=folder,) + actual = OsLoginServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = OsLoginServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = OsLoginServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "squid" + + expected = "organizations/{organization}".format(organization=organization,) + actual = OsLoginServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = OsLoginServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = OsLoginServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "whelk" + + expected = "projects/{project}".format(project=project,) + actual = OsLoginServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = OsLoginServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = OsLoginServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "oyster" + location = "nudibranch" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + actual = OsLoginServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = OsLoginServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = OsLoginServiceClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo()