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 1919try :
2020 import google .auth
2121 import google .auth .credentials
22- import google_auth_httplib2
2322 HAS_GOOGLE_AUTH = True
2423except ImportError : # pragma: NO COVER
2524 HAS_GOOGLE_AUTH = False
2625
26+ try :
27+ import google_auth_httplib2
28+ except ImportError : # pragma: NO COVER
29+ google_auth_httplib2 = None
30+
2731try :
2832 import oauth2client
2933 import oauth2client .client
@@ -88,6 +92,12 @@ def authorized_http(credentials):
8892
8993 if HAS_GOOGLE_AUTH and isinstance (
9094 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.' )
91101 return google_auth_httplib2 .AuthorizedHttp (credentials ,
92102 http = build_http ())
93103 else :
Original file line number Diff line number Diff line change @@ -68,7 +68,9 @@ def test_authorized_http(self):
6868
6969 authorized_http = _auth .authorized_http (credentials )
7070
71- self .assertIsInstance (authorized_http , google_auth_httplib2 .AuthorizedHttp )
71+ self .assertIsInstance (
72+ authorized_http ,
73+ google_auth_httplib2 .AuthorizedHttp )
7274 self .assertEqual (authorized_http .credentials , credentials )
7375 self .assertIsInstance (authorized_http .http , httplib2 .Http )
7476 self .assertIsInstance (authorized_http .http .timeout , int )
@@ -138,3 +140,16 @@ def tearDown(self):
138140 def test_default_credentials (self ):
139141 with self .assertRaises (EnvironmentError ):
140142 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