From 9d821b0559add4f90ec0ad5c08e4bf219b14bf29 Mon Sep 17 00:00:00 2001 From: "ade@google.com" Date: Mon, 11 Oct 2010 03:33:51 -0700 Subject: [PATCH] Added support for requests that return an HTTP 204: No Content. Added tests for creating a private activity and for deleting activities. --- apiclient/discovery.py | 3 +++ functional_tests/test_services.py | 34 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/apiclient/discovery.py b/apiclient/discovery.py index db17cea..945db74 100644 --- a/apiclient/discovery.py +++ b/apiclient/discovery.py @@ -114,6 +114,9 @@ class JsonModel(object): # Error handling is TBD, for example, do we retry # for some operation/error combinations? if resp.status < 300: + if resp.status == 204: + # A 204: No Content response should be treated differently to all the other success states + return simplejson.loads('{}') return simplejson.loads(content)['data'] else: logging.debug('Content from bad request was: %s' % content) diff --git a/functional_tests/test_services.py b/functional_tests/test_services.py index 99efe35..50a1a4d 100644 --- a/functional_tests/test_services.py +++ b/functional_tests/test_services.py @@ -149,6 +149,23 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase): ).execute() self.assertTrue(activity is not None) + def test_can_create_private_activity(self): + buzz = build('buzz', 'v1', http=self.http) + + activity = buzz.activities().insert(userId='@me', body={ + 'title': 'Testing insert', + 'object': { + 'content': 'This is a private post.' + }, + 'visibility': { + 'entries': [ + { 'id': 'tag:google.com,2010:buzz-group:108242092577082601423:13' } + ] + } + } + ).execute() + self.assertTrue(activity is not None) + def test_can_identify_number_of_groups_belonging_to_user(self): buzz = build('buzz', 'v1', http=self.http) groups = buzz.groups().list(userId='108242092577082601423').execute() @@ -208,6 +225,23 @@ class BuzzAuthenticatedFunctionalTest(unittest.TestCase): group = buzz.groups().get(userId='108242092577082601423', groupId='G:108242092577082601423:9999999').execute() self.assertEquals(None, group, group) + 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': { + 'content': u'Created this activity so that it can be deleted.', + 'type': 'note'} + } + ).execute() + id = activity['id'] + + buzz.activities().delete(scope='@self', userId='@me', postId=id).execute() + + activity_url = activity['links']['self'][0]['href'] + resp, content = self.http.request(activity_url, 'GET') + self.assertEquals(404, resp.status) if __name__ == '__main__': unittest.main()