Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dee9cd5

Browse files
Merge pull request googleapis#114 from jonparrott/patch-1
Making http parameter in discovery.build_from_document optional.
2 parents ffe845f + a6e6fbd commit dee9cd5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

googleapiclient/discovery.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ def build_from_document(
254254
A Resource object with methods for interacting with the service.
255255
"""
256256

257+
if http is None:
258+
http = httplib2.Http()
259+
257260
# future is no longer used.
258261
future = {}
259262

tests/test_discovery.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,17 @@ def test_building_with_base_remembers_base(self):
366366
plus = build_from_document(discovery, base=base)
367367
self.assertEquals("https://www.googleapis.com/plus/v1/", plus._baseUrl)
368368

369+
def test_building_with_optional_http(self):
370+
discovery = open(datafile('plus.json')).read()
371+
plus = build_from_document(discovery, base="https://www.googleapis.com/")
372+
self.assertTrue(isinstance(plus._http, httplib2.Http))
373+
374+
def test_building_with_explicit_http(self):
375+
http = HttpMock()
376+
discovery = open(datafile('plus.json')).read()
377+
plus = build_from_document(
378+
discovery, base="https://www.googleapis.com/", http=http)
379+
self.assertEquals(plus._http, http)
369380

370381
class DiscoveryFromHttp(unittest.TestCase):
371382
def setUp(self):

0 commit comments

Comments
 (0)