Fix for a temporary problem with discovery documents. Now query vs path parameters are inferred from the restPath.
This commit is contained in:
@@ -35,6 +35,9 @@ except ImportError:
|
|||||||
from apiclient.http import HttpRequest
|
from apiclient.http import HttpRequest
|
||||||
from apiclient.json import simplejson
|
from apiclient.json import simplejson
|
||||||
|
|
||||||
|
URITEMPLATE = re.compile('{[^}]*}')
|
||||||
|
VARNAME = re.compile('[a-zA-Z0-9_-]+')
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
"""Base error for this module."""
|
"""Base error for this module."""
|
||||||
pass
|
pass
|
||||||
@@ -215,6 +218,13 @@ def createResource(http, baseUrl, model, resourceName, developerKey,
|
|||||||
if desc.get('restParameterType') == 'path':
|
if desc.get('restParameterType') == 'path':
|
||||||
path_params[param] = param
|
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):
|
def method(self, **kwargs):
|
||||||
for name in kwargs.iterkeys():
|
for name in kwargs.iterkeys():
|
||||||
if name not in argmap:
|
if name not in argmap:
|
||||||
|
|||||||
@@ -124,7 +124,8 @@ class BuzzFunctionalTest(unittest.TestCase):
|
|||||||
buzz = build('buzz', 'v1')
|
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.
|
# 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
|
# @googlebuzz has a large but fluctuating number of followers
|
||||||
# It is sufficient if the result is bigger than 10, 000
|
# 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)
|
buzz = build('buzz', 'v1', http=self.http)
|
||||||
|
|
||||||
activity = buzz.activities().insert(userId='@me', body={
|
activity = buzz.activities().insert(userId='@me', body={
|
||||||
'title': 'Testing insert',
|
'data': {
|
||||||
'object': {
|
'title': 'Testing insert',
|
||||||
'content': u'Just a short note to show that insert is working. ?',
|
'object': {
|
||||||
'type': 'note'}
|
'content': u'Just a short note to show that insert is working. ?',
|
||||||
}
|
'type': 'note'}
|
||||||
|
}
|
||||||
|
}
|
||||||
).execute()
|
).execute()
|
||||||
self.assertTrue(activity is not None)
|
self.assertTrue(activity is not None)
|
||||||
|
|
||||||
@@ -164,16 +167,18 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
|
|||||||
buzz = build('buzz', 'v1', http=self.http)
|
buzz = build('buzz', 'v1', http=self.http)
|
||||||
|
|
||||||
activity = buzz.activities().insert(userId='@me', body={
|
activity = buzz.activities().insert(userId='@me', body={
|
||||||
'title': 'Testing insert',
|
'data': {
|
||||||
'object': {
|
'title': 'Testing insert',
|
||||||
'content': 'This is a private post.'
|
'object': {
|
||||||
},
|
'content': 'This is a private post.'
|
||||||
'visibility': {
|
},
|
||||||
'entries': [
|
'visibility': {
|
||||||
{ 'id': 'tag:google.com,2010:buzz-group:108242092577082601423:13' }
|
'entries': [
|
||||||
]
|
{ 'id': 'tag:google.com,2010:buzz-group:108242092577082601423:13' }
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
).execute()
|
).execute()
|
||||||
self.assertTrue(activity is not None)
|
self.assertTrue(activity is not None)
|
||||||
|
|
||||||
@@ -201,11 +206,13 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
|
|||||||
def IGNORE__test_can_like_activity(self):
|
def IGNORE__test_can_like_activity(self):
|
||||||
buzz = build('buzz', 'v1', http=self.http)
|
buzz = build('buzz', 'v1', http=self.http)
|
||||||
activity = buzz.activities().insert(userId='@me', body={
|
activity = buzz.activities().insert(userId='@me', body={
|
||||||
'title': 'Testing insert',
|
'data': {
|
||||||
'object': {
|
'title': 'Testing insert',
|
||||||
'content': u'Just a short note to show that insert is working. ?',
|
'object': {
|
||||||
'type': 'note'}
|
'content': u'Just a short note to show that insert is working. ?',
|
||||||
}
|
'type': 'note'}
|
||||||
|
}
|
||||||
|
}
|
||||||
).execute()
|
).execute()
|
||||||
pprint.pprint(activity)
|
pprint.pprint(activity)
|
||||||
id = activity['id']
|
id = activity['id']
|
||||||
@@ -216,16 +223,20 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
|
|||||||
buzz = build('buzz', 'v1', http=self.http)
|
buzz = build('buzz', 'v1', http=self.http)
|
||||||
|
|
||||||
activity = buzz.activities().insert(userId='@me', body={
|
activity = buzz.activities().insert(userId='@me', body={
|
||||||
'title': 'A new activity',
|
'data': {
|
||||||
'object': {
|
'title': 'A new activity',
|
||||||
'content': u'The body of the new activity',
|
'object': {
|
||||||
'type': 'note'}
|
'content': u'The body of the new activity',
|
||||||
}
|
'type': 'note'}
|
||||||
|
}
|
||||||
|
}
|
||||||
).execute()
|
).execute()
|
||||||
|
|
||||||
id = activity['id']
|
id = activity['id']
|
||||||
comment = buzz.comments().insert(userId='@me', postId=id, body={
|
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()
|
}).execute()
|
||||||
|
|
||||||
def test_can_list_groups_belonging_to_user(self):
|
def test_can_list_groups_belonging_to_user(self):
|
||||||
@@ -248,11 +259,13 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
|
|||||||
buzz = build('buzz', 'v1', http=self.http)
|
buzz = build('buzz', 'v1', http=self.http)
|
||||||
|
|
||||||
activity = buzz.activities().insert(userId='@me', body={
|
activity = buzz.activities().insert(userId='@me', body={
|
||||||
'title': 'Activity to be deleted',
|
'data': {
|
||||||
'object': {
|
'title': 'Activity to be deleted',
|
||||||
'content': u'Created this activity so that it can be deleted.',
|
'object': {
|
||||||
'type': 'note'}
|
'content': u'Created this activity so that it can be deleted.',
|
||||||
}
|
'type': 'note'}
|
||||||
|
}
|
||||||
|
}
|
||||||
).execute()
|
).execute()
|
||||||
id = activity['id']
|
id = activity['id']
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import pickle
|
|||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
# Uncomment the next line to get very detailed logging
|
# Uncomment the next line to get very detailed logging
|
||||||
# httplib2.debuglevel = 4
|
#httplib2.debuglevel = 4
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
f = open("buzz.dat", "r")
|
f = open("buzz.dat", "r")
|
||||||
@@ -56,7 +56,9 @@ def main():
|
|||||||
|
|
||||||
# Add a comment to that activity
|
# Add a comment to that activity
|
||||||
comment_body = {
|
comment_body = {
|
||||||
|
"data": {
|
||||||
"content": "This is a comment"
|
"content": "This is a comment"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
item = activitylist['items'][0]
|
item = activitylist['items'][0]
|
||||||
comment = p.comments().insert(
|
comment = p.comments().insert(
|
||||||
|
|||||||
Reference in New Issue
Block a user