No longer adding in the 'data' wrapper object if it is missing, as some APIs don't use it.
This commit is contained in:
@@ -88,12 +88,8 @@ class JsonModel(object):
|
|||||||
if body_value is None:
|
if body_value is None:
|
||||||
return (headers, path_params, query, None)
|
return (headers, path_params, query, None)
|
||||||
else:
|
else:
|
||||||
if len(body_value) == 1 and 'data' in body_value:
|
|
||||||
model = body_value
|
|
||||||
else:
|
|
||||||
model = {'data': body_value}
|
|
||||||
headers['content-type'] = 'application/json'
|
headers['content-type'] = 'application/json'
|
||||||
return (headers, path_params, query, simplejson.dumps(model))
|
return (headers, path_params, query, simplejson.dumps(body_value))
|
||||||
|
|
||||||
def build_query(self, params):
|
def build_query(self, params):
|
||||||
params.update({'alt': 'json'})
|
params.update({'alt': 'json'})
|
||||||
|
|||||||
@@ -36,16 +36,19 @@ def main():
|
|||||||
print "Retrieved the first two activities"
|
print "Retrieved the first two activities"
|
||||||
|
|
||||||
# Retrieve the next two activities
|
# Retrieve the next two activities
|
||||||
|
if activitylist:
|
||||||
activitylist = activities.list_next(activitylist).execute()
|
activitylist = activities.list_next(activitylist).execute()
|
||||||
print "Retrieved the next two activities"
|
print "Retrieved the next two activities"
|
||||||
|
|
||||||
# Add a new activity
|
# Add a new activity
|
||||||
new_activity_body = {
|
new_activity_body = {
|
||||||
|
"data": {
|
||||||
'title': 'Testing insert',
|
'title': 'Testing insert',
|
||||||
'object': {
|
'object': {
|
||||||
'content': u'Just a short note to show that insert is working. ☄',
|
'content': u'Just a short note to show that insert is working. ☄',
|
||||||
'type': 'note'}
|
'type': 'note'}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
activity = activities.insert(userId='@me', body=new_activity_body).execute()
|
activity = activities.insert(userId='@me', body=new_activity_body).execute()
|
||||||
print "Added a new activity"
|
print "Added a new activity"
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,12 @@ def main():
|
|||||||
p = build("moderator", "v1", http=http)
|
p = build("moderator", "v1", http=http)
|
||||||
|
|
||||||
series_body = {
|
series_body = {
|
||||||
|
"data": {
|
||||||
"description": "Share and rank tips for eating healthily on the cheaps!",
|
"description": "Share and rank tips for eating healthily on the cheaps!",
|
||||||
"name": "Eating Healthy & Cheap",
|
"name": "Eating Healthy & Cheap",
|
||||||
"videoSubmissionAllowed": False
|
"videoSubmissionAllowed": False
|
||||||
}
|
}
|
||||||
|
}
|
||||||
series = p.series().insert(body=series_body).execute()
|
series = p.series().insert(body=series_body).execute()
|
||||||
print "Created a new series"
|
print "Created a new series"
|
||||||
|
|
||||||
|
|||||||
@@ -81,10 +81,12 @@ def main():
|
|||||||
p = build("moderator", "v1", http=http)
|
p = build("moderator", "v1", http=http)
|
||||||
|
|
||||||
series_body = {
|
series_body = {
|
||||||
|
"data": {
|
||||||
"description": "An example of bulk creating topics",
|
"description": "An example of bulk creating topics",
|
||||||
"name": "Using threading and queues",
|
"name": "Using threading and queues",
|
||||||
"videoSubmissionAllowed": False
|
"videoSubmissionAllowed": False
|
||||||
}
|
}
|
||||||
|
}
|
||||||
series = p.series().insert(body=series_body).execute()
|
series = p.series().insert(body=series_body).execute()
|
||||||
print "Created a new series"
|
print "Created a new series"
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class Model(unittest.TestCase):
|
|||||||
self.assertEqual(headers['accept'], 'application/json')
|
self.assertEqual(headers['accept'], 'application/json')
|
||||||
self.assertEqual(headers['content-type'], 'application/json')
|
self.assertEqual(headers['content-type'], 'application/json')
|
||||||
self.assertNotEqual(query, '')
|
self.assertNotEqual(query, '')
|
||||||
self.assertEqual(body, '{"data": {}}')
|
self.assertEqual(body, '{}')
|
||||||
|
|
||||||
def test_json_body_default_data(self):
|
def test_json_body_default_data(self):
|
||||||
"""Test that a 'data' wrapper doesn't get added if one is already present."""
|
"""Test that a 'data' wrapper doesn't get added if one is already present."""
|
||||||
@@ -96,7 +96,7 @@ class Model(unittest.TestCase):
|
|||||||
query_dict = parse_qs(query)
|
query_dict = parse_qs(query)
|
||||||
self.assertEqual(query_dict['foo'], ['1'])
|
self.assertEqual(query_dict['foo'], ['1'])
|
||||||
self.assertEqual(query_dict['bar'], [u'\N{COMET}'.encode('utf-8')])
|
self.assertEqual(query_dict['bar'], [u'\N{COMET}'.encode('utf-8')])
|
||||||
self.assertEqual(body, '{"data": {}}')
|
self.assertEqual(body, '{}')
|
||||||
|
|
||||||
def test_user_agent(self):
|
def test_user_agent(self):
|
||||||
model = JsonModel()
|
model = JsonModel()
|
||||||
|
|||||||
Reference in New Issue
Block a user