Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

chore: use gapic-generator-python 0.62.1 #149

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ async def get_function(

"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -425,7 +425,7 @@ async def create_function(

"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([location, function])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -509,7 +509,7 @@ async def update_function(

"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([function])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -616,7 +616,7 @@ async def delete_function(

"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -714,7 +714,7 @@ async def call_function(
Response of CallFunction method.
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, data])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -839,8 +839,7 @@ async def generate_download_url(
limited period and should be used within minutes after
generation.
For more information about the signed URL usage see:
https://cloud.google.com/storage/docs/access-
control/signed-urls
https://cloud.google.com/storage/docs/access-control/signed-urls

Args:
request (Union[google.cloud.functions_v1.types.GenerateDownloadUrlRequest, dict]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def get_function(

"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -629,7 +629,7 @@ def create_function(

"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([location, function])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -713,7 +713,7 @@ def update_function(

"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([function])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -810,7 +810,7 @@ def delete_function(

"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -898,7 +898,7 @@ def call_function(
Response of CallFunction method.
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, data])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -1024,8 +1024,7 @@ def generate_download_url(
limited period and should be used within minutes after
generation.
For more information about the signed URL usage see:
https://cloud.google.com/storage/docs/access-
control/signed-urls
https://cloud.google.com/storage/docs/access-control/signed-urls

Args:
request (Union[google.cloud.functions_v1.types.GenerateDownloadUrlRequest, dict]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ def __init__(
if not self._grpc_channel:
self._grpc_channel = type(self).create_channel(
self._host,
# use the credentials which are saved
credentials=self._credentials,
credentials_file=credentials_file,
# Set ``credentials_file`` to ``None`` here as
# the credentials that we saved earlier should be used.
credentials_file=None,
scopes=self._scopes,
ssl_credentials=self._ssl_channel_credentials,
quota_project_id=quota_project_id,
Expand Down Expand Up @@ -238,7 +241,7 @@ def operations_client(self) -> operations_v1.OperationsClient:
This property caches on the instance; repeated calls return the same
client.
"""
# Sanity check: Only create a new client if we do not already have one.
# Quick check: Only create a new client if we do not already have one.
if self._operations_client is None:
self._operations_client = operations_v1.OperationsClient(self.grpc_channel)

Expand Down Expand Up @@ -479,8 +482,7 @@ def generate_download_url(
limited period and should be used within minutes after
generation.
For more information about the signed URL usage see:
https://cloud.google.com/storage/docs/access-
control/signed-urls
https://cloud.google.com/storage/docs/access-control/signed-urls

Returns:
Callable[[~.GenerateDownloadUrlRequest],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,11 @@ def __init__(
if not self._grpc_channel:
self._grpc_channel = type(self).create_channel(
self._host,
# use the credentials which are saved
credentials=self._credentials,
credentials_file=credentials_file,
# Set ``credentials_file`` to ``None`` here as
# the credentials that we saved earlier should be used.
credentials_file=None,
scopes=self._scopes,
ssl_credentials=self._ssl_channel_credentials,
quota_project_id=quota_project_id,
Expand Down Expand Up @@ -240,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient:
This property caches on the instance; repeated calls return the same
client.
"""
# Sanity check: Only create a new client if we do not already have one.
# Quick check: Only create a new client if we do not already have one.
if self._operations_client is None:
self._operations_client = operations_v1.OperationsAsyncClient(
self.grpc_channel
Expand Down Expand Up @@ -495,8 +498,7 @@ def generate_download_url(
limited period and should be used within minutes after
generation.
For more information about the signed URL usage see:
https://cloud.google.com/storage/docs/access-
control/signed-urls
https://cloud.google.com/storage/docs/access-control/signed-urls

Returns:
Callable[[~.GenerateDownloadUrlRequest],
Expand Down
74 changes: 72 additions & 2 deletions tests/unit/gapic/functions_v1/test_cloud_functions_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from google.api_core import gapic_v1
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
from google.api_core import operation
from google.api_core import operation_async # type: ignore
from google.api_core import operations_v1
from google.api_core import path_template
Expand Down Expand Up @@ -543,25 +544,28 @@ def test_cloud_functions_service_client_client_options_scopes(


@pytest.mark.parametrize(
"client_class,transport_class,transport_name",
"client_class,transport_class,transport_name,grpc_helpers",
[
(
CloudFunctionsServiceClient,
transports.CloudFunctionsServiceGrpcTransport,
"grpc",
grpc_helpers,
),
(
CloudFunctionsServiceAsyncClient,
transports.CloudFunctionsServiceGrpcAsyncIOTransport,
"grpc_asyncio",
grpc_helpers_async,
),
],
)
def test_cloud_functions_service_client_client_options_credentials_file(
client_class, transport_class, transport_name
client_class, transport_class, transport_name, grpc_helpers
):
# Check the case credentials file is provided.
options = client_options.ClientOptions(credentials_file="credentials.json")

with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options, transport=transport_name)
Expand Down Expand Up @@ -597,6 +601,72 @@ def test_cloud_functions_service_client_client_options_from_dict():
)


@pytest.mark.parametrize(
"client_class,transport_class,transport_name,grpc_helpers",
[
(
CloudFunctionsServiceClient,
transports.CloudFunctionsServiceGrpcTransport,
"grpc",
grpc_helpers,
),
(
CloudFunctionsServiceAsyncClient,
transports.CloudFunctionsServiceGrpcAsyncIOTransport,
"grpc_asyncio",
grpc_helpers_async,
),
],
)
def test_cloud_functions_service_client_create_channel_credentials_file(
client_class, transport_class, transport_name, grpc_helpers
):
# Check the case credentials file is provided.
options = client_options.ClientOptions(credentials_file="credentials.json")

with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options, transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file="credentials.json",
host=client.DEFAULT_ENDPOINT,
scopes=None,
client_cert_source_for_mtls=None,
quota_project_id=None,
client_info=transports.base.DEFAULT_CLIENT_INFO,
always_use_jwt_access=True,
)

# test that the credentials from file are saved and used as the credentials.
with mock.patch.object(
google.auth, "load_credentials_from_file", autospec=True
) as load_creds, mock.patch.object(
google.auth, "default", autospec=True
) as adc, mock.patch.object(
grpc_helpers, "create_channel"
) as create_channel:
creds = ga_credentials.AnonymousCredentials()
file_creds = ga_credentials.AnonymousCredentials()
load_creds.return_value = (file_creds, None)
adc.return_value = (creds, None)
client = client_class(client_options=options, transport=transport_name)
create_channel.assert_called_with(
"cloudfunctions.googleapis.com:443",
credentials=file_creds,
credentials_file=None,
quota_project_id=None,
default_scopes=("https://www.googleapis.com/auth/cloud-platform",),
scopes=None,
default_host="cloudfunctions.googleapis.com",
ssl_credentials=None,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)


@pytest.mark.parametrize("request_type", [functions.ListFunctionsRequest, dict,])
def test_list_functions(request_type, transport: str = "grpc"):
client = CloudFunctionsServiceClient(
Expand Down