Fix for a temporary problem with discovery documents. Now query vs path parameters are inferred from the restPath.

This commit is contained in:
Joe Gregorio
2010-11-08 09:20:48 -05:00
parent 913e70d225
commit bc2ff9bc4e
3 changed files with 58 additions and 33 deletions

View File

@@ -35,6 +35,9 @@ except ImportError:
from apiclient.http import HttpRequest
from apiclient.json import simplejson
URITEMPLATE = re.compile('{[^}]*}')
VARNAME = re.compile('[a-zA-Z0-9_-]+')
class Error(Exception):
"""Base error for this module."""
pass
@@ -215,6 +218,13 @@ def createResource(http, baseUrl, model, resourceName, developerKey,
if desc.get('restParameterType') == 'path':
path_params[param] = param
for match in URITEMPLATE.finditer(pathUrl):
for namematch in VARNAME.finditer(match.group(0)):
name = key2param(namematch.group(0))
path_params[name] = name
if name in query_params:
query_params.remove(name)
def method(self, **kwargs):
for name in kwargs.iterkeys():
if name not in argmap:

View File

@@ -124,7 +124,8 @@ class BuzzFunctionalTest(unittest.TestCase):
buzz = build('buzz', 'v1')
# Restricting max_results to 1 means only a tiny amount of data comes back but the totalResults still has the total.
following = buzz.people().list(userId='googlebuzz', groupId='@followers', max_results=1).execute()
following = buzz.people().list(userId='googlebuzz', groupId='@followers',
max_results='1').execute()
# @googlebuzz has a large but fluctuating number of followers
# It is sufficient if the result is bigger than 10, 000
@@ -152,11 +153,13 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
'title': 'Testing insert',
'object': {
'content': u'Just a short note to show that insert is working. ?',
'type': 'note'}
}
'data': {
'title': 'Testing insert',
'object': {
'content': u'Just a short note to show that insert is working. ?',
'type': 'note'}
}
}
).execute()
self.assertTrue(activity is not None)
@@ -164,16 +167,18 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
'title': 'Testing insert',
'object': {
'content': 'This is a private post.'
},
'visibility': {
'entries': [
{ 'id': 'tag:google.com,2010:buzz-group:108242092577082601423:13' }
]
}
}
'data': {
'title': 'Testing insert',
'object': {
'content': 'This is a private post.'
},
'visibility': {
'entries': [
{ 'id': 'tag:google.com,2010:buzz-group:108242092577082601423:13' }
]
}
}
}
).execute()
self.assertTrue(activity is not None)
@@ -201,11 +206,13 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
def IGNORE__test_can_like_activity(self):
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
'title': 'Testing insert',
'object': {
'content': u'Just a short note to show that insert is working. ?',
'type': 'note'}
}
'data': {
'title': 'Testing insert',
'object': {
'content': u'Just a short note to show that insert is working. ?',
'type': 'note'}
}
}
).execute()
pprint.pprint(activity)
id = activity['id']
@@ -216,16 +223,20 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
'title': 'A new activity',
'object': {
'content': u'The body of the new activity',
'type': 'note'}
}
'data': {
'title': 'A new activity',
'object': {
'content': u'The body of the new activity',
'type': 'note'}
}
}
).execute()
id = activity['id']
comment = buzz.comments().insert(userId='@me', postId=id, body={
"content": "A comment on the new activity"
'data': {
'content': 'A comment on the new activity'
}
}).execute()
def test_can_list_groups_belonging_to_user(self):
@@ -248,11 +259,13 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
'title': 'Activity to be deleted',
'object': {
'content': u'Created this activity so that it can be deleted.',
'type': 'note'}
}
'data': {
'title': 'Activity to be deleted',
'object': {
'content': u'Created this activity so that it can be deleted.',
'type': 'note'}
}
}
).execute()
id = activity['id']

View File

@@ -18,7 +18,7 @@ import pickle
import pprint
# Uncomment the next line to get very detailed logging
# httplib2.debuglevel = 4
#httplib2.debuglevel = 4
def main():
f = open("buzz.dat", "r")
@@ -56,7 +56,9 @@ def main():
# Add a comment to that activity
comment_body = {
"data": {
"content": "This is a comment"
}
}
item = activitylist['items'][0]
comment = p.comments().insert(