File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 19
19
try :
20
20
import google .auth
21
21
import google .auth .credentials
22
- import google_auth_httplib2
23
22
HAS_GOOGLE_AUTH = True
24
23
except ImportError : # pragma: NO COVER
25
24
HAS_GOOGLE_AUTH = False
26
25
26
+ try :
27
+ import google_auth_httplib2
28
+ except ImportError : # pragma: NO COVER
29
+ google_auth_httplib2 = None
30
+
27
31
try :
28
32
import oauth2client
29
33
import oauth2client .client
@@ -88,6 +92,12 @@ def authorized_http(credentials):
88
92
89
93
if HAS_GOOGLE_AUTH and isinstance (
90
94
credentials , google .auth .credentials .Credentials ):
95
+ if google_auth_httplib2 is None :
96
+ raise ValueError (
97
+ 'Credentials from google.auth specified, but '
98
+ 'google-api-python-client is unable to use these credentials '
99
+ 'unless google-auth-httplib2 is installed. Please install '
100
+ 'google-auth-httplib2.' )
91
101
return google_auth_httplib2 .AuthorizedHttp (credentials ,
92
102
http = build_http ())
93
103
else :
Original file line number Diff line number Diff line change @@ -68,7 +68,9 @@ def test_authorized_http(self):
68
68
69
69
authorized_http = _auth .authorized_http (credentials )
70
70
71
- self .assertIsInstance (authorized_http , google_auth_httplib2 .AuthorizedHttp )
71
+ self .assertIsInstance (
72
+ authorized_http ,
73
+ google_auth_httplib2 .AuthorizedHttp )
72
74
self .assertEqual (authorized_http .credentials , credentials )
73
75
self .assertIsInstance (authorized_http .http , httplib2 .Http )
74
76
self .assertIsInstance (authorized_http .http .timeout , int )
@@ -138,3 +140,16 @@ def tearDown(self):
138
140
def test_default_credentials (self ):
139
141
with self .assertRaises (EnvironmentError ):
140
142
print (_auth .default_credentials ())
143
+
144
+
145
+ class TestGoogleAuthWithoutHttplib2 (unittest2 .TestCase ):
146
+ def setUp (self ):
147
+ _auth .google_auth_httplib2 = None
148
+
149
+ def tearDown (self ):
150
+ _auth .google_auth_httplib2 = google_auth_httplib2
151
+
152
+ def test_default_credentials (self ):
153
+ credentials = mock .Mock (spec = google .auth .credentials .Credentials )
154
+ with self .assertRaises (ValueError ):
155
+ _auth .authorized_http (credentials )
You can’t perform that action at this time.
0 commit comments