Re-implement Facebook service to use OAuth2 and Graph API. This allows
[hermes] / package / test / integration / test_oauth2.py
1 import unittest
2 import oauth2
3 import httplib
4 import simplejson
5 httplib.HTTPConnection.debuglevel = 1
6
7 class IntegrationTestOAuth2(unittest.TestCase):
8     access_token = None
9     
10     # -----------------------------------------------------------------------
11     def setUp(self):
12         self.oauth = oauth2.OAuth2('5916f12942feea4b3247d42a84371112', '19f7538edd96b6870f2da7e84a6390a4', IntegrationTestOAuth2.access_token)
13         
14         
15     # -----------------------------------------------------------------------
16     def test_authorisation(self):
17         self.oauth.authorise('https://graph.facebook.com/oauth/authorize',
18                              'https://graph.facebook.com/oauth/access_token',
19                              {'scope': 'user_about_me,friends_about_me,user_birthday,friends_birthday,user_website,friends_website,user_work_history,friends_work_history'})
20
21         IntegrationTestOAuth2.access_token = self.oauth.get_access_token()
22         assert IntegrationTestOAuth2.access_token
23
24
25     # -----------------------------------------------------------------------
26     def test_request(self):
27         if not IntegrationTestOAuth2.access_token:
28             self.test_authorisation()
29             
30         response = self.oauth.request('https://graph.facebook.com/me')
31         data = simplejson.loads(response)
32         if 'error' in data:
33             print response
34             raise Exception(data['error'])
35
36         print response
37         assert 'name' in data and data['name']
38
39     
40 if __name__ == '__main__':
41     unittest.main()