blob: c318d956bbc180f95c0063f8edf8fbf8a18564b3 [file] [log] [blame]
ade@google.comac41d842010-08-20 17:11:25 +01001# Copyright (C) 2010 Google Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15__author__ = 'ade@google.com'
16
17import buzz_gae_client
18import unittest
19
20class BuzzGaeClientTest(unittest.TestCase):
21 def test_can_build_client(self):
22 client = buzz_gae_client.BuzzGaeClient()
23 self.assertNotEquals(None, client)
24
25 def test_can_get_request_token(self):
26 client = buzz_gae_client.BuzzGaeClient()
27 callback_url = 'http://example.com'
28 request_token = client.get_request_token(callback_url)
29 self.assertTrue(request_token['oauth_token'] is not None)
30 self.assertTrue(request_token['oauth_token_secret'] is not None)
31 self.assertEquals(request_token['oauth_callback_confirmed'], 'true')
32
33 def test_can_generate_authorisation_url(self):
34 client = buzz_gae_client.BuzzGaeClient()
35 callback_url = 'http://example.com'
36 request_token = client.get_request_token(callback_url)
37 authorisation_url = client.generate_authorisation_url(request_token)
38 self.assertTrue(authorisation_url is not None)
39 self.assertTrue(authorisation_url.startswith('https://www.google.com/buzz/api/auth/OAuthAuthorizeToken?scope='))
40
41 # TODO(ade) this test can't work outside of the AppEngine environment. Find an equivalent that works.
42 def _test_can_upgrade_tokens(self):
43 client = buzz_gae_client.BuzzGaeClient()
44 callback_url = 'http://example.com'
45 request_token = client.get_request_token(callback_url)
46 oauth_verifier = 'some verifier'
47
48 consumer_key = 'anonymous'
49 consumer_secret = 'anonymous'
50 usable_token = client.upgrade_to_access_token(request_token, oauth_verifier)
51 self.assertTrue(usable_token is not None)
52 self.assertEquals(consumer_key, usable_token['consumer_key'])
53 self.assertEquals(consumer_secret, usable_token['consumer_secret'])
54 self.assertTrue(usable_token['access_token'] is not None)
55
56 def test_can_build_apiary_client_with_access_token(self):
57 client = buzz_gae_client.BuzzGaeClient()
58 oauth_parameters = {}
59 oauth_parameters['oauth_token'] = ''
60 oauth_parameters['oauth_token_secret'] = ''
61 oauth_parameters['consumer_key'] = ''
62 oauth_parameters['consumer_secret'] = ''
63 api_client = client.build_api_client(oauth_parameters)
64 self.assertTrue(api_client is not None)
65
ade@google.come80fec82010-08-20 23:42:08 +010066 def test_can_fetch_activites_from_buzz(self):
67 client = buzz_gae_client.BuzzGaeClient()
68 api_client = client.build_api_client()
69 count = 9
70 activities = api_client.activities().list(userId='googlebuzz', scope='@self', max_results=count)['items']
71 self.assertEquals(count, len(activities))
72
ade@google.comac41d842010-08-20 17:11:25 +010073if __name__ == '__main__':
74 unittest.main()