Allow deserialized discovery docs to be passed to build_from_document().

Reviewed in https://codereview.appspot.com/6906052/.
This commit is contained in:
Joe Gregorio
2012-12-10 10:22:37 -05:00
parent 504a17fa87
commit 4772f3df36
2 changed files with 13 additions and 2 deletions

View File

@@ -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)

View File

@@ -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()