Skip to content

Commit fbacd50

Browse files
authored
test: Support running the test suite without oauth2client (#2021)
* test: make MockCredentials class standalone Remove the inheritance of MockCredentials from oauth2client.Credentials. This is unnecessary, and removing it makes it possible to run the respective tests without oauth2client installed. * test: Support testing without oauth2client Make it possible to run the test suite without oauth2client, by skipping the few tests that specifically require it. Given that oauth2client is deprecated, we are aiming towards removing it entirely from Gentoo and the unconditional imports in the test suite are a blocker for that. * test: Test without oauth2client as well
1 parent ce9188c commit fbacd50

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

noxfile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def format(session):
8484
@nox.parametrize(
8585
"oauth2client",
8686
[
87+
None,
8788
"oauth2client<2dev",
8889
"oauth2client>=2,<=3dev",
8990
"oauth2client>=3,<=4dev",
@@ -96,7 +97,8 @@ def unit(session, oauth2client):
9697
shutil.rmtree("build", ignore_errors=True)
9798

9899
session.install(*test_dependencies)
99-
session.install(oauth2client)
100+
if oauth2client is not None:
101+
session.install(oauth2client)
100102

101103
# Create and install wheels
102104
session.run("python3", "setup.py", "bdist_wheel")

tests/test__auth.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
import google.auth.credentials
1919
import google_auth_httplib2
2020
import httplib2
21-
import oauth2client.client
21+
22+
try:
23+
import oauth2client.client
24+
25+
HAS_OAUTH2CLIENT = True
26+
except ImportError:
27+
HAS_OAUTH2CLIENT = False
2228

2329
from googleapiclient import _auth
2430

@@ -105,6 +111,7 @@ def test_authorized_http(self):
105111
self.assertGreater(authorized_http.http.timeout, 0)
106112

107113

114+
@unittest.skipIf(not HAS_OAUTH2CLIENT, "oauth2client unavailable.")
108115
class TestAuthWithOAuth2Client(unittest.TestCase):
109116
def setUp(self):
110117
_auth.HAS_GOOGLE_AUTH = False

tests/test_discovery.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@
4343
from google.auth.exceptions import MutualTLSChannelError
4444
import google_auth_httplib2
4545
import httplib2
46-
from oauth2client import GOOGLE_TOKEN_URI
47-
from oauth2client.client import GoogleCredentials, OAuth2Credentials
4846
from parameterized import parameterized
4947
import uritemplate
5048

49+
try:
50+
from oauth2client import GOOGLE_TOKEN_URI
51+
from oauth2client.client import GoogleCredentials, OAuth2Credentials
52+
53+
HAS_OAUTH2CLIENT = True
54+
except ImportError:
55+
HAS_OAUTH2CLIENT = False
56+
5157
from googleapiclient import _helpers as util
5258
from googleapiclient.discovery import (
5359
DISCOVERY_URI,
@@ -1513,6 +1519,7 @@ def test_plus_resources(self):
15131519
self.assertTrue(getattr(plus, "activities"))
15141520
self.assertTrue(getattr(plus, "people"))
15151521

1522+
@unittest.skipIf(not HAS_OAUTH2CLIENT, "oauth2client unavailable.")
15161523
def test_oauth2client_credentials(self):
15171524
credentials = mock.Mock(spec=GoogleCredentials)
15181525
credentials.create_scoped_required.return_value = False
@@ -2198,6 +2205,7 @@ def _dummy_token(self):
21982205
user_agent,
21992206
)
22002207

2208+
@unittest.skipIf(not HAS_OAUTH2CLIENT, "oauth2client unavailable.")
22012209
def test_pickle_with_credentials(self):
22022210
credentials = self._dummy_token()
22032211
http = self._dummy_zoo_request()

tests/test_http.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import urllib
3939

4040
import httplib2
41-
from oauth2client.client import Credentials
4241

4342
from googleapiclient.discovery import build
4443
from googleapiclient.errors import BatchError, HttpError, InvalidChunkSizeError
@@ -60,7 +59,7 @@
6059
from googleapiclient.model import JsonModel
6160

6261

63-
class MockCredentials(Credentials):
62+
class MockCredentials:
6463
"""Mock class for all Credentials objects."""
6564

6665
def __init__(self, bearer_token, expired=False):

0 commit comments

Comments
 (0)