2e38d9fbffb3b7725673a6309b7b77f47130d2a0
[hermes] / package / test / integration / test_linkedinapi.py
1 from org.maemo.hermes.engine.linkedin.service import Service
2 from org.maemo.hermes.engine.linkedin.api import LinkedInApi
3 from org.maemo.hermes.engine.names import canonical
4 from org.maemo.hermes.engine.friend import Friend
5 import unittest
6     
7 class FakeGConf(dict):
8     def __init__(self, props=None):
9         dict.__init__(self)
10         if props:
11             for key in props:
12                 self.set_string(key, props[key])
13     def get_string(self, key):
14         try: return self.__getitem__(key)
15         except: return None
16     def set_string(self, key, value):
17         self.__setitem__(key, value)
18
19 class IntegrationTestLinkedInApi(unittest.TestCase):
20     
21     def setUp(self):
22         self.gconf = FakeGConf({
23                 LinkedInApi.GCONF_API_KEY:'1et4G-VtmtqNfY7gF8PHtxMOf0KNWl9ericlTEtdKJeoA4ubk4wEQwf8lSL8AnYE',
24                 LinkedInApi.GCONF_API_SECRET:'uk--OtmWcxER-Yh6Py5p0VeLPNlDJSMaXj1xfHILoFzrK7fM9eepNo5RbwGdkRo_'})
25         self.testee = LinkedInApi(self.gconf)
26
27
28     def test_get_request_token(self):
29         token = self.testee._get_request_token()
30         
31         assert token is not None
32         assert token.callback_confirmed == "true"
33         assert token.key is not None
34         assert token.secret is not None
35         
36         
37     def test_get_authorize_url(self):
38         request_token = self.testee._get_request_token()
39         url = self.testee._get_authorize_url(request_token)
40         
41         assert url is not None
42         assert "linkedin.com" in url
43     
44     
45     def test_verify_verifier_opens_browser(self):
46         self.verifier = "IllegalVerifier"
47         authenticate_threw_exception = False
48
49         try:
50         #if True:
51             self.testee.authenticate(self._need_auth_cb, self._block_for_auth)
52             assert False # should always go to except clause
53         except Exception, e:
54             authenticate_threw_exception = True
55         
56         assert authenticate_threw_exception
57         assert self.need_auth_called
58         assert self.block_for_auth_called
59         assert self.block_for_auth_show_input_field
60
61
62     def _need_auth_cb(self):
63         self.need_auth_called = True
64
65
66     def _block_for_auth(self, show_input_field, url=None):
67         self.block_for_auth_called = True
68         self.block_for_auth_show_input_field = show_input_field
69         self.block_for_auth_url = url
70         return self.verifier
71
72     
73 if __name__ == '__main__':
74     unittest.main()