Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
chore: use gapic-generator-python 0.62.1 (#179)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

fix: resolve DuplicateCredentialArgs error when using credentials_file

committer: parthea
PiperOrigin-RevId: 425964861

Source-Link: googleapis/googleapis@84b1a5a

Source-Link: googleapis/googleapis-gen@4fb761b
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGZiNzYxYmJkODUwNmFjMTU2ZjQ5YmFjNWYxODMwNmFhOGViM2FhOCJ9
  • Loading branch information
gcf-owl-bot[bot] committed Feb 3, 2022
1 parent 5c1ea85 commit e0294af
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 21 deletions.
6 changes: 3 additions & 3 deletions google/cloud/trace_v1/services/trace_service/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ async def list_traces(
"""
# 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([project_id])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -331,7 +331,7 @@ async def get_trace(
"""
# 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([project_id, trace_id])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -414,7 +414,7 @@ async def patch_traces(
sent along with the request as metadata.
"""
# 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([project_id, traces])
if request is not None and has_flattened_params:
Expand Down
6 changes: 3 additions & 3 deletions google/cloud/trace_v1/services/trace_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def list_traces(
"""
# 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([project_id])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -506,7 +506,7 @@ def get_trace(
"""
# 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([project_id, trace_id])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -579,7 +579,7 @@ def patch_traces(
sent along with the request as metadata.
"""
# 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([project_id, traces])
if request is not None and has_flattened_params:
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
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
6 changes: 3 additions & 3 deletions google/cloud/trace_v1/types/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class TraceSpan(proto.Message):
bytes. The span name is sanitized and displayed
in the Stackdriver Trace tool in the Google
Cloud Platform Console.
The name may be a method name or some other per-
call site name. For the same executable and the
same call point, a best practice is to use a
The name may be a method name or some other
per-call site name. For the same executable and
the same call point, a best practice is to use a
consistent name, which makes it easier to
correlate cross-trace spans.
start_time (google.protobuf.timestamp_pb2.Timestamp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async def batch_write_spans(
sent along with the request as metadata.
"""
# 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, spans])
if request is not None and has_flattened_params:
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/trace_v2/services/trace_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def batch_write_spans(
sent along with the request as metadata.
"""
# 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, spans])
if request is not None and has_flattened_params:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,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
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,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
83 changes: 80 additions & 3 deletions tests/unit/gapic/trace_v1/test_trace_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,21 +494,28 @@ def test_trace_service_client_client_options_scopes(


@pytest.mark.parametrize(
"client_class,transport_class,transport_name",
"client_class,transport_class,transport_name,grpc_helpers",
[
(TraceServiceClient, transports.TraceServiceGrpcTransport, "grpc"),
(
TraceServiceClient,
transports.TraceServiceGrpcTransport,
"grpc",
grpc_helpers,
),
(
TraceServiceAsyncClient,
transports.TraceServiceGrpcAsyncIOTransport,
"grpc_asyncio",
grpc_helpers_async,
),
],
)
def test_trace_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 @@ -542,6 +549,76 @@ def test_trace_service_client_client_options_from_dict():
)


@pytest.mark.parametrize(
"client_class,transport_class,transport_name,grpc_helpers",
[
(
TraceServiceClient,
transports.TraceServiceGrpcTransport,
"grpc",
grpc_helpers,
),
(
TraceServiceAsyncClient,
transports.TraceServiceGrpcAsyncIOTransport,
"grpc_asyncio",
grpc_helpers_async,
),
],
)
def test_trace_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(
"cloudtrace.googleapis.com:443",
credentials=file_creds,
credentials_file=None,
quota_project_id=None,
default_scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/trace.append",
"https://www.googleapis.com/auth/trace.readonly",
),
scopes=None,
default_host="cloudtrace.googleapis.com",
ssl_credentials=None,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)


@pytest.mark.parametrize("request_type", [trace.ListTracesRequest, dict,])
def test_list_traces(request_type, transport: str = "grpc"):
client = TraceServiceClient(
Expand Down
82 changes: 79 additions & 3 deletions tests/unit/gapic/trace_v2/test_trace_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,21 +497,28 @@ def test_trace_service_client_client_options_scopes(


@pytest.mark.parametrize(
"client_class,transport_class,transport_name",
"client_class,transport_class,transport_name,grpc_helpers",
[
(TraceServiceClient, transports.TraceServiceGrpcTransport, "grpc"),
(
TraceServiceClient,
transports.TraceServiceGrpcTransport,
"grpc",
grpc_helpers,
),
(
TraceServiceAsyncClient,
transports.TraceServiceGrpcAsyncIOTransport,
"grpc_asyncio",
grpc_helpers_async,
),
],
)
def test_trace_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 @@ -545,6 +552,75 @@ def test_trace_service_client_client_options_from_dict():
)


@pytest.mark.parametrize(
"client_class,transport_class,transport_name,grpc_helpers",
[
(
TraceServiceClient,
transports.TraceServiceGrpcTransport,
"grpc",
grpc_helpers,
),
(
TraceServiceAsyncClient,
transports.TraceServiceGrpcAsyncIOTransport,
"grpc_asyncio",
grpc_helpers_async,
),
],
)
def test_trace_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(
"cloudtrace.googleapis.com:443",
credentials=file_creds,
credentials_file=None,
quota_project_id=None,
default_scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/trace.append",
),
scopes=None,
default_host="cloudtrace.googleapis.com",
ssl_credentials=None,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)


@pytest.mark.parametrize("request_type", [tracing.BatchWriteSpansRequest, dict,])
def test_batch_write_spans(request_type, transport: str = "grpc"):
client = TraceServiceClient(
Expand Down

0 comments on commit e0294af

Please sign in to comment.