Allow deserialized discovery docs to be passed to build_from_document().
Reviewed in https://codereview.appspot.com/6906052/.
This commit is contained in:
@@ -225,7 +225,9 @@ def build_from_document(
|
||||
document that is it given, as opposed to retrieving one over HTTP.
|
||||
|
||||
Args:
|
||||
service: string, discovery document.
|
||||
service: string or object, the JSON discovery document describing the API.
|
||||
The value passed in may either be the JSON string or the deserialized
|
||||
JSON.
|
||||
base: string, base URI for all HTTP requests, usually the discovery URI.
|
||||
This parameter is no longer used as rootUrl and servicePath are included
|
||||
within the discovery document. (deprecated)
|
||||
@@ -245,7 +247,8 @@ def build_from_document(
|
||||
# future is no longer used.
|
||||
future = {}
|
||||
|
||||
service = simplejson.loads(service)
|
||||
if isinstance(service, basestring):
|
||||
service = simplejson.loads(service)
|
||||
base = urlparse.urljoin(service['rootUrl'], service['servicePath'])
|
||||
schema = Schemas(service)
|
||||
|
||||
|
||||
@@ -125,6 +125,14 @@ class DiscoveryFromDocument(unittest.TestCase):
|
||||
discovery = file(datafile('plus.json')).read()
|
||||
plus = build_from_document(discovery, base="https://www.googleapis.com/")
|
||||
self.assertTrue(plus is not None)
|
||||
self.assertTrue(hasattr(plus, 'activities'))
|
||||
|
||||
def test_can_build_from_local_deserialized_document(self):
|
||||
discovery = file(datafile('plus.json')).read()
|
||||
discovery = simplejson.loads(discovery)
|
||||
plus = build_from_document(discovery, base="https://www.googleapis.com/")
|
||||
self.assertTrue(plus is not None)
|
||||
self.assertTrue(hasattr(plus, 'activities'))
|
||||
|
||||
def test_building_with_base_remembers_base(self):
|
||||
discovery = file(datafile('plus.json')).read()
|
||||
|
||||
Reference in New Issue
Block a user