Skip to content

Commit

Permalink
chore: Re-generated to pick up changes from googleapis (#95)
Browse files Browse the repository at this point in the history
* chore: update gapic-generator-python

PiperOrigin-RevId: 355923884

Source-Author: Google APIs <noreply@google.com>
Source-Date: Fri Feb 5 14:04:52 2021 -0800
Source-Repo: googleapis/googleapis
Source-Sha: 5e3dacee19405529b841b53797df799c2383536c
Source-Link: googleapis/googleapis@5e3dace

* chore: update gapic-generator-python to 0.40.11

PiperOrigin-RevId: 359562873

Source-Author: Google APIs <noreply@google.com>
Source-Date: Thu Feb 25 10:52:32 2021 -0800
Source-Repo: googleapis/googleapis
Source-Sha: 07932bb995e7dc91b43620ea8402c6668c7d102c
Source-Link: googleapis/googleapis@07932bb
  • Loading branch information
yoshi-automation authored Feb 26, 2021
1 parent ab9bb0a commit 3af2254
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,36 @@ class ContainerAnalysisAsyncClient:
ContainerAnalysisClient.parse_common_location_path
)

from_service_account_info = ContainerAnalysisClient.from_service_account_info
from_service_account_file = ContainerAnalysisClient.from_service_account_file
@classmethod
def from_service_account_info(cls, info: dict, *args, **kwargs):
"""Creates an instance of this client using the provided credentials info.
Args:
info (dict): The service account private key info.
args: Additional arguments to pass to the constructor.
kwargs: Additional arguments to pass to the constructor.
Returns:
ContainerAnalysisAsyncClient: The constructed client.
"""
return ContainerAnalysisClient.from_service_account_info.__func__(ContainerAnalysisAsyncClient, info, *args, **kwargs) # type: ignore

@classmethod
def from_service_account_file(cls, filename: str, *args, **kwargs):
"""Creates an instance of this client using the provided credentials
file.
Args:
filename (str): The path to the service account private key json
file.
args: Additional arguments to pass to the constructor.
kwargs: Additional arguments to pass to the constructor.
Returns:
ContainerAnalysisAsyncClient: The constructed client.
"""
return ContainerAnalysisClient.from_service_account_file.__func__(ContainerAnalysisAsyncClient, filename, *args, **kwargs) # type: ignore

