Skip to content

Commit 1da1819

Browse files
committed
test: Add tests to covere deprecation and suppression
1 parent ebf3363 commit 1da1819

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/test__default.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import json
1616
import os
17+
import warnings
1718

1819
import mock
1920
import pytest # type: ignore
@@ -1410,3 +1411,52 @@ def test_quota_gce_credentials(unused_get, unused_ping):
14101411
quota_project_id=explicit_quota
14111412
)
14121413
assert credentials.quota_project_id == explicit_quota
1414+
def test_load_credentials_from_file_deprecation_warning():
1415+
with pytest.warns(
1416+
DeprecationWarning, match="The load_credentials_from_file method is deprecated"
1417+
):
1418+
_default.load_credentials_from_file(SERVICE_ACCOUNT_FILE)
1419+
1420+
1421+
def test_load_credentials_from_dict_deprecation_warning():
1422+
with pytest.warns(
1423+
DeprecationWarning, match="The load_credentials_from_dict method is deprecated"
1424+
):
1425+
_default.load_credentials_from_dict(SERVICE_ACCOUNT_FILE_DATA)
1426+
1427+
1428+
@mock.patch("google.auth._cloud_sdk.get_project_id", return_value=None, autospec=True)
1429+
@mock.patch("os.path.isfile", return_value=True, autospec=True)
1430+
@mock.patch(
1431+
"google.auth._cloud_sdk.get_application_default_credentials_path",
1432+
return_value=SERVICE_ACCOUNT_FILE,
1433+
autospec=True,
1434+
)
1435+
def test_get_gcloud_sdk_credentials_suppresses_deprecation_warning(
1436+
get_adc_path, isfile, get_project_id
1437+
):
1438+
with warnings.catch_warnings(record=True) as caught_warnings:
1439+
warnings.simplefilter("always")
1440+
1441+
_default._get_gcloud_sdk_credentials()
1442+
1443+
assert not any(
1444+
isinstance(w.message, DeprecationWarning)
1445+
and "load_credentials_from_file" in str(w.message)
1446+
for w in caught_warnings
1447+
)
1448+
1449+
1450+
def test_get_explicit_environ_credentials_suppresses_deprecation_warning(monkeypatch):
1451+
monkeypatch.setenv(environment_vars.CREDENTIALS, SERVICE_ACCOUNT_FILE)
1452+
1453+
with warnings.catch_warnings(record=True) as caught_warnings:
1454+
warnings.simplefilter("always")
1455+
1456+
_default._get_explicit_environ_credentials()
1457+
1458+
assert not any(
1459+
isinstance(w.message, DeprecationWarning)
1460+
and "load_credentials_from_file" in str(w.message)
1461+
for w in caught_warnings
1462+
)

0 commit comments

Comments
 (0)