| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,7 @@ | |||
| 35 | 35 | import io | |
| 36 | 36 | import json | |
| 37 | 37 | import logging | |
| 38 | + import warnings | ||
| 38 | 39 | ||
| 39 | 40 | import six | |
| 40 | 41 | ||
@@ -498,6 +499,13 @@ class UserAccessTokenCredentials(credentials.CredentialsWithQuotaProject): | |||
| 498 | 499 | """ | |
| 499 | 500 | ||
| 500 | 501 | def __init__(self, account=None, quota_project_id=None): | |
| 502 | + warnings.warn( | ||
| 503 | + "UserAccessTokenCredentials is deprecated, please use " | ||
| 504 | + "google.oauth2.credentials.Credentials instead. To use " | ||
| 505 | + "that credential type, simply run " | ||
| 506 | + "`gcloud auth application-default login` and let the " | ||
| 507 | + "client libraries pick up the application default credentials." | ||
| 508 | + ) | ||
| 501 | 509 | super(UserAccessTokenCredentials, self).__init__() | |
| 502 | 510 | self._account = account | |
| 503 | 511 | self._quota_project_id = quota_project_id | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -951,25 +951,34 @@ def test_unpickle_old_credentials_pickle(self): | |||
| 951 | 951 | ||
| 952 | 952 | class TestUserAccessTokenCredentials(object): | |
| 953 | 953 | def test_instance(self): | |
| 954 | - cred = credentials.UserAccessTokenCredentials() | ||
| 955 | - assert cred._account is None | ||
| 954 | + with pytest.warns( | ||
| 955 | + UserWarning, match="UserAccessTokenCredentials is deprecated" | ||
| 956 | + ): | ||
| 957 | + cred = credentials.UserAccessTokenCredentials() | ||
| 958 | + assert cred._account is None | ||
| 956 | 959 | ||
| 957 | - cred = cred.with_account("account") | ||
| 958 | - assert cred._account == "account" | ||
| 960 | + cred = cred.with_account("account") | ||
| 961 | + assert cred._account == "account" | ||
| 959 | 962 | ||
| 960 | 963 | @mock.patch("google.auth._cloud_sdk.get_auth_access_token", autospec=True) | |
| 961 | 964 | def test_refresh(self, get_auth_access_token): | |
| 962 | - get_auth_access_token.return_value = "access_token" | ||
| 963 | - cred = credentials.UserAccessTokenCredentials() | ||
| 964 | - cred.refresh(None) | ||
| 965 | - assert cred.token == "access_token" | ||
| 965 | + with pytest.warns( | ||
| 966 | + UserWarning, match="UserAccessTokenCredentials is deprecated" | ||
| 967 | + ): | ||
| 968 | + get_auth_access_token.return_value = "access_token" | ||
| 969 | + cred = credentials.UserAccessTokenCredentials() | ||
| 970 | + cred.refresh(None) | ||
| 971 | + assert cred.token == "access_token" | ||
| 966 | 972 | ||
| 967 | 973 | def test_with_quota_project(self): | |
| 968 | - cred = credentials.UserAccessTokenCredentials() | ||
| 969 | - quota_project_cred = cred.with_quota_project("project-foo") | ||
| 974 | + with pytest.warns( | ||
| 975 | + UserWarning, match="UserAccessTokenCredentials is deprecated" | ||
| 976 | + ): | ||
| 977 | + cred = credentials.UserAccessTokenCredentials() | ||
| 978 | + quota_project_cred = cred.with_quota_project("project-foo") | ||
| 970 | 979 | ||
| 971 | - assert quota_project_cred._quota_project_id == "project-foo" | ||
| 972 | - assert quota_project_cred._account == cred._account | ||
| 980 | + assert quota_project_cred._quota_project_id == "project-foo" | ||
| 981 | + assert quota_project_cred._account == cred._account | ||
| 973 | 982 | ||
| 974 | 983 | @mock.patch( | |
| 975 | 984 | "google.oauth2.credentials.UserAccessTokenCredentials.apply", autospec=True | |
@@ -978,7 +987,10 @@ def test_with_quota_project(self): | |||
| 978 | 987 | "google.oauth2.credentials.UserAccessTokenCredentials.refresh", autospec=True | |
| 979 | 988 | ) | |
| 980 | 989 | def test_before_request(self, refresh, apply): | |
| 981 | - cred = credentials.UserAccessTokenCredentials() | ||
| 982 | - cred.before_request(mock.Mock(), "GET", "https://example.com", {}) | ||
| 983 | - refresh.assert_called() | ||
| 984 | - apply.assert_called() | ||
| 990 | + with pytest.warns( | ||
| 991 | + UserWarning, match="UserAccessTokenCredentials is deprecated" | ||
| 992 | + ): | ||
| 993 | + cred = credentials.UserAccessTokenCredentials() | ||
| 994 | + cred.before_request(mock.Mock(), "GET", "https://example.com", {}) | ||
| 995 | + refresh.assert_called() | ||
| 996 | + apply.assert_called() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments