diff --git a/packages/google-cloud-iam/.github/.OwlBot.lock.yaml b/packages/google-cloud-iam/.github/.OwlBot.lock.yaml index 88076277a251..87dd00611576 100644 --- a/packages/google-cloud-iam/.github/.OwlBot.lock.yaml +++ b/packages/google-cloud-iam/.github/.OwlBot.lock.yaml @@ -13,4 +13,4 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:2d13c2172a5d6129c861edaa48b60ead15aeaf58aa75e02d870c4cbdfa63aaba + digest: sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe diff --git a/packages/google-cloud-iam/docs/conf.py b/packages/google-cloud-iam/docs/conf.py index cb4ffff64053..baa5e6498538 100644 --- a/packages/google-cloud-iam/docs/conf.py +++ b/packages/google-cloud-iam/docs/conf.py @@ -314,7 +314,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (root_doc, "google-cloud-iam", "google-cloud-iam Documentation", [author], 1,) + ( + root_doc, + "google-cloud-iam", + "google-cloud-iam Documentation", + [author], + 1, + ) ] # If true, show URL addresses after external links. @@ -355,7 +361,10 @@ intersphinx_mapping = { "python": ("https://python.readthedocs.org/en/latest/", None), "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), + "google.api_core": ( + "https://googleapis.dev/python/google-api-core/latest/", + None, + ), "grpc": ("https://grpc.github.io/grpc/python/", None), "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py index afb9ded268e6..bc1f7f314179 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py @@ -363,7 +363,12 @@ def sample_generate_access_token(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -510,7 +515,12 @@ def sample_generate_id_token(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -643,7 +653,12 @@ def sample_sign_blob(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -779,7 +794,12 @@ def sample_sign_jwt(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -793,7 +813,9 @@ async def __aexit__(self, exc_type, exc, tb): try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution("google-cloud-iam",).version, + gapic_version=pkg_resources.get_distribution( + "google-cloud-iam", + ).version, ) except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py index 110fadae40fd..ab6da6ddd650 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py @@ -56,7 +56,10 @@ class IAMCredentialsClientMeta(type): _transport_registry["grpc"] = IAMCredentialsGrpcTransport _transport_registry["grpc_asyncio"] = IAMCredentialsGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[IAMCredentialsTransport]: + def get_transport_class( + cls, + label: str = None, + ) -> Type[IAMCredentialsTransport]: """Returns an appropriate transport class. Args: @@ -171,10 +174,14 @@ def transport(self) -> IAMCredentialsTransport: return self._transport @staticmethod - def service_account_path(project: str, service_account: str,) -> str: + def service_account_path( + project: str, + service_account: str, + ) -> str: """Returns a fully-qualified service_account string.""" return "projects/{project}/serviceAccounts/{service_account}".format( - project=project, service_account=service_account, + project=project, + service_account=service_account, ) @staticmethod @@ -187,7 +194,9 @@ def parse_service_account_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: + def common_billing_account_path( + billing_account: str, + ) -> str: """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, @@ -200,9 +209,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_folder_path(folder: str,) -> str: + def common_folder_path( + folder: str, + ) -> str: """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder,) + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -211,9 +224,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_organization_path(organization: str,) -> str: + def common_organization_path( + organization: str, + ) -> str: """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization,) + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -222,9 +239,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_project_path(project: str,) -> str: + def common_project_path( + project: str, + ) -> str: """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project,) + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -233,10 +254,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: + def common_location_path( + project: str, + location: str, + ) -> str: """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -548,7 +573,12 @@ def sample_generate_access_token(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -685,7 +715,12 @@ def sample_generate_id_token(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -808,7 +843,12 @@ def sample_sign_blob(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -934,7 +974,12 @@ def sample_sign_jwt(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -955,7 +1000,9 @@ def __exit__(self, type, value, traceback): try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution("google-cloud-iam",).version, + gapic_version=pkg_resources.get_distribution( + "google-cloud-iam", + ).version, ) except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py index ea013e4b4373..5435a7dc4347 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py @@ -29,7 +29,9 @@ try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution("google-cloud-iam",).version, + gapic_version=pkg_resources.get_distribution( + "google-cloud-iam", + ).version, ) except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() @@ -183,9 +185,9 @@ def _prep_wrapped_messages(self, client_info): def close(self): """Closes resources associated with the transport. - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! """ raise NotImplementedError() diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py index b90ba656f5a0..fe4f26ba0cd9 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py @@ -233,8 +233,7 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/types/common.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/types/common.py index 7b7cb5651f00..bef1556b8419 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/types/common.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/types/common.py @@ -72,10 +72,23 @@ class GenerateAccessTokenRequest(proto.Message): to a default value of one hour. """ - name = proto.Field(proto.STRING, number=1,) - delegates = proto.RepeatedField(proto.STRING, number=2,) - scope = proto.RepeatedField(proto.STRING, number=4,) - lifetime = proto.Field(proto.MESSAGE, number=7, message=duration_pb2.Duration,) + name = proto.Field( + proto.STRING, + number=1, + ) + delegates = proto.RepeatedField( + proto.STRING, + number=2, + ) + scope = proto.RepeatedField( + proto.STRING, + number=4, + ) + lifetime = proto.Field( + proto.MESSAGE, + number=7, + message=duration_pb2.Duration, + ) class GenerateAccessTokenResponse(proto.Message): @@ -89,8 +102,15 @@ class GenerateAccessTokenResponse(proto.Message): The expiration time is always set. """ - access_token = proto.Field(proto.STRING, number=1,) - expire_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + access_token = proto.Field( + proto.STRING, + number=1, + ) + expire_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) class SignBlobRequest(proto.Message): @@ -121,9 +141,18 @@ class SignBlobRequest(proto.Message): Required. The bytes to sign. """ - name = proto.Field(proto.STRING, number=1,) - delegates = proto.RepeatedField(proto.STRING, number=3,) - payload = proto.Field(proto.BYTES, number=5,) + name = proto.Field( + proto.STRING, + number=1, + ) + delegates = proto.RepeatedField( + proto.STRING, + number=3, + ) + payload = proto.Field( + proto.BYTES, + number=5, + ) class SignBlobResponse(proto.Message): @@ -136,8 +165,14 @@ class SignBlobResponse(proto.Message): The signed blob. """ - key_id = proto.Field(proto.STRING, number=1,) - signed_blob = proto.Field(proto.BYTES, number=4,) + key_id = proto.Field( + proto.STRING, + number=1, + ) + signed_blob = proto.Field( + proto.BYTES, + number=4, + ) class SignJwtRequest(proto.Message): @@ -169,9 +204,18 @@ class SignJwtRequest(proto.Message): object that contains a JWT Claims Set. """ - name = proto.Field(proto.STRING, number=1,) - delegates = proto.RepeatedField(proto.STRING, number=3,) - payload = proto.Field(proto.STRING, number=5,) + name = proto.Field( + proto.STRING, + number=1, + ) + delegates = proto.RepeatedField( + proto.STRING, + number=3, + ) + payload = proto.Field( + proto.STRING, + number=5, + ) class SignJwtResponse(proto.Message): @@ -184,8 +228,14 @@ class SignJwtResponse(proto.Message): The signed JWT. """ - key_id = proto.Field(proto.STRING, number=1,) - signed_jwt = proto.Field(proto.STRING, number=2,) + key_id = proto.Field( + proto.STRING, + number=1, + ) + signed_jwt = proto.Field( + proto.STRING, + number=2, + ) class GenerateIdTokenRequest(proto.Message): @@ -222,10 +272,22 @@ class GenerateIdTokenRequest(proto.Message): ``email_verified`` claims. """ - name = proto.Field(proto.STRING, number=1,) - delegates = proto.RepeatedField(proto.STRING, number=2,) - audience = proto.Field(proto.STRING, number=3,) - include_email = proto.Field(proto.BOOL, number=4,) + name = proto.Field( + proto.STRING, + number=1, + ) + delegates = proto.RepeatedField( + proto.STRING, + number=2, + ) + audience = proto.Field( + proto.STRING, + number=3, + ) + include_email = proto.Field( + proto.BOOL, + number=4, + ) class GenerateIdTokenResponse(proto.Message): @@ -236,7 +298,10 @@ class GenerateIdTokenResponse(proto.Message): The OpenId Connect ID token. """ - token = proto.Field(proto.STRING, number=1,) + token = proto.Field( + proto.STRING, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/types/iamcredentials.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/types/iamcredentials.py index 581b6a0d08bb..8277d3bc472c 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/types/iamcredentials.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/types/iamcredentials.py @@ -15,7 +15,10 @@ # -__protobuf__ = proto.module(package="google.iam.credentials.v1", manifest={},) +__protobuf__ = proto.module( + package="google.iam.credentials.v1", + manifest={}, +) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-iam/noxfile.py b/packages/google-cloud-iam/noxfile.py index 2a2001c49998..3addb4ed9431 100644 --- a/packages/google-cloud-iam/noxfile.py +++ b/packages/google-cloud-iam/noxfile.py @@ -24,7 +24,7 @@ import nox -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "3.8" @@ -57,7 +57,9 @@ def lint(session): """ session.install("flake8", BLACK_VERSION) session.run( - "black", "--check", *BLACK_PATHS, + "black", + "--check", + *BLACK_PATHS, ) session.run("flake8", "google", "tests") @@ -67,7 +69,8 @@ def blacken(session): """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) session.run( - "black", *BLACK_PATHS, + "black", + *BLACK_PATHS, ) diff --git a/packages/google-cloud-iam/tests/unit/gapic/credentials_v1/test_iam_credentials.py b/packages/google-cloud-iam/tests/unit/gapic/credentials_v1/test_iam_credentials.py index b745f65cd3e0..1fa3365701aa 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/credentials_v1/test_iam_credentials.py +++ b/packages/google-cloud-iam/tests/unit/gapic/credentials_v1/test_iam_credentials.py @@ -90,7 +90,11 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [IAMCredentialsClient, IAMCredentialsAsyncClient,] + "client_class", + [ + IAMCredentialsClient, + IAMCredentialsAsyncClient, + ], ) def test_iam_credentials_client_from_service_account_info(client_class): creds = ga_credentials.AnonymousCredentials() @@ -132,7 +136,11 @@ def test_iam_credentials_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", [IAMCredentialsClient, IAMCredentialsAsyncClient,] + "client_class", + [ + IAMCredentialsClient, + IAMCredentialsAsyncClient, + ], ) def test_iam_credentials_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -415,7 +423,9 @@ def test_iam_credentials_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(transport=transport_name, client_options=options) @@ -486,7 +496,8 @@ def test_generate_access_token( transport: str = "grpc", request_type=common.GenerateAccessTokenRequest ): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -521,7 +532,8 @@ def test_generate_access_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -539,7 +551,8 @@ async def test_generate_access_token_async( transport: str = "grpc_asyncio", request_type=common.GenerateAccessTokenRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -552,7 +565,9 @@ async def test_generate_access_token_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - common.GenerateAccessTokenResponse(access_token="access_token_value",) + common.GenerateAccessTokenResponse( + access_token="access_token_value", + ) ) response = await client.generate_access_token(request) @@ -572,7 +587,9 @@ async def test_generate_access_token_async_from_dict(): def test_generate_access_token_field_headers(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -594,7 +611,10 @@ def test_generate_access_token_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -625,11 +645,16 @@ async def test_generate_access_token_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_generate_access_token_flattened(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -659,7 +684,9 @@ def test_generate_access_token_flattened(): def test_generate_access_token_flattened_error(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -732,7 +759,8 @@ def test_generate_id_token( transport: str = "grpc", request_type=common.GenerateIdTokenRequest ): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -744,7 +772,9 @@ def test_generate_id_token( type(client.transport.generate_id_token), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = common.GenerateIdTokenResponse(token="token_value",) + call.return_value = common.GenerateIdTokenResponse( + token="token_value", + ) response = client.generate_id_token(request) # Establish that the underlying gRPC stub method was called. @@ -765,7 +795,8 @@ def test_generate_id_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -783,7 +814,8 @@ async def test_generate_id_token_async( transport: str = "grpc_asyncio", request_type=common.GenerateIdTokenRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -796,7 +828,9 @@ async def test_generate_id_token_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - common.GenerateIdTokenResponse(token="token_value",) + common.GenerateIdTokenResponse( + token="token_value", + ) ) response = await client.generate_id_token(request) @@ -816,7 +850,9 @@ async def test_generate_id_token_async_from_dict(): def test_generate_id_token_field_headers(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -838,7 +874,10 @@ def test_generate_id_token_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -869,11 +908,16 @@ async def test_generate_id_token_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_generate_id_token_flattened(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -901,7 +945,9 @@ def test_generate_id_token_flattened(): def test_generate_id_token_flattened_error(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -970,7 +1016,8 @@ async def test_generate_id_token_flattened_error_async(): def test_sign_blob(transport: str = "grpc", request_type=common.SignBlobRequest): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -981,7 +1028,8 @@ def test_sign_blob(transport: str = "grpc", request_type=common.SignBlobRequest) with mock.patch.object(type(client.transport.sign_blob), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = common.SignBlobResponse( - key_id="key_id_value", signed_blob=b"signed_blob_blob", + key_id="key_id_value", + signed_blob=b"signed_blob_blob", ) response = client.sign_blob(request) @@ -1004,7 +1052,8 @@ def test_sign_blob_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1020,7 +1069,8 @@ async def test_sign_blob_async( transport: str = "grpc_asyncio", request_type=common.SignBlobRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1032,7 +1082,8 @@ async def test_sign_blob_async( # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( common.SignBlobResponse( - key_id="key_id_value", signed_blob=b"signed_blob_blob", + key_id="key_id_value", + signed_blob=b"signed_blob_blob", ) ) response = await client.sign_blob(request) @@ -1054,7 +1105,9 @@ async def test_sign_blob_async_from_dict(): def test_sign_blob_field_headers(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -1074,7 +1127,10 @@ def test_sign_blob_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1103,11 +1159,16 @@ async def test_sign_blob_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_sign_blob_flattened(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.sign_blob), "__call__") as call: @@ -1116,7 +1177,9 @@ def test_sign_blob_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.sign_blob( - name="name_value", delegates=["delegates_value"], payload=b"payload_blob", + name="name_value", + delegates=["delegates_value"], + payload=b"payload_blob", ) # Establish that the underlying call was made with the expected @@ -1129,7 +1192,9 @@ def test_sign_blob_flattened(): def test_sign_blob_flattened_error(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1159,7 +1224,9 @@ async def test_sign_blob_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.sign_blob( - name="name_value", delegates=["delegates_value"], payload=b"payload_blob", + name="name_value", + delegates=["delegates_value"], + payload=b"payload_blob", ) # Establish that the underlying call was made with the expected @@ -1190,7 +1257,8 @@ async def test_sign_blob_flattened_error_async(): def test_sign_jwt(transport: str = "grpc", request_type=common.SignJwtRequest): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1201,7 +1269,8 @@ def test_sign_jwt(transport: str = "grpc", request_type=common.SignJwtRequest): with mock.patch.object(type(client.transport.sign_jwt), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = common.SignJwtResponse( - key_id="key_id_value", signed_jwt="signed_jwt_value", + key_id="key_id_value", + signed_jwt="signed_jwt_value", ) response = client.sign_jwt(request) @@ -1224,7 +1293,8 @@ def test_sign_jwt_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1240,7 +1310,8 @@ async def test_sign_jwt_async( transport: str = "grpc_asyncio", request_type=common.SignJwtRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1252,7 +1323,8 @@ async def test_sign_jwt_async( # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( common.SignJwtResponse( - key_id="key_id_value", signed_jwt="signed_jwt_value", + key_id="key_id_value", + signed_jwt="signed_jwt_value", ) ) response = await client.sign_jwt(request) @@ -1274,7 +1346,9 @@ async def test_sign_jwt_async_from_dict(): def test_sign_jwt_field_headers(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -1294,7 +1368,10 @@ def test_sign_jwt_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1323,11 +1400,16 @@ async def test_sign_jwt_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_sign_jwt_flattened(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.sign_jwt), "__call__") as call: @@ -1336,7 +1418,9 @@ def test_sign_jwt_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.sign_jwt( - name="name_value", delegates=["delegates_value"], payload="payload_value", + name="name_value", + delegates=["delegates_value"], + payload="payload_value", ) # Establish that the underlying call was made with the expected @@ -1349,7 +1433,9 @@ def test_sign_jwt_flattened(): def test_sign_jwt_flattened_error(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1379,7 +1465,9 @@ async def test_sign_jwt_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.sign_jwt( - name="name_value", delegates=["delegates_value"], payload="payload_value", + name="name_value", + delegates=["delegates_value"], + payload="payload_value", ) # Establish that the underlying call was made with the expected @@ -1415,7 +1503,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1434,7 +1523,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = IAMCredentialsClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1479,8 +1569,13 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.IAMCredentialsGrpcTransport,) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.IAMCredentialsGrpcTransport, + ) def test_iam_credentials_base_transport_error(): @@ -1528,7 +1623,8 @@ def test_iam_credentials_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IAMCredentialsTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1686,7 +1782,8 @@ def test_iam_credentials_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.IAMCredentialsGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1698,7 +1795,8 @@ def test_iam_credentials_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.IAMCredentialsGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1809,7 +1907,8 @@ def test_service_account_path(): project = "squid" service_account = "clam" expected = "projects/{project}/serviceAccounts/{service_account}".format( - project=project, service_account=service_account, + project=project, + service_account=service_account, ) actual = IAMCredentialsClient.service_account_path(project, service_account) assert expected == actual @@ -1849,7 +1948,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "cuttlefish" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = IAMCredentialsClient.common_folder_path(folder) assert expected == actual @@ -1867,7 +1968,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "winkle" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = IAMCredentialsClient.common_organization_path(organization) assert expected == actual @@ -1885,7 +1988,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "scallop" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = IAMCredentialsClient.common_project_path(project) assert expected == actual @@ -1905,7 +2010,8 @@ def test_common_location_path(): project = "squid" location = "clam" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = IAMCredentialsClient.common_location_path(project, location) assert expected == actual @@ -1930,7 +2036,8 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.IAMCredentialsTransport, "_prep_wrapped_messages" ) as prep: client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1939,7 +2046,8 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = IAMCredentialsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1947,7 +2055,8 @@ def test_client_withDEFAULT_CLIENT_INFO(): @pytest.mark.asyncio async def test_transport_close_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) with mock.patch.object( type(getattr(client.transport, "grpc_channel")), "close" diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py b/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py index 5349da8d015f..a614996b1b78 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py @@ -90,7 +90,11 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [IAMCredentialsClient, IAMCredentialsAsyncClient,] + "client_class", + [ + IAMCredentialsClient, + IAMCredentialsAsyncClient, + ], ) def test_iam_credentials_client_from_service_account_info(client_class): creds = ga_credentials.AnonymousCredentials() @@ -132,7 +136,11 @@ def test_iam_credentials_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", [IAMCredentialsClient, IAMCredentialsAsyncClient,] + "client_class", + [ + IAMCredentialsClient, + IAMCredentialsAsyncClient, + ], ) def test_iam_credentials_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -496,7 +504,9 @@ def test_iam_credentials_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -636,10 +646,17 @@ def test_iam_credentials_client_create_channel_credentials_file( ) -@pytest.mark.parametrize("request_type", [common.GenerateAccessTokenRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + common.GenerateAccessTokenRequest, + dict, + ], +) def test_generate_access_token(request_type, transport: str = "grpc"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -670,7 +687,8 @@ def test_generate_access_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -688,7 +706,8 @@ async def test_generate_access_token_async( transport: str = "grpc_asyncio", request_type=common.GenerateAccessTokenRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -701,7 +720,9 @@ async def test_generate_access_token_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - common.GenerateAccessTokenResponse(access_token="access_token_value",) + common.GenerateAccessTokenResponse( + access_token="access_token_value", + ) ) response = await client.generate_access_token(request) @@ -721,7 +742,9 @@ async def test_generate_access_token_async_from_dict(): def test_generate_access_token_field_headers(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -743,7 +766,10 @@ def test_generate_access_token_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -774,11 +800,16 @@ async def test_generate_access_token_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_generate_access_token_flattened(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -814,7 +845,9 @@ def test_generate_access_token_flattened(): def test_generate_access_token_flattened_error(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -889,10 +922,17 @@ async def test_generate_access_token_flattened_error_async(): ) -@pytest.mark.parametrize("request_type", [common.GenerateIdTokenRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + common.GenerateIdTokenRequest, + dict, + ], +) def test_generate_id_token(request_type, transport: str = "grpc"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -904,7 +944,9 @@ def test_generate_id_token(request_type, transport: str = "grpc"): type(client.transport.generate_id_token), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = common.GenerateIdTokenResponse(token="token_value",) + call.return_value = common.GenerateIdTokenResponse( + token="token_value", + ) response = client.generate_id_token(request) # Establish that the underlying gRPC stub method was called. @@ -921,7 +963,8 @@ def test_generate_id_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -939,7 +982,8 @@ async def test_generate_id_token_async( transport: str = "grpc_asyncio", request_type=common.GenerateIdTokenRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -952,7 +996,9 @@ async def test_generate_id_token_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - common.GenerateIdTokenResponse(token="token_value",) + common.GenerateIdTokenResponse( + token="token_value", + ) ) response = await client.generate_id_token(request) @@ -972,7 +1018,9 @@ async def test_generate_id_token_async_from_dict(): def test_generate_id_token_field_headers(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -994,7 +1042,10 @@ def test_generate_id_token_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1025,11 +1076,16 @@ async def test_generate_id_token_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_generate_id_token_flattened(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1065,7 +1121,9 @@ def test_generate_id_token_flattened(): def test_generate_id_token_flattened_error(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1140,10 +1198,17 @@ async def test_generate_id_token_flattened_error_async(): ) -@pytest.mark.parametrize("request_type", [common.SignBlobRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + common.SignBlobRequest, + dict, + ], +) def test_sign_blob(request_type, transport: str = "grpc"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1154,7 +1219,8 @@ def test_sign_blob(request_type, transport: str = "grpc"): with mock.patch.object(type(client.transport.sign_blob), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = common.SignBlobResponse( - key_id="key_id_value", signed_blob=b"signed_blob_blob", + key_id="key_id_value", + signed_blob=b"signed_blob_blob", ) response = client.sign_blob(request) @@ -1173,7 +1239,8 @@ def test_sign_blob_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1189,7 +1256,8 @@ async def test_sign_blob_async( transport: str = "grpc_asyncio", request_type=common.SignBlobRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1201,7 +1269,8 @@ async def test_sign_blob_async( # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( common.SignBlobResponse( - key_id="key_id_value", signed_blob=b"signed_blob_blob", + key_id="key_id_value", + signed_blob=b"signed_blob_blob", ) ) response = await client.sign_blob(request) @@ -1223,7 +1292,9 @@ async def test_sign_blob_async_from_dict(): def test_sign_blob_field_headers(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -1243,7 +1314,10 @@ def test_sign_blob_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1272,11 +1346,16 @@ async def test_sign_blob_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_sign_blob_flattened(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.sign_blob), "__call__") as call: @@ -1285,7 +1364,9 @@ def test_sign_blob_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.sign_blob( - name="name_value", delegates=["delegates_value"], payload=b"payload_blob", + name="name_value", + delegates=["delegates_value"], + payload=b"payload_blob", ) # Establish that the underlying call was made with the expected @@ -1304,7 +1385,9 @@ def test_sign_blob_flattened(): def test_sign_blob_flattened_error(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1334,7 +1417,9 @@ async def test_sign_blob_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.sign_blob( - name="name_value", delegates=["delegates_value"], payload=b"payload_blob", + name="name_value", + delegates=["delegates_value"], + payload=b"payload_blob", ) # Establish that the underlying call was made with the expected @@ -1369,10 +1454,17 @@ async def test_sign_blob_flattened_error_async(): ) -@pytest.mark.parametrize("request_type", [common.SignJwtRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + common.SignJwtRequest, + dict, + ], +) def test_sign_jwt(request_type, transport: str = "grpc"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1383,7 +1475,8 @@ def test_sign_jwt(request_type, transport: str = "grpc"): with mock.patch.object(type(client.transport.sign_jwt), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = common.SignJwtResponse( - key_id="key_id_value", signed_jwt="signed_jwt_value", + key_id="key_id_value", + signed_jwt="signed_jwt_value", ) response = client.sign_jwt(request) @@ -1402,7 +1495,8 @@ def test_sign_jwt_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1418,7 +1512,8 @@ async def test_sign_jwt_async( transport: str = "grpc_asyncio", request_type=common.SignJwtRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1430,7 +1525,8 @@ async def test_sign_jwt_async( # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( common.SignJwtResponse( - key_id="key_id_value", signed_jwt="signed_jwt_value", + key_id="key_id_value", + signed_jwt="signed_jwt_value", ) ) response = await client.sign_jwt(request) @@ -1452,7 +1548,9 @@ async def test_sign_jwt_async_from_dict(): def test_sign_jwt_field_headers(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -1472,7 +1570,10 @@ def test_sign_jwt_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1501,11 +1602,16 @@ async def test_sign_jwt_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_sign_jwt_flattened(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.sign_jwt), "__call__") as call: @@ -1514,7 +1620,9 @@ def test_sign_jwt_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.sign_jwt( - name="name_value", delegates=["delegates_value"], payload="payload_value", + name="name_value", + delegates=["delegates_value"], + payload="payload_value", ) # Establish that the underlying call was made with the expected @@ -1533,7 +1641,9 @@ def test_sign_jwt_flattened(): def test_sign_jwt_flattened_error(): - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1563,7 +1673,9 @@ async def test_sign_jwt_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.sign_jwt( - name="name_value", delegates=["delegates_value"], payload="payload_value", + name="name_value", + delegates=["delegates_value"], + payload="payload_value", ) # Establish that the underlying call was made with the expected @@ -1605,7 +1717,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1625,7 +1738,10 @@ def test_credentials_transport_error(): options = client_options.ClientOptions() options.api_key = "api_key" with pytest.raises(ValueError): - client = IAMCredentialsClient(client_options=options, transport=transport,) + client = IAMCredentialsClient( + client_options=options, + transport=transport, + ) # It is an error to provide an api_key and a credential. options = mock.Mock() @@ -1641,7 +1757,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = IAMCredentialsClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1686,8 +1803,13 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = IAMCredentialsClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.IAMCredentialsGrpcTransport,) + client = IAMCredentialsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.IAMCredentialsGrpcTransport, + ) def test_iam_credentials_base_transport_error(): @@ -1735,7 +1857,8 @@ def test_iam_credentials_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IAMCredentialsTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1893,7 +2016,8 @@ def test_iam_credentials_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.IAMCredentialsGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1905,7 +2029,8 @@ def test_iam_credentials_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.IAMCredentialsGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2016,7 +2141,8 @@ def test_service_account_path(): project = "squid" service_account = "clam" expected = "projects/{project}/serviceAccounts/{service_account}".format( - project=project, service_account=service_account, + project=project, + service_account=service_account, ) actual = IAMCredentialsClient.service_account_path(project, service_account) assert expected == actual @@ -2056,7 +2182,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "cuttlefish" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = IAMCredentialsClient.common_folder_path(folder) assert expected == actual @@ -2074,7 +2202,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "winkle" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = IAMCredentialsClient.common_organization_path(organization) assert expected == actual @@ -2092,7 +2222,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "scallop" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = IAMCredentialsClient.common_project_path(project) assert expected == actual @@ -2112,7 +2244,8 @@ def test_common_location_path(): project = "squid" location = "clam" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = IAMCredentialsClient.common_location_path(project, location) assert expected == actual @@ -2137,7 +2270,8 @@ def test_client_with_default_client_info(): transports.IAMCredentialsTransport, "_prep_wrapped_messages" ) as prep: client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2146,7 +2280,8 @@ def test_client_with_default_client_info(): ) as prep: transport_class = IAMCredentialsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2154,7 +2289,8 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) with mock.patch.object( type(getattr(client.transport, "grpc_channel")), "close"