From 8963ff928e88574db863b63d4ad6f0e2b13608d2 Mon Sep 17 00:00:00 2001 From: Joe Gregorio Date: Mon, 11 Oct 2010 13:14:43 -0400 Subject: [PATCH] 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. --- functional_tests/test_services.py | 4 +++- tests/test_json_model.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/functional_tests/test_services.py b/functional_tests/test_services.py index 50a1a4d..a849577 100644 --- a/functional_tests/test_services.py +++ b/functional_tests/test_services.py @@ -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') diff --git a/tests/test_json_model.py b/tests/test_json_model.py index 79b63ab..01015f1 100644 --- a/tests/test_json_model.py +++ b/tests/test_json_model.py @@ -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()