1414
1515import json
1616import os
17+ import warnings
1718
1819import mock
1920import 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