Added support buzz.people.liked. Marked the functional test as IGNORED since it requires a bug fix in the Buzz API

This commit is contained in:
ade@google.com
2010-09-27 23:26:54 +01:00
parent cfc39d1f74
commit 2ab0de7000
5 changed files with 55 additions and 4 deletions

View File

@@ -112,7 +112,12 @@
"methods": { "methods": {
"delete": {}, "delete": {},
"get": {}, "get": {},
"liked": {}, "liked": {
"next": {
"type": "uri",
"location": ["links", "next", 0, "href"]
}
},
"list": {}, "list": {},
"relatedToUri": {}, "relatedToUri": {},
"reshared": {}, "reshared": {},

View File

@@ -36,6 +36,7 @@ REQUEST_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetRequestToken?domain
AUTHORIZE_URL = 'https://www.google.com/buzz/api/auth/OAuthAuthorizeToken?domain=anonymous&scope=https://www.googleapis.com/auth/buzz' AUTHORIZE_URL = 'https://www.google.com/buzz/api/auth/OAuthAuthorizeToken?domain=anonymous&scope=https://www.googleapis.com/auth/buzz'
ACCESS_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetAccessToken' ACCESS_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetAccessToken'
# TODO(ade) This class is really a BuzzGaeBuilder. Rename it.
class BuzzGaeClient(object): class BuzzGaeClient(object):
def __init__(self, consumer_key='anonymous', consumer_secret='anonymous'): def __init__(self, consumer_key='anonymous', consumer_secret='anonymous'):
self.consumer = oauth.Consumer(consumer_key, consumer_secret) self.consumer = oauth.Consumer(consumer_key, consumer_secret)

View File

@@ -9,13 +9,29 @@ Functional tests that verify we can retrieve data from existing services.
These tests are read-only in order to ensure they're repeatable. They also These tests are read-only in order to ensure they're repeatable. They also
only work with publicly visible data in order to avoid dealing with OAuth. only work with publicly visible data in order to avoid dealing with OAuth.
""" """
import httplib2
__author__ = 'ade@google.com (Ade Oshineye)' __author__ = 'ade@google.com (Ade Oshineye)'
from apiclient.discovery import build from apiclient.discovery import build
import httplib2
import logging import logging
import os
import unittest import unittest
# TODO(ade) Remove this mock once the bug in the discovery document is fixed
DATA_DIR = os.path.join(logging.os.path.dirname(__file__), '../tests/data')
class HttpMock(object):
def __init__(self, filename, headers):
f = file(os.path.join(DATA_DIR, filename), 'r')
self.data = f.read()
f.close()
self.headers = headers
def request(self, uri, method="GET", body=None, headers=None, redirections=1, connection_type=None):
return httplib2.Response(self.headers), self.data
class BuzzFunctionalTest(unittest.TestCase): class BuzzFunctionalTest(unittest.TestCase):
def test_can_get_buzz_activities_with_many_params(self): def test_can_get_buzz_activities_with_many_params(self):
buzz = build('buzz', 'v1') buzz = build('buzz', 'v1')
@@ -31,7 +47,7 @@ class BuzzFunctionalTest(unittest.TestCase):
activity_count = len(activities['items']) activity_count = len(activities['items'])
self.assertEquals(max_results, activity_count) self.assertEquals(max_results, activity_count)
def test_can_page_through_users_activities(self): def test_can_get_multiple_pages_of_buzz_activities(self):
buzz = build('buzz', 'v1') buzz = build('buzz', 'v1')
max_results = 2 max_results = 2
actcol = buzz.activities() actcol = buzz.activities()
@@ -43,5 +59,21 @@ class BuzzFunctionalTest(unittest.TestCase):
activity_count = len(activities['items']) activity_count = len(activities['items'])
self.assertEquals(max_results, activity_count, 'Failed after %s pages' % str(count)) self.assertEquals(max_results, activity_count, 'Failed after %s pages' % str(count))
def IGNORE__test_can_get_multiple_pages_of_buzz_likers(self):
# Ignore this test until the Buzz API fixes the bug with next links
# http://code.google.com/p/google-buzz-api/issues/detail?id=114
self.http = HttpMock('buzz.json', {'status': '200'})
buzz = build('buzz', 'v1', self.http)
max_results = 1
people_cmd = buzz.people()
#https://www.googleapis.com/buzz/v1/activities/111062888259659218284/@self/B:z13nh535yk2syfob004cdjyb3mjeulcwv3c?alt=json#
people = people_cmd.liked(groupId='@liked', userId='googlebuzz', scope='@self',
postId='B:z13nh535yk2syfob004cdjyb3mjeulcwv3c', max_results=max_results).execute()
for count in range(10):
people = people_cmd.liked_next(people).execute()
people_count = len(people['items'])
self.assertEquals(max_results, people_count, 'Failed after %s pages' % str(count))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@@ -621,7 +621,7 @@
"liked": { "liked": {
"pathUrl": "buzz/v1/activities/{userId}/{scope}/{postId}/{groupId}", "pathUrl": "buzz/v1/activities/{userId}/{scope}/{postId}/{groupId}",
"rpcName": "buzz.people.liked", "rpcName": "buzz.people.liked",
"httpMethod": "POST", "httpMethod": "GET",
"methodType": "rest", "methodType": "rest",
"parameters": { "parameters": {
"groupId": { "groupId": {
@@ -646,6 +646,11 @@
"pattern": "[^/]+", "pattern": "[^/]+",
"required": true "required": true
}, },
"scope": {
"parameterType": "path",
"pattern": "@.*",
"required": true
},
"postId": { "postId": {
"parameterType": "path", "parameterType": "path",
"pattern": ".*", "pattern": ".*",

View File

@@ -100,7 +100,7 @@ class Discovery(unittest.TestCase):
class Next(unittest.TestCase): class Next(unittest.TestCase):
def test_next(self): def test_next_for_activities_list(self):
self.http = HttpMock('buzz.json', {'status': '200'}) self.http = HttpMock('buzz.json', {'status': '200'})
buzz = build('buzz', 'v1', self.http) buzz = build('buzz', 'v1', self.http)
activities = {'links': activities = {'links':
@@ -109,6 +109,14 @@ class Next(unittest.TestCase):
request = buzz.activities().list_next(activities) request = buzz.activities().list_next(activities)
self.assertEqual(request.uri, 'http://www.googleapis.com/next-link') self.assertEqual(request.uri, 'http://www.googleapis.com/next-link')
def test_next_for_people_liked(self):
self.http = HttpMock('buzz.json', {'status': '200'})
buzz = build('buzz', 'v1', self.http)
people = {'links':
{'next':
[{'href': 'http://www.googleapis.com/next-link'}]}}
request = buzz.people().liked_next(people)
self.assertEqual(request.uri, 'http://www.googleapis.com/next-link')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()