from_service_account_json = from_service_account_file

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,10 @@ def set_iam_policy(
request = iam_policy.SetIamPolicyRequest(**request)

elif not request:
request = iam_policy.SetIamPolicyRequest(resource=resource,)
request = iam_policy.SetIamPolicyRequest()

if resource is not None:
request.resource = resource

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
Expand Down Expand Up @@ -604,7 +607,10 @@ def get_iam_policy(
request = iam_policy.GetIamPolicyRequest(**request)

elif not request:
request = iam_policy.GetIamPolicyRequest(resource=resource,)
request = iam_policy.GetIamPolicyRequest()

if resource is not None:
request.resource = resource

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
Expand Down Expand Up @@ -690,9 +696,13 @@ def test_iam_permissions(
request = iam_policy.TestIamPermissionsRequest(**request)

elif not request:
request = iam_policy.TestIamPermissionsRequest(
resource=resource, permissions=permissions,
)
request = iam_policy.TestIamPermissionsRequest()

if resource is not None:
request.resource = resource

if permissions:
request.permissions.extend(permissions)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
Expand Down
6 changes: 3 additions & 3 deletions packages/google-cloud-containeranalysis/synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/python-containeranalysis.git",
"sha": "e5bb6c9f095a4db273a9546ea02ed19c2846b738"
"sha": "ddc94b633532f22d7f4ecfc8a4de804f3522937e"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "20712b8fe95001b312f62c6c5f33e3e3ec92cfaf",
"internalRef": "354996675"
"sha": "07932bb995e7dc91b43620ea8402c6668c7d102c",
"internalRef": "359562873"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
# -*- coding: utf-8 -*-

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,19 @@ def test__get_default_mtls_endpoint():
)


def test_container_analysis_client_from_service_account_info():
@pytest.mark.parametrize(
"client_class", [ContainerAnalysisClient, ContainerAnalysisAsyncClient,]
)
def test_container_analysis_client_from_service_account_info(client_class):
creds = credentials.AnonymousCredentials()
with mock.patch.object(
service_account.Credentials, "from_service_account_info"
) as factory:
factory.return_value = creds
info = {"valid": True}
client = ContainerAnalysisClient.from_service_account_info(info)
client = client_class.from_service_account_info(info)
assert client.transport._credentials == creds
assert isinstance(client, client_class)

assert client.transport._host == "containeranalysis.googleapis.com:443"

Expand All @@ -118,9 +122,11 @@ def test_container_analysis_client_from_service_account_file(client_class):
factory.return_value = creds
client = client_class.from_service_account_file("dummy/file/path.json")
assert client.transport._credentials == creds
assert isinstance(client, client_class)

client = client_class.from_service_account_json("dummy/file/path.json")
assert client.transport._credentials == creds
assert isinstance(client, client_class)

assert client.transport._host == "containeranalysis.googleapis.com:443"

Expand Down Expand Up @@ -493,6 +499,22 @@ def test_set_iam_policy_from_dict():
test_set_iam_policy(request_type=dict)


def test_set_iam_policy_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 = ContainerAnalysisClient(
credentials=credentials.AnonymousCredentials(), transport="grpc",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call:
client.set_iam_policy()
call.assert_called()
_, args, _ = call.mock_calls[0]

assert args[0] == iam_policy.SetIamPolicyRequest()


@pytest.mark.asyncio
async def test_set_iam_policy_async(
transport: str = "grpc_asyncio", request_type=iam_policy.SetIamPolicyRequest
Expand Down Expand Up @@ -706,6 +728,22 @@ def test_get_iam_policy_from_dict():
test_get_iam_policy(request_type=dict)


def test_get_iam_policy_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 = ContainerAnalysisClient(
credentials=credentials.AnonymousCredentials(), transport="grpc",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call:
client.get_iam_policy()
call.assert_called()
_, args, _ = call.mock_calls[0]

assert args[0] == iam_policy.GetIamPolicyRequest()


@pytest.mark.asyncio
async def test_get_iam_policy_async(
transport: str = "grpc_asyncio", request_type=iam_policy.GetIamPolicyRequest
Expand Down Expand Up @@ -921,6 +959,24 @@ def test_test_iam_permissions_from_dict():
test_test_iam_permissions(request_type=dict)


def test_test_iam_permissions_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 = ContainerAnalysisClient(
credentials=credentials.AnonymousCredentials(), transport="grpc",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.test_iam_permissions), "__call__"
) as call:
client.test_iam_permissions()
call.assert_called()
_, args, _ = call.mock_calls[0]

assert args[0] == iam_policy.TestIamPermissionsRequest()


@pytest.mark.asyncio
async def test_test_iam_permissions_async(
transport: str = "grpc_asyncio", request_type=iam_policy.TestIamPermissionsRequest
Expand Down Expand Up @@ -1159,6 +1215,24 @@ def test_get_vulnerability_occurrences_summary_from_dict():
test_get_vulnerability_occurrences_summary(request_type=dict)


def test_get_vulnerability_occurrences_summary_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 = ContainerAnalysisClient(
credentials=credentials.AnonymousCredentials(), transport="grpc",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.get_vulnerability_occurrences_summary), "__call__"
) as call:
client.get_vulnerability_occurrences_summary()
call.assert_called()
_, args, _ = call.mock_calls[0]

assert args[0] == containeranalysis.GetVulnerabilityOccurrencesSummaryRequest()


@pytest.mark.asyncio
async def test_get_vulnerability_occurrences_summary_async(
transport: str = "grpc_asyncio",
Expand Down

0 comments on commit 3af2254

Please sign in to comment.