Skip to content

Commit

Permalink
update golden files
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed Jan 27, 2022
1 parent 7e7f081 commit 8b8b631
Show file tree
Hide file tree
Showing 18 changed files with 269 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ def __init__(self, *,
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 @@ -203,8 +203,11 @@ def __init__(self, *,
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 @@ -394,15 +394,16 @@ def test_asset_service_client_client_options_scopes(client_class, transport_clas
always_use_jwt_access=True,
)

@pytest.mark.parametrize("client_class,transport_class,transport_name", [
(AssetServiceClient, transports.AssetServiceGrpcTransport, "grpc"),
(AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport, "grpc_asyncio"),
@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [
(AssetServiceClient, transports.AssetServiceGrpcTransport, "grpc", grpc_helpers),
(AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async),
])
def test_asset_service_client_client_options_credentials_file(client_class, transport_class, transport_name):
def test_asset_service_client_client_options_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)
Expand All @@ -417,6 +418,36 @@ def test_asset_service_client_client_options_credentials_file(client_class, tran
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(
"cloudasset.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="cloudasset.googleapis.com",
ssl_credentials=None,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)

def test_asset_service_client_client_options_from_dict():
with mock.patch('google.cloud.asset_v1.services.asset_service.transports.AssetServiceGrpcTransport.__init__') as grpc_transport:
grpc_transport.return_value = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ def __init__(self, *,
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 @@ -208,8 +208,11 @@ def __init__(self, *,
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 @@ -385,15 +385,16 @@ def test_iam_credentials_client_client_options_scopes(client_class, transport_cl
always_use_jwt_access=True,
)

@pytest.mark.parametrize("client_class,transport_class,transport_name", [
(IAMCredentialsClient, transports.IAMCredentialsGrpcTransport, "grpc"),
(IAMCredentialsAsyncClient, transports.IAMCredentialsGrpcAsyncIOTransport, "grpc_asyncio"),
@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [
(IAMCredentialsClient, transports.IAMCredentialsGrpcTransport, "grpc", grpc_helpers),
(IAMCredentialsAsyncClient, transports.IAMCredentialsGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async),
])
def test_iam_credentials_client_client_options_credentials_file(client_class, transport_class, transport_name):
def test_iam_credentials_client_client_options_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)
Expand All @@ -408,6 +409,36 @@ def test_iam_credentials_client_client_options_credentials_file(client_class, tr
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(
"iamcredentials.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="iamcredentials.googleapis.com",
ssl_credentials=None,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)

def test_iam_credentials_client_client_options_from_dict():
with mock.patch('google.iam.credentials_v1.services.iam_credentials.transports.IAMCredentialsGrpcTransport.__init__') as grpc_transport:
grpc_transport.return_value = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ def __init__(self, *,
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 @@ -200,8 +200,11 @@ def __init__(self, *,
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 @@ -156,8 +156,11 @@ def __init__(self, *,
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 @@ -200,8 +200,11 @@ def __init__(self, *,
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 @@ -156,8 +156,11 @@ def __init__(self, *,
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 @@ -200,8 +200,11 @@ def __init__(self, *,
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 @@ -386,15 +386,16 @@ def test_config_service_v2_client_client_options_scopes(client_class, transport_
always_use_jwt_access=True,
)

@pytest.mark.parametrize("client_class,transport_class,transport_name", [
(ConfigServiceV2Client, transports.ConfigServiceV2GrpcTransport, "grpc"),
(ConfigServiceV2AsyncClient, transports.ConfigServiceV2GrpcAsyncIOTransport, "grpc_asyncio"),
@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [
(ConfigServiceV2Client, transports.ConfigServiceV2GrpcTransport, "grpc", grpc_helpers),
(ConfigServiceV2AsyncClient, transports.ConfigServiceV2GrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async),
])
def test_config_service_v2_client_client_options_credentials_file(client_class, transport_class, transport_name):
def test_config_service_v2_client_client_options_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)
Expand All @@ -409,6 +410,39 @@ def test_config_service_v2_client_client_options_credentials_file(client_class,
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(
"logging.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/cloud-platform.read-only',
'https://www.googleapis.com/auth/logging.admin',
'https://www.googleapis.com/auth/logging.read',
),
scopes=None,
default_host="logging.googleapis.com",
ssl_credentials=None,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)

def test_config_service_v2_client_client_options_from_dict():
with mock.patch('google.cloud.logging_v2.services.config_service_v2.transports.ConfigServiceV2GrpcTransport.__init__') as grpc_transport:
grpc_transport.return_value = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,16 @@ def test_logging_service_v2_client_client_options_scopes(client_class, transport
always_use_jwt_access=True,
)

@pytest.mark.parametrize("client_class,transport_class,transport_name", [
(LoggingServiceV2Client, transports.LoggingServiceV2GrpcTransport, "grpc"),
(LoggingServiceV2AsyncClient, transports.LoggingServiceV2GrpcAsyncIOTransport, "grpc_asyncio"),
@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [
(LoggingServiceV2Client, transports.LoggingServiceV2GrpcTransport, "grpc", grpc_helpers),
(LoggingServiceV2AsyncClient, transports.LoggingServiceV2GrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async),
])
def test_logging_service_v2_client_client_options_credentials_file(client_class, transport_class, transport_name):
def test_logging_service_v2_client_client_options_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)
Expand All @@ -415,6 +416,40 @@ def test_logging_service_v2_client_client_options_credentials_file(client_class,
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(
"logging.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/cloud-platform.read-only',
'https://www.googleapis.com/auth/logging.admin',
'https://www.googleapis.com/auth/logging.read',
'https://www.googleapis.com/auth/logging.write',
),
scopes=None,
default_host="logging.googleapis.com",
ssl_credentials=None,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)

def test_logging_service_v2_client_client_options_from_dict():
with mock.patch('google.cloud.logging_v2.services.logging_service_v2.transports.LoggingServiceV2GrpcTransport.__init__') as grpc_transport:
grpc_transport.return_value = None
Expand Down
Loading

0 comments on commit 8b8b631

Please sign in to comment.