ade@google.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 1 | #!/usr/bin/python2.4 |
| 2 | # |
| 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | """Discovery document tests |
| 6 | |
| 7 | Functional tests that verify we can retrieve data from existing services. |
| 8 | |
| 9 | These tests are read-only in order to ensure they're repeatable. They also |
| 10 | only work with publicly visible data in order to avoid dealing with OAuth. |
| 11 | """ |
ade@google.com | 2ab0de7 | 2010-09-27 23:26:54 +0100 | [diff] [blame] | 12 | import httplib2 |
ade@google.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 13 | |
| 14 | __author__ = 'ade@google.com (Ade Oshineye)' |
| 15 | |
| 16 | from apiclient.discovery import build |
ade@google.com | 2ab0de7 | 2010-09-27 23:26:54 +0100 | [diff] [blame] | 17 | import httplib2 |
ade@google.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 18 | import logging |
ade@google.com | 2ab0de7 | 2010-09-27 23:26:54 +0100 | [diff] [blame] | 19 | import os |
ade@google.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 20 | import unittest |
| 21 | |
ade@google.com | 2ab0de7 | 2010-09-27 23:26:54 +0100 | [diff] [blame] | 22 | # TODO(ade) Remove this mock once the bug in the discovery document is fixed |
| 23 | DATA_DIR = os.path.join(logging.os.path.dirname(__file__), '../tests/data') |
| 24 | class 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.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 35 | class BuzzFunctionalTest(unittest.TestCase): |
| 36 | def test_can_get_buzz_activities_with_many_params(self): |
| 37 | buzz = build('buzz', 'v1') |
| 38 | max_results = 2 |
Joe Gregorio | c5c5a37 | 2010-09-22 11:42:32 -0400 | [diff] [blame] | 39 | actcol = buzz.activities() |
| 40 | activities = actcol.list(userId='googlebuzz', scope='@self', |
| 41 | max_comments=max_results*2 ,max_liked=max_results*3, |
Joe Gregorio | db849af | 2010-09-22 16:53:59 -0400 | [diff] [blame] | 42 | max_results=max_results).execute() |
| 43 | activity_count = len(activities['items']) |
ade@google.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 44 | self.assertEquals(max_results, activity_count) |
Joe Gregorio | c5c5a37 | 2010-09-22 11:42:32 -0400 | [diff] [blame] | 45 | |
Joe Gregorio | db849af | 2010-09-22 16:53:59 -0400 | [diff] [blame] | 46 | activities = actcol.list_next(activities).execute() |
| 47 | activity_count = len(activities['items']) |
| 48 | self.assertEquals(max_results, activity_count) |
| 49 | |
ade@google.com | 2ab0de7 | 2010-09-27 23:26:54 +0100 | [diff] [blame] | 50 | def test_can_get_multiple_pages_of_buzz_activities(self): |
ade@google.com | 973d1a6 | 2010-09-23 21:21:21 +0100 | [diff] [blame] | 51 | 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.com | 2ab0de7 | 2010-09-27 23:26:54 +0100 | [diff] [blame] | 62 | 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.com | d6d6f2f | 2010-09-28 07:37:25 +0100 | [diff] [blame] | 78 | 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.com | 75fdddd | 2010-09-29 16:44:00 +0100 | [diff] [blame^] | 88 | |
| 89 | class 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 Gregorio | db849af | 2010-09-22 16:53:59 -0400 | [diff] [blame] | 102 | if __name__ == '__main__': |
| 103 | unittest.main() |