From 072283e3853260142143a56b8e604493f2bc8913 Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Fri, 25 Sep 2020 14:12:35 -0700 Subject: [PATCH] refactor: port #561 split 'with_quota_project' into separate base class --- google/auth/_credentials_async.py | 4 ++++ tests_async/test__default_async.py | 2 +- tests_async/test_credentials_async.py | 6 ------ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/google/auth/_credentials_async.py b/google/auth/_credentials_async.py index 1aafe0b17..d4d4e2c0e 100644 --- a/google/auth/_credentials_async.py +++ b/google/auth/_credentials_async.py @@ -70,6 +70,10 @@ async def before_request(self, request, method, url, headers): self.apply(headers) +class CredentialsWithQuotaProject(credentials.CredentialsWithQuotaProject): + """Abstract base for credentials supporting ``with_quota_project`` factory""" + + class AnonymousCredentials(credentials.AnonymousCredentials, Credentials): """Credentials that do not provide any authentication information. diff --git a/tests_async/test__default_async.py b/tests_async/test__default_async.py index 75774d987..21fc92e92 100644 --- a/tests_async/test__default_async.py +++ b/tests_async/test__default_async.py @@ -28,7 +28,7 @@ import google.oauth2.credentials from tests import test__default as test_default -MOCK_CREDENTIALS = mock.Mock(spec=credentials.Credentials) +MOCK_CREDENTIALS = mock.Mock(spec=credentials.CredentialsWithQuotaProject) MOCK_CREDENTIALS.with_quota_project.return_value = MOCK_CREDENTIALS LOAD_FILE_PATCH = mock.patch( diff --git a/tests_async/test_credentials_async.py b/tests_async/test_credentials_async.py index 43c46ac5a..5a5de8518 100644 --- a/tests_async/test_credentials_async.py +++ b/tests_async/test_credentials_async.py @@ -118,12 +118,6 @@ def test_anonymous_credentials_before_request(): assert headers == {} -def test_anonymous_credentials_with_quota_project(): - with pytest.raises(ValueError): - anon = credentials.AnonymousCredentials() - anon.with_quota_project("project-foo") - - class ReadOnlyScopedCredentialsImpl(credentials.ReadOnlyScoped, CredentialsImpl): @property def requires_scopes(self):