|
65 | 65 | from googleapiclient.errors import UnacceptableMimeTypeError |
66 | 66 | from googleapiclient.errors import UnknownApiNameOrVersion |
67 | 67 | from googleapiclient.errors import UnknownFileType |
| 68 | +from googleapiclient.http import build_http |
68 | 69 | from googleapiclient.http import BatchHttpRequest |
69 | 70 | from googleapiclient.http import HttpMock |
70 | 71 | from googleapiclient.http import HttpMockSequence |
@@ -402,13 +403,32 @@ def test_building_with_base_remembers_base(self): |
402 | 403 | discovery, base=base, credentials=self.MOCK_CREDENTIALS) |
403 | 404 | self.assertEquals("https://www.googleapis.com/plus/v1/", plus._baseUrl) |
404 | 405 |
|
405 | | - def test_building_with_optional_http(self): |
| 406 | + def test_building_with_optional_http_with_authorization(self): |
406 | 407 | discovery = open(datafile('plus.json')).read() |
407 | 408 | plus = build_from_document( |
408 | 409 | discovery, base="https://www.googleapis.com/", |
409 | 410 | credentials=self.MOCK_CREDENTIALS) |
410 | | - self.assertIsInstance( |
411 | | - plus._http, (httplib2.Http, google_auth_httplib2.AuthorizedHttp)) |
| 411 | + |
| 412 | + # plus service requires Authorization, hence we expect to see AuthorizedHttp object here |
| 413 | + self.assertIsInstance(plus._http, google_auth_httplib2.AuthorizedHttp) |
| 414 | + self.assertIsInstance(plus._http.http, httplib2.Http) |
| 415 | + self.assertIsInstance(plus._http.http.timeout, int) |
| 416 | + self.assertGreater(plus._http.http.timeout, 0) |
| 417 | + |
| 418 | + def test_building_with_optional_http_with_no_authorization(self): |
| 419 | + discovery = open(datafile('plus.json')).read() |
| 420 | + # Cleanup auth field, so we would use plain http client |
| 421 | + discovery = json.loads(discovery) |
| 422 | + discovery['auth'] = {} |
| 423 | + discovery = json.dumps(discovery) |
| 424 | + |
| 425 | + plus = build_from_document( |
| 426 | + discovery, base="https://www.googleapis.com/", |
| 427 | + credentials=self.MOCK_CREDENTIALS) |
| 428 | + # plus service requires Authorization |
| 429 | + self.assertIsInstance(plus._http, httplib2.Http) |
| 430 | + self.assertIsInstance(plus._http.timeout, int) |
| 431 | + self.assertGreater(plus._http.timeout, 0) |
412 | 432 |
|
413 | 433 | def test_building_with_explicit_http(self): |
414 | 434 | http = HttpMock() |
@@ -1316,7 +1336,7 @@ def _dummy_zoo_request(self): |
1316 | 1336 | zoo_uri = util._add_query_parameter(zoo_uri, 'userIp', |
1317 | 1337 | os.environ['REMOTE_ADDR']) |
1318 | 1338 |
|
1319 | | - http = httplib2.Http() |
| 1339 | + http = build_http() |
1320 | 1340 | original_request = http.request |
1321 | 1341 | def wrapped_request(uri, method='GET', *args, **kwargs): |
1322 | 1342 | if uri == zoo_uri: |
|
0 commit comments