Skip to content

Commit 36d4e1b

Browse files
Jon Wayne Parrottnathanielmanistaatgoogle
authored andcommitted
Add support for oauth2client 4.0.0
1 parent be8b1cb commit 36d4e1b

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

googleapiclient/discovery_cache/file_cache.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
from oauth2client.contrib.locked_file import LockedFile
3434
except ImportError:
3535
# oauth2client < 2.0.0
36-
from oauth2client.locked_file import LockedFile
36+
try:
37+
from oauth2client.locked_file import LockedFile
38+
except ImportError:
39+
# oauth2client > 4.0.0
40+
raise ImportError(
41+
'file_cache is unavailable when using oauth2client >= 4.0.0')
3742

3843
from . import base
3944
from ..discovery_cache import DISCOVERY_DOC_MAX_AGE

tests/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515

1616
__author__ = '[email protected] (Ali Afshar)'
1717

18-
import oauth2client.util
18+
19+
# Oauth2client < 3 has the positional helper in 'util', >= 3 has it
20+
# in '_helpers'.
21+
try:
22+
from oauth2client import util
23+
except ImportError:
24+
from oauth2client import _helpers as util
25+
1926

2027
def setup_package():
2128
"""Run on testing package."""
22-
oauth2client.util.positional_parameters_enforcement = 'EXCEPTION'
29+
util.positional_parameters_enforcement = 'EXCEPTION'

tests/test_discovery.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,18 @@
7070
from googleapiclient.http import MediaUploadProgress
7171
from googleapiclient.http import tunnel_patch
7272
from oauth2client import GOOGLE_TOKEN_URI
73-
from oauth2client import util
7473
from oauth2client.client import OAuth2Credentials
7574

75+
try:
76+
from oauth2client import util
77+
except ImportError:
78+
from oauth2client import _helpers as util
79+
7680
import uritemplate
7781

7882

7983
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
8084

81-
util.positional_parameters_enforcement = util.POSITIONAL_EXCEPTION
82-
8385

8486
def assertUrisEqual(testcase, expected, actual):
8587
"""Test that URIs are the same, up to reordering of query parameters."""
@@ -501,8 +503,8 @@ def contains(self, url):
501503
class DiscoveryFromFileCache(unittest.TestCase):
502504
def test_file_based_cache(self):
503505
cache = mock.Mock(wraps=DictCache())
504-
with mock.patch('googleapiclient.discovery_cache.file_cache.cache',
505-
new=cache):
506+
with mock.patch('googleapiclient.discovery_cache.autodetect',
507+
return_value=cache):
506508
self.http = HttpMock(datafile('plus.json'), {'status': '200'})
507509

508510
plus = build('plus', 'v1', http=self.http)

tests/test_discovery_cache.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@
2424

2525
from googleapiclient.discovery_cache import DISCOVERY_DOC_MAX_AGE
2626
from googleapiclient.discovery_cache.base import Cache
27-
from googleapiclient.discovery_cache.file_cache import Cache as FileCache
2827

28+
try:
29+
from googleapiclient.discovery_cache.file_cache import Cache as FileCache
30+
except ImportError:
31+
FileCache = None
2932

33+
34+
@unittest.skipIf(FileCache is None, 'FileCache unavailable.')
3035
class FileCacheTest(unittest.TestCase):
3136
@mock.patch('googleapiclient.discovery_cache.file_cache.FILENAME',
3237
new='google-api-python-client-discovery-doc-tests.cache')

tox.ini

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[tox]
2-
envlist = py{26,27,33,34}-oauth2client{1,2,3}
2+
envlist = py{26,27,33,34}-oauth2client{1,2,3,4}
33

44
[testenv]
55
deps =
6-
oauth2client1: oauth2client<2
7-
oauth2client2: oauth2client>=2,<=3
8-
oauth2client3: oauth2client>=3,<=4
6+
oauth2client1: oauth2client<2dev
7+
oauth2client2: oauth2client>=2,<=3dev
8+
oauth2client3: oauth2client>=3,<=4dev
9+
oauth2client4: oauth2client>=4,<=5dev
910
keyring
1011
mox
1112
pyopenssl

0 commit comments

Comments
 (0)