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

Commit

Permalink
feat: add from_service_account_info (#12)
Browse files Browse the repository at this point in the history
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/fb22f59c-8962-43c6-89b6-9796466cdaca/targets

- [ ] To automatically regenerate this PR, check this box.

PiperOrigin-RevId: 359562873
Source-Link: googleapis/googleapis@07932bb
  • Loading branch information
yoshi-automation authored Mar 23, 2021
1 parent 4413a83 commit f1f7ccb
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,36 @@ class HubServiceAsyncClient:
HubServiceClient.parse_common_location_path
)

from_service_account_info = HubServiceClient.from_service_account_info
from_service_account_file = HubServiceClient.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:
HubServiceAsyncClient: The constructed client.
"""
return HubServiceClient.from_service_account_info.__func__(HubServiceAsyncClient, 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:
HubServiceAsyncClient: The constructed client.
"""
return HubServiceClient.from_service_account_file.__func__(HubServiceAsyncClient, filename, *args, **kwargs) # type: ignore

from_service_account_json = from_service_account_file

@property
Expand Down
6 changes: 3 additions & 3 deletions 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-network-connectivity.git",
"sha": "47311e98c3a67fd67a711e9ea9b5cecfd7b06bc2"
"sha": "edb1e0f97addce1cd9e575c32d2b96e6d05f6857"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "e53f05caf2fcc77c92be82bc2654e5d6000c5148",
"internalRef": "358007902"
"sha": "07932bb995e7dc91b43620ea8402c6668c7d102c",
"internalRef": "359562873"
}
},
{
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/gapic/networkconnectivity_v1alpha1/__init__.py
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.
#
168 changes: 166 additions & 2 deletions tests/unit/gapic/networkconnectivity_v1alpha1/test_hub_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@ def test__get_default_mtls_endpoint():
assert HubServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi


def test_hub_service_client_from_service_account_info():
@pytest.mark.parametrize("client_class", [HubServiceClient, HubServiceAsyncClient,])
def test_hub_service_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 = HubServiceClient.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 == "networkconnectivity.googleapis.com:443"

Expand All @@ -115,9 +117,11 @@ def test_hub_service_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 == "networkconnectivity.googleapis.com:443"

Expand Down Expand Up @@ -474,6 +478,22 @@ def test_list_hubs_from_dict():
test_list_hubs(request_type=dict)


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

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

assert args[0] == hub.ListHubsRequest()


@pytest.mark.asyncio
async def test_list_hubs_async(
transport: str = "grpc_asyncio", request_type=hub.ListHubsRequest
Expand Down Expand Up @@ -784,6 +804,22 @@ def test_get_hub_from_dict():
test_get_hub(request_type=dict)


def test_get_hub_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 = HubServiceClient(
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_hub), "__call__") as call:
client.get_hub()
call.assert_called()
_, args, _ = call.mock_calls[0]

assert args[0] == hub.GetHubRequest()


@pytest.mark.asyncio
async def test_get_hub_async(
transport: str = "grpc_asyncio", request_type=hub.GetHubRequest
Expand Down Expand Up @@ -980,6 +1016,22 @@ def test_create_hub_from_dict():
test_create_hub(request_type=dict)


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

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

assert args[0] == gcn_hub.CreateHubRequest()


@pytest.mark.asyncio
async def test_create_hub_async(
transport: str = "grpc_asyncio", request_type=gcn_hub.CreateHubRequest
Expand Down Expand Up @@ -1186,6 +1238,22 @@ def test_update_hub_from_dict():
test_update_hub(request_type=dict)


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

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

assert args[0] == gcn_hub.UpdateHubRequest()


@pytest.mark.asyncio
async def test_update_hub_async(
transport: str = "grpc_asyncio", request_type=gcn_hub.UpdateHubRequest
Expand Down Expand Up @@ -1384,6 +1452,22 @@ def test_delete_hub_from_dict():
test_delete_hub(request_type=dict)


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

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

assert args[0] == hub.DeleteHubRequest()


@pytest.mark.asyncio
async def test_delete_hub_async(
transport: str = "grpc_asyncio", request_type=hub.DeleteHubRequest
Expand Down Expand Up @@ -1575,6 +1659,22 @@ def test_list_spokes_from_dict():
test_list_spokes(request_type=dict)


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

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

assert args[0] == hub.ListSpokesRequest()


@pytest.mark.asyncio
async def test_list_spokes_async(
transport: str = "grpc_asyncio", request_type=hub.ListSpokesRequest
Expand Down Expand Up @@ -1893,6 +1993,22 @@ def test_get_spoke_from_dict():
test_get_spoke(request_type=dict)


def test_get_spoke_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 = HubServiceClient(
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_spoke), "__call__") as call:
client.get_spoke()
call.assert_called()
_, args, _ = call.mock_calls[0]

assert args[0] == hub.GetSpokeRequest()


@pytest.mark.asyncio
async def test_get_spoke_async(
transport: str = "grpc_asyncio", request_type=hub.GetSpokeRequest
Expand Down Expand Up @@ -2099,6 +2215,22 @@ def test_create_spoke_from_dict():
test_create_spoke(request_type=dict)


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

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

assert args[0] == hub.CreateSpokeRequest()


@pytest.mark.asyncio
async def test_create_spoke_async(
transport: str = "grpc_asyncio", request_type=hub.CreateSpokeRequest
Expand Down Expand Up @@ -2305,6 +2437,22 @@ def test_update_spoke_from_dict():
test_update_spoke(request_type=dict)


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

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

assert args[0] == hub.UpdateSpokeRequest()


@pytest.mark.asyncio
async def test_update_spoke_async(
transport: str = "grpc_asyncio", request_type=hub.UpdateSpokeRequest
Expand Down Expand Up @@ -2503,6 +2651,22 @@ def test_delete_spoke_from_dict():
test_delete_spoke(request_type=dict)


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

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

assert args[0] == hub.DeleteSpokeRequest()


@pytest.mark.asyncio
async def test_delete_spoke_async(
transport: str = "grpc_asyncio", request_type=hub.DeleteSpokeRequest
Expand Down

0 comments on commit f1f7ccb

Please sign in to comment.