Skip to content

Commit b159a82

Browse files
committed
chore: fix additional tests
1 parent 6287fdd commit b159a82

File tree

3 files changed

+99
-40
lines changed

3 files changed

+99
-40
lines changed

tests/asyncio/test_grpc_helpers_async.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,15 @@ 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(
526+
DeprecationWarning,
527+
match="argument is deprecated because of a potential security risk",
528+
):
529+
grpc_helpers_async.create_channel(
530+
target,
531+
credentials_file="credentials.json",
532+
credentials=mock.sentinel.credentials,
533+
)
530534

531535
assert "mutually exclusive" in str(excinfo.value)
532536

@@ -641,9 +645,13 @@ def test_create_channel_with_credentials_file(
641645
credentials_file = "/path/to/credentials/file.json"
642646
composite_creds = composite_creds_call.return_value
643647

644-
channel = grpc_helpers_async.create_channel(
645-
target, credentials_file=credentials_file
646-
)
648+
with pytest.warns(
649+
DeprecationWarning,
650+
match="argument is deprecated because of a potential security risk",
651+
):
652+
channel = grpc_helpers_async.create_channel(
653+
target, credentials_file=credentials_file
654+
)
647655

648656
google.auth.load_credentials_from_file.assert_called_once_with(
649657
credentials_file, scopes=None, default_scopes=None
@@ -670,9 +678,13 @@ def test_create_channel_with_credentials_file_and_scopes(
670678
credentials_file = "/path/to/credentials/file.json"
671679
composite_creds = composite_creds_call.return_value
672680

673-
channel = grpc_helpers_async.create_channel(
674-
target, credentials_file=credentials_file, scopes=scopes
675-
)
681+
with pytest.warns(
682+
DeprecationWarning,
683+
match="argument is deprecated because of a potential security risk",
684+
):
685+
channel = grpc_helpers_async.create_channel(
686+
target, credentials_file=credentials_file, scopes=scopes
687+
)
676688

677689
google.auth.load_credentials_from_file.assert_called_once_with(
678690
credentials_file, scopes=scopes, default_scopes=None
@@ -699,9 +711,13 @@ def test_create_channel_with_credentials_file_and_default_scopes(
699711
credentials_file = "/path/to/credentials/file.json"
700712
composite_creds = composite_creds_call.return_value
701713

702-
channel = grpc_helpers_async.create_channel(
703-
target, credentials_file=credentials_file, default_scopes=default_scopes
704-
)
714+
with pytest.warns(
715+
DeprecationWarning,
716+
match="argument is deprecated because of a potential security risk",
717+
):
718+
channel = grpc_helpers_async.create_channel(
719+
target, credentials_file=credentials_file, default_scopes=default_scopes
720+
)
705721

706722
google.auth.load_credentials_from_file.assert_called_once_with(
707723
credentials_file, scopes=None, default_scopes=default_scopes

tests/unit/operations_v1/test_operations_rest_client.py

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,11 @@ 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(
373+
DeprecationWarning,
374+
match="argument is deprecated because of a potential security risk",
375+
):
376+
options = client_options.ClientOptions(credentials_file="credentials.json")
373377
with mock.patch.object(transport_class, "__init__") as patched:
374378
patched.return_value = None
375379
client = client_class(client_options=options, transport=transport_name)
@@ -539,7 +543,11 @@ def test_operations_client_client_options_credentials_file(
539543
client_class, transport_class, transport_name
540544
):
541545
# Check the case credentials file is provided.
542-
options = client_options.ClientOptions(credentials_file="credentials.json")
546+
with pytest.warns(
547+
DeprecationWarning,
548+
match="argument is deprecated because of a potential security risk",
549+
):
550+
options = client_options.ClientOptions(credentials_file="credentials.json")
543551
if "async" in str(client_class):
544552
# TODO(): Add support for credentials file to async REST transport.
545553
with pytest.raises(core_exceptions.AsyncRestUnsupportedParameterError):
@@ -570,10 +578,21 @@ def test_operations_client_client_options_credentials_file(
570578
return_value=(mock.sentinel.credentials, mock.sentinel.project),
571579
)
572580
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-
)
581+
if credentials_file:
582+
with pytest.warns(
583+
DeprecationWarning,
584+
match="argument is deprecated because of a potential security risk",
585+
):
586+
sync_transport = transports.rest.OperationsRestTransport(
587+
credentials_file=credentials_file,
588+
http_options=HTTP_OPTIONS,
589+
)
590+
else:
591+
# no warning expected
592+
sync_transport = transports.rest.OperationsRestTransport(
593+
credentials_file=credentials_file,
594+
http_options=HTTP_OPTIONS,
595+
)
577596

578597
client = AbstractOperationsClient(transport=sync_transport)
579598

@@ -1130,10 +1149,14 @@ def test_transport_adc(client_class, transport_class, credentials):
11301149
def test_operations_base_transport_error():
11311150
# Passing both a credentials object and credentials_file should raise an error
11321151
with pytest.raises(core_exceptions.DuplicateCredentialArgs):
1133-
transports.OperationsTransport(
1134-
credentials=ga_credentials.AnonymousCredentials(),
1135-
credentials_file="credentials.json",
1136-
)
1152+
with pytest.warns(
1153+
DeprecationWarning,
1154+
match="argument is deprecated because of a potential security risk",
1155+
):
1156+
transports.OperationsTransport(
1157+
credentials=ga_credentials.AnonymousCredentials(),
1158+
credentials_file="credentials.json",
1159+
)
11371160

11381161

11391162
def test_operations_base_transport():
@@ -1171,10 +1194,14 @@ def test_operations_base_transport_with_credentials_file():
11711194
) as Transport:
11721195
Transport.return_value = None
11731196
load_creds.return_value = (ga_credentials.AnonymousCredentials(), None)
1174-
transports.OperationsTransport(
1175-
credentials_file="credentials.json",
1176-
quota_project_id="octopus",
1177-
)
1197+
with pytest.warns(
1198+
DeprecationWarning,
1199+
match="argument is deprecated because of a potential security risk",
1200+
):
1201+
transports.OperationsTransport(
1202+
credentials_file="credentials.json",
1203+
quota_project_id="octopus",
1204+
)
11781205
load_creds.assert_called_once_with(
11791206
"credentials.json",
11801207
scopes=None,

tests/unit/test_grpc_helpers.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,15 @@ 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(
585+
DeprecationWarning,
586+
match="argument is deprecated because of a potential security risk",
587+
):
588+
grpc_helpers.create_channel(
589+
target,
590+
credentials_file="credentials.json",
591+
credentials=mock.sentinel.credentials,
592+
)
589593

590594

591595
@mock.patch("grpc.compute_engine_channel_credentials")
@@ -710,7 +714,11 @@ def test_create_channel_with_credentials_file(
710714
credentials_file = "/path/to/credentials/file.json"
711715
composite_creds = composite_creds_call.return_value
712716

713-
channel = grpc_helpers.create_channel(target, credentials_file=credentials_file)
717+
with pytest.warns(
718+
DeprecationWarning,
719+
match="argument is deprecated because of a potential security risk",
720+
):
721+
channel = grpc_helpers.create_channel(target, credentials_file=credentials_file)
714722

715723
google.auth.load_credentials_from_file.assert_called_once_with(
716724
credentials_file, scopes=None, default_scopes=None
@@ -742,9 +750,13 @@ def test_create_channel_with_credentials_file_and_scopes(
742750
credentials_file = "/path/to/credentials/file.json"
743751
composite_creds = composite_creds_call.return_value
744752

745-
channel = grpc_helpers.create_channel(
746-
target, credentials_file=credentials_file, scopes=scopes
747-
)
753+
with pytest.warns(
754+
DeprecationWarning,
755+
match="argument is deprecated because of a potential security risk",
756+
):
757+
channel = grpc_helpers.create_channel(
758+
target, credentials_file=credentials_file, scopes=scopes
759+
)
748760

749761
google.auth.load_credentials_from_file.assert_called_once_with(
750762
credentials_file, scopes=scopes, default_scopes=None
@@ -776,9 +788,13 @@ def test_create_channel_with_credentials_file_and_default_scopes(
776788
credentials_file = "/path/to/credentials/file.json"
777789
composite_creds = composite_creds_call.return_value
778790

779-
channel = grpc_helpers.create_channel(
780-
target, credentials_file=credentials_file, default_scopes=default_scopes
781-
)
791+
with pytest.warns(
792+
DeprecationWarning,
793+
match="argument is deprecated because of a potential security risk",
794+
):
795+
channel = grpc_helpers.create_channel(
796+
target, credentials_file=credentials_file, default_scopes=default_scopes
797+
)
782798

783799
load_credentials_from_file.assert_called_once_with(
784800
credentials_file, scopes=None, default_scopes=default_scopes

0 commit comments

Comments
 (0)