blob: 7665d4b95ff881fecb0b4f234614fc275899f09d [file] [log] [blame]
ade@google.com46179d32010-08-21 00:00:03 +01001#!/usr/bin/python2.4
2#
3# Copyright 2010 Google Inc. All Rights Reserved.
4
5"""Discovery document tests
6
7Functional tests that verify we can retrieve data from existing services.
8
9These tests are read-only in order to ensure they're repeatable. They also
10only work with publicly visible data in order to avoid dealing with OAuth.
11"""
ade@google.com2ab0de72010-09-27 23:26:54 +010012import httplib2
ade@google.com46179d32010-08-21 00:00:03 +010013
14__author__ = 'ade@google.com (Ade Oshineye)'
15
16from apiclient.discovery import build
ade@google.com2ab0de72010-09-27 23:26:54 +010017import httplib2
ade@google.com46179d32010-08-21 00:00:03 +010018import logging
ade@google.com2ab0de72010-09-27 23:26:54 +010019import os
ade@google.com46179d32010-08-21 00:00:03 +010020import unittest
21
ade@google.com2ab0de72010-09-27 23:26:54 +010022# TODO(ade) Remove this mock once the bug in the discovery document is fixed
23DATA_DIR = os.path.join(logging.os.path.dirname(__file__), '../tests/data')
24class HttpMock(object):
25
26 def __init__(self, filename, headers):
27 f = file(os.path.join(DATA_DIR, filename), 'r')
28 self.data = f.read()
29 f.close()
30 self.headers = headers
31
32 def request(self, uri, method="GET", body=None, headers=None, redirections=1, connection_type=None):
33 return httplib2.Response(self.headers), self.data
34
ade@google.com46179d32010-08-21 00:00:03 +010035class BuzzFunctionalTest(unittest.TestCase):
36 def test_can_get_buzz_activities_with_many_params(self):
37 buzz = build('buzz', 'v1')
38 max_results = 2
Joe Gregorioc5c5a372010-09-22 11:42:32 -040039 actcol = buzz.activities()
40 activities = actcol.list(userId='googlebuzz', scope='@self',
41 max_comments=max_results*2 ,max_liked=max_results*3,
Joe Gregoriodb849af2010-09-22 16:53:59 -040042 max_results=max_results).execute()
43 activity_count = len(activities['items'])
ade@google.com46179d32010-08-21 00:00:03 +010044 self.assertEquals(max_results, activity_count)
Joe Gregorioc5c5a372010-09-22 11:42:32 -040045
Joe Gregoriodb849af2010-09-22 16:53:59 -040046 activities = actcol.list_next(activities).execute()
47 activity_count = len(activities['items'])
48 self.assertEquals(max_results, activity_count)
49
ade@google.com2ab0de72010-09-27 23:26:54 +010050 def test_can_get_multiple_pages_of_buzz_activities(self):
ade@google.com973d1a62010-09-23 21:21:21 +010051 buzz = build('buzz', 'v1')
52 max_results = 2
53 actcol = buzz.activities()
54
55 activities = actcol.list(userId='adewale', scope='@self',
56 max_results=max_results).execute()
57 for count in range(10):
58 activities = actcol.list_next(activities).execute()
59 activity_count = len(activities['items'])
60 self.assertEquals(max_results, activity_count, 'Failed after %s pages' % str(count))
61
ade@google.com2ab0de72010-09-27 23:26:54 +010062 def IGNORE__test_can_get_multiple_pages_of_buzz_likers(self):
63 # Ignore this test until the Buzz API fixes the bug with next links
64 # http://code.google.com/p/google-buzz-api/issues/detail?id=114
65 self.http = HttpMock('buzz.json', {'status': '200'})
66 buzz = build('buzz', 'v1', self.http)
67 max_results = 1
68 people_cmd = buzz.people()
69 #https://www.googleapis.com/buzz/v1/activities/111062888259659218284/@self/B:z13nh535yk2syfob004cdjyb3mjeulcwv3c?alt=json#
70 people = people_cmd.liked(groupId='@liked', userId='googlebuzz', scope='@self',
71 postId='B:z13nh535yk2syfob004cdjyb3mjeulcwv3c', max_results=max_results).execute()
72
73 for count in range(10):
74 people = people_cmd.liked_next(people).execute()
75 people_count = len(people['items'])
76 self.assertEquals(max_results, people_count, 'Failed after %s pages' % str(count))
77
ade@google.comd6d6f2f2010-09-28 07:37:25 +010078 def test_can_get_user_profile(self):
79 buzz = build('buzz', 'v1')
80 person = buzz.people().get(userId='googlebuzz').execute()
81
82 self.assertTrue(person is not None)
83 self.assertEquals('buzz#person', person['kind'])
84 self.assertEquals('Google Buzz Team', person['displayName'])
85 self.assertEquals('111062888259659218284', person['id'])
86 self.assertEquals('http://www.google.com/profiles/googlebuzz', person['profileUrl'])
87
ade@google.com75fdddd2010-09-29 16:44:00 +010088
89class BuzzAuthenticatedFunctionalTest(unittest.TestCase):
90 def IGNORE__test_can_list_groups_belonging_to_user(self):
91 buzz = build('buzz', 'v1')
92 groups = buzz.groups().list(userId='googlebuzz').execute()
93
94 self.assertTrue(len(groups) > 1)
95
96 def IGNORE__test_can_get_followees_of_user(self):
97 buzz = build('buzz', 'v1')
98 following = buzz.groups().get(userId='googlebuzz', groupId='@following').execute()
99
100 self.assertEquals(17, len(following))
101
Joe Gregoriodb849af2010-09-22 16:53:59 -0400102if __name__ == '__main__':
103 unittest.main()