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: | ||||
|       return (headers, path_params, query, None) | ||||
|     else: | ||||
|       if len(body_value) == 1 and 'data' in body_value: | ||||
|         model = body_value | ||||
|       else: | ||||
|         model = {'data': body_value} | ||||
|       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): | ||||
|     params.update({'alt': 'json'}) | ||||
|   | ||||
| @@ -36,15 +36,18 @@ def main(): | ||||
|   print "Retrieved the first two activities" | ||||
|  | ||||
|   # Retrieve the next two activities | ||||
|   activitylist = activities.list_next(activitylist).execute() | ||||
|   print "Retrieved the next two activities" | ||||
|   if activitylist: | ||||
|     activitylist = activities.list_next(activitylist).execute() | ||||
|     print "Retrieved the next two activities" | ||||
|  | ||||
|   # Add a new activity | ||||
|   new_activity_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'} | ||||
|           } | ||||
|       } | ||||
|   activity = activities.insert(userId='@me', body=new_activity_body).execute() | ||||
|   print "Added a new activity" | ||||
|   | ||||
| @@ -31,9 +31,11 @@ def main(): | ||||
|   p = build("moderator", "v1", http=http) | ||||
|  | ||||
|   series_body = { | ||||
|       "data": { | ||||
|         "description": "Share and rank tips for eating healthily on the cheaps!", | ||||
|         "name": "Eating Healthy & Cheap", | ||||
|         "videoSubmissionAllowed": False | ||||
|         } | ||||
|       } | ||||
|   series = p.series().insert(body=series_body).execute() | ||||
|   print "Created a new series" | ||||
|   | ||||
| @@ -81,9 +81,11 @@ def main(): | ||||
|   p = build("moderator", "v1", http=http) | ||||
|  | ||||
|   series_body = { | ||||
|         "description": "An example of bulk creating topics", | ||||
|         "name": "Using threading and queues", | ||||
|         "videoSubmissionAllowed": False | ||||
|       "data": { | ||||
|           "description": "An example of bulk creating topics", | ||||
|           "name": "Using threading and queues", | ||||
|           "videoSubmissionAllowed": False | ||||
|           } | ||||
|       } | ||||
|   series = p.series().insert(body=series_body).execute() | ||||
|   print "Created a new series" | ||||
|   | ||||
| @@ -62,7 +62,7 @@ class Model(unittest.TestCase): | ||||
|     self.assertEqual(headers['accept'], 'application/json') | ||||
|     self.assertEqual(headers['content-type'], 'application/json') | ||||
|     self.assertNotEqual(query, '') | ||||
|     self.assertEqual(body, '{"data": {}}') | ||||
|     self.assertEqual(body, '{}') | ||||
|  | ||||
|   def test_json_body_default_data(self): | ||||
|     """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) | ||||
|     self.assertEqual(query_dict['foo'], ['1']) | ||||
|     self.assertEqual(query_dict['bar'], [u'\N{COMET}'.encode('utf-8')]) | ||||
|     self.assertEqual(body, '{"data": {}}') | ||||
|     self.assertEqual(body, '{}') | ||||
|  | ||||
|   def test_user_agent(self): | ||||
|     model = JsonModel() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Joe Gregorio
					Joe Gregorio