Skip to content

Commit ab8cc79

Browse files
committed
chore: update credentials file unit tests
1 parent 628003e commit ab8cc79

File tree

5 files changed

+89
-65
lines changed

5 files changed

+89
-65
lines changed

tests/asyncio/test_grpc_helpers_async.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,12 @@ def test_create_channel_explicit_with_duplicate_credentials():
522522
target = "example:443"
523523

524524
with pytest.raises(exceptions.DuplicateCredentialArgs) as excinfo:
525-
grpc_helpers_async.create_channel(
526-
target,
527-
credentials_file="credentials.json",
528-
credentials=mock.sentinel.credentials,
529-
)
525+
with pytest.warns(DeprecationWarning):
526+
grpc_helpers_async.create_channel(
527+
target,
528+
credentials_file="credentials.json",
529+
credentials=mock.sentinel.credentials,
530+
)
530531

531532
assert "mutually exclusive" in str(excinfo.value)
532533

@@ -641,9 +642,10 @@ def test_create_channel_with_credentials_file(
641642
credentials_file = "/path/to/credentials/file.json"
642643
composite_creds = composite_creds_call.return_value
643644

644-
channel = grpc_helpers_async.create_channel(
645-
target, credentials_file=credentials_file
646-
)
645+
with pytest.warns(DeprecationWarning):
646+
channel = grpc_helpers_async.create_channel(
647+
target, credentials_file=credentials_file
648+
)
647649

648650
google.auth.load_credentials_from_file.assert_called_once_with(
649651
credentials_file, scopes=None, default_scopes=None
@@ -670,9 +672,10 @@ def test_create_channel_with_credentials_file_and_scopes(
670672
credentials_file = "/path/to/credentials/file.json"
671673
composite_creds = composite_creds_call.return_value
672674

673-
channel = grpc_helpers_async.create_channel(
674-
target, credentials_file=credentials_file, scopes=scopes
675-
)
675+
with pytest.warns(DeprecationWarning):
676+
channel = grpc_helpers_async.create_channel(
677+
target, credentials_file=credentials_file, scopes=scopes
678+
)
676679

677680
google.auth.load_credentials_from_file.assert_called_once_with(
678681
credentials_file, scopes=scopes, default_scopes=None
@@ -699,9 +702,10 @@ def test_create_channel_with_credentials_file_and_default_scopes(
699702
credentials_file = "/path/to/credentials/file.json"
700703
composite_creds = composite_creds_call.return_value
701704

702-
channel = grpc_helpers_async.create_channel(
703-
target, credentials_file=credentials_file, default_scopes=default_scopes
704-
)
705+
with pytest.warns(DeprecationWarning):
706+
channel = grpc_helpers_async.create_channel(
707+
target, credentials_file=credentials_file, default_scopes=default_scopes
708+
)
705709

706710
google.auth.load_credentials_from_file.assert_called_once_with(
707711
credentials_file, scopes=None, default_scopes=default_scopes

tests/unit/operations_v1/test_operations_rest_client.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ def test_operations_client_client_options(
369369
)
370370

371371
# Check the case credentials_file is provided
372-
options = client_options.ClientOptions(credentials_file="credentials.json")
372+
with pytest.warns(DeprecationWarning):
373+
options = client_options.ClientOptions(credentials_file="credentials.json")
373374
with mock.patch.object(transport_class, "__init__") as patched:
374375
patched.return_value = None
375376
client = client_class(client_options=options, transport=transport_name)
@@ -539,7 +540,8 @@ def test_operations_client_client_options_credentials_file(
539540
client_class, transport_class, transport_name
540541
):
541542
# Check the case credentials file is provided.
542-
options = client_options.ClientOptions(credentials_file="credentials.json")
543+
with pytest.warns(DeprecationWarning):
544+
options = client_options.ClientOptions(credentials_file="credentials.json")
543545
if "async" in str(client_class):
544546
# TODO(): Add support for credentials file to async REST transport.
545547
with pytest.raises(core_exceptions.AsyncRestUnsupportedParameterError):
@@ -570,10 +572,17 @@ def test_operations_client_client_options_credentials_file(
570572
return_value=(mock.sentinel.credentials, mock.sentinel.project),
571573
)
572574
def test_list_operations_rest(google_auth_default, credentials_file):
573-
sync_transport = transports.rest.OperationsRestTransport(
574-
credentials_file=credentials_file,
575-
http_options=HTTP_OPTIONS,
576-
)
575+
if credentials_file is not None:
576+
with pytest.warns(DeprecationWarning):
577+
sync_transport = transports.rest.OperationsRestTransport(
578+
credentials_file=credentials_file,
579+
http_options=HTTP_OPTIONS,
580+
)
581+
else:
582+
sync_transport = transports.rest.OperationsRestTransport(
583+
credentials_file=credentials_file,
584+
http_options=HTTP_OPTIONS,
585+
)
577586

578587
client = AbstractOperationsClient(transport=sync_transport)
579588

@@ -1130,10 +1139,11 @@ def test_transport_adc(client_class, transport_class, credentials):
11301139
def test_operations_base_transport_error():
11311140
# Passing both a credentials object and credentials_file should raise an error
11321141
with pytest.raises(core_exceptions.DuplicateCredentialArgs):
1133-
transports.OperationsTransport(
1134-
credentials=ga_credentials.AnonymousCredentials(),
1135-
credentials_file="credentials.json",
1136-
)
1142+
with pytest.warns(DeprecationWarning):
1143+
transports.OperationsTransport(
1144+
credentials=ga_credentials.AnonymousCredentials(),
1145+
credentials_file="credentials.json",
1146+
)
11371147

11381148

11391149
def test_operations_base_transport():
@@ -1171,10 +1181,11 @@ def test_operations_base_transport_with_credentials_file():
11711181
) as Transport:
11721182
Transport.return_value = None
11731183
load_creds.return_value = (ga_credentials.AnonymousCredentials(), None)
1174-
transports.OperationsTransport(
1175-
credentials_file="credentials.json",
1176-
quota_project_id="octopus",
1177-
)
1184+
with pytest.warns(DeprecationWarning):
1185+
transports.OperationsTransport(
1186+
credentials_file="credentials.json",
1187+
quota_project_id="octopus",
1188+
)
11781189
load_creds.assert_called_once_with(
11791190
"credentials.json",
11801191
scopes=None,

tests/unit/test_client_options.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ def get_client_encrypted_cert():
2727

2828

2929
def test_constructor():
30-
31-
options = client_options.ClientOptions(
32-
api_endpoint="foo.googleapis.com",
33-
client_cert_source=get_client_cert,
34-
quota_project_id="quote-proj",
35-
credentials_file="path/to/credentials.json",
36-
scopes=[
37-
"https://www.googleapis.com/auth/cloud-platform",
38-
"https://www.googleapis.com/auth/cloud-platform.read-only",
39-
],
40-
api_audience="foo2.googleapis.com",
41-
universe_domain="googleapis.com",
42-
)
30+
with pytest.warns(DeprecationWarning):
31+
options = client_options.ClientOptions(
32+
api_endpoint="foo.googleapis.com",
33+
client_cert_source=get_client_cert,
34+
quota_project_id="quote-proj",
35+
credentials_file="path/to/credentials.json",
36+
scopes=[
37+
"https://www.googleapis.com/auth/cloud-platform",
38+
"https://www.googleapis.com/auth/cloud-platform.read-only",
39+
],
40+
api_audience="foo2.googleapis.com",
41+
universe_domain="googleapis.com",
42+
)
4343

4444
assert options.api_endpoint == "foo.googleapis.com"
4545
assert options.client_cert_source() == (b"cert", b"key")
@@ -102,10 +102,11 @@ def test_constructor_with_api_key():
102102

103103
def test_constructor_with_both_api_key_and_credentials_file():
104104
with pytest.raises(ValueError):
105-
client_options.ClientOptions(
106-
api_key="api-key",
107-
credentials_file="path/to/credentials.json",
108-
)
105+
with pytest.warns(DeprecationWarning):
106+
client_options.ClientOptions(
107+
api_key="api-key",
108+
credentials_file="path/to/credentials.json",
109+
)
109110

110111

111112
def test_from_dict():

tests/unit/test_grpc_helpers.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,12 @@ def test_create_channel_explicit_with_duplicate_credentials():
581581
target = "example.com:443"
582582

583583
with pytest.raises(exceptions.DuplicateCredentialArgs):
584-
grpc_helpers.create_channel(
585-
target,
586-
credentials_file="credentials.json",
587-
credentials=mock.sentinel.credentials,
588-
)
584+
with pytest.warns(DeprecationWarning):
585+
grpc_helpers.create_channel(
586+
target,
587+
credentials_file="credentials.json",
588+
credentials=mock.sentinel.credentials,
589+
)
589590

590591

591592
@mock.patch("grpc.compute_engine_channel_credentials")
@@ -710,7 +711,8 @@ def test_create_channel_with_credentials_file(
710711
credentials_file = "/path/to/credentials/file.json"
711712
composite_creds = composite_creds_call.return_value
712713

713-
channel = grpc_helpers.create_channel(target, credentials_file=credentials_file)
714+
with pytest.warns(DeprecationWarning):
715+
channel = grpc_helpers.create_channel(target, credentials_file=credentials_file)
714716

715717
google.auth.load_credentials_from_file.assert_called_once_with(
716718
credentials_file, scopes=None, default_scopes=None
@@ -742,9 +744,10 @@ def test_create_channel_with_credentials_file_and_scopes(
742744
credentials_file = "/path/to/credentials/file.json"
743745
composite_creds = composite_creds_call.return_value
744746

745-
channel = grpc_helpers.create_channel(
746-
target, credentials_file=credentials_file, scopes=scopes
747-
)
747+
with pytest.warns(DeprecationWarning):
748+
channel = grpc_helpers.create_channel(
749+
target, credentials_file=credentials_file, scopes=scopes
750+
)
748751

749752
google.auth.load_credentials_from_file.assert_called_once_with(
750753
credentials_file, scopes=scopes, default_scopes=None
@@ -776,9 +779,10 @@ def test_create_channel_with_credentials_file_and_default_scopes(
776779
credentials_file = "/path/to/credentials/file.json"
777780
composite_creds = composite_creds_call.return_value
778781

779-
channel = grpc_helpers.create_channel(
780-
target, credentials_file=credentials_file, default_scopes=default_scopes
781-
)
782+
with pytest.warns(DeprecationWarning):
783+
channel = grpc_helpers.create_channel(
784+
target, credentials_file=credentials_file, default_scopes=default_scopes
785+
)
782786

783787
load_credentials_from_file.assert_called_once_with(
784788
credentials_file, scopes=None, default_scopes=default_scopes

tests/unit/test_python_version_support.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,20 @@ def test_override_gapic_end_only():
178178
"google.api_core._python_version_support.PYTHON_VERSION_INFO",
179179
{version_tuple: overridden_info},
180180
):
181-
result_before_boundary = check_python_version(
182-
today=custom_gapic_end + datetime.timedelta(days=-1)
183-
)
181+
with pytest.warns(FutureWarning):
182+
result_before_boundary = check_python_version(
183+
today=custom_gapic_end + datetime.timedelta(days=-1)
184+
)
184185
assert result_before_boundary == PythonVersionStatus.PYTHON_VERSION_EOL
185186

186-
result_at_boundary = check_python_version(today=custom_gapic_end)
187+
with pytest.warns(FutureWarning):
188+
result_at_boundary = check_python_version(today=custom_gapic_end)
187189
assert result_at_boundary == PythonVersionStatus.PYTHON_VERSION_EOL
188190

189-
result_after_boundary = check_python_version(
190-
today=custom_gapic_end + datetime.timedelta(days=1)
191-
)
191+
with pytest.warns(FutureWarning):
192+
result_after_boundary = check_python_version(
193+
today=custom_gapic_end + datetime.timedelta(days=1)
194+
)
192195
assert (
193196
result_after_boundary == PythonVersionStatus.PYTHON_VERSION_UNSUPPORTED
194197
)
@@ -217,7 +220,8 @@ def test_override_gapic_deprecation_only():
217220
result_before_boundary == PythonVersionStatus.PYTHON_VERSION_SUPPORTED
218221
)
219222

220-
result_at_boundary = check_python_version(today=custom_gapic_dep)
223+
with pytest.warns(FutureWarning):
224+
result_at_boundary = check_python_version(today=custom_gapic_dep)
221225
assert result_at_boundary == PythonVersionStatus.PYTHON_VERSION_DEPRECATED
222226

223227

0 commit comments

Comments
 (0)