Added test of new model where 'data' wrapper isn't added if it isn't necessary. This will allow developers to cut and paste JSON from the developer docs into Python code and it should just work.

This commit is contained in:
Joe Gregorio
2010-10-11 13:14:43 -04:00
parent 4fb70ccd02
commit 8963ff928e
2 changed files with 19 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ import httplib2
import logging
import pickle
import os
import time
import unittest
# TODO(ade) Remove this mock once the bug in the discovery document is fixed
@@ -227,7 +228,7 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
def test_can_delete_activity(self):
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
'title': 'Activity to be deleted',
'object': {
@@ -238,6 +239,7 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
id = activity['id']
buzz.activities().delete(scope='@self', userId='@me', postId=id).execute()
time.sleep(2)
activity_url = activity['links']['self'][0]['href']
resp, content = self.http.request(activity_url, 'GET')

View File

@@ -65,6 +65,22 @@ class Model(unittest.TestCase):
self.assertNotEqual(query, '')
self.assertEqual(body, '{"data": {}}')
def test_json_body_default_data(self):
"""Test that a 'data' wrapper doesn't get added if one is already present."""
model = JsonModel()
headers = {}
path_params = {}
query_params = {}
body = {'data': 'foo'}
headers, params, query, body = model.request(headers, path_params, query_params, body)
self.assertEqual(headers['accept'], 'application/json')
self.assertEqual(headers['content-type'], 'application/json')
self.assertNotEqual(query, '')
self.assertEqual(body, '{"data": "foo"}')
def test_json_build_query(self):
model = JsonModel()