Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
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, sys
7 def log(msg):
8     sys.__stderr__.write(msg + "\n")
10 class FakeGConf(dict):
11     def __init__(self, props=None):
12         dict.__init__(self)
13         if props:
14             for key in props:
15                 self.set_string(key, props[key])
16     def get_string(self, key):
17         try: return self.__getitem__(key)
18         except: return None
19     def set_string(self, key, value):
20         log("gconf %s = %s" % (key, value))
21         self.__setitem__(key, value)
23 class TestLinkedInApi(unittest.TestCase):
24     
25     def setUp(self):
26         self.gconf = FakeGConf({
27                 LinkedInApi.GCONF_API_KEY:'1et4G-VtmtqNfY7gF8PHtxMOf0KNWl9ericlTEtdKJeoA4ubk4wEQwf8lSL8AnYE',
28                 LinkedInApi.GCONF_API_SECRET:'uk--OtmWcxER-Yh6Py5p0VeLPNlDJSMaXj1xfHILoFzrK7fM9eepNo5RbwGdkRo_',
29                 LinkedInApi.GCONF_ACCESS_TOKEN:None })
30         self.testee = LinkedInApi(self.gconf)
32         # uncomment to increase verbosity on HTTP level
33         #httplib.HTTPSConnection.debuglevel = 1
34         #httplib.HTTPConnection.debuglevel = 1
36         
37     def test_typical_flow(self):
38         # uncomment next line if you need to authorize ...
39         #self.testee.authenticate(self._need_auth_cb, self._block_for_auth)
40         # ... or uncomment the following four lines - replacing the oauth_token string with whatever you got
41         #self.gconf.set_string(
42         #          LinkedInApi.GCONF_ACCESS_TOKEN, 
43         #          'oauth_token=f89c2b7b-1c12-4f83-a469-838e78901716&oauth_token_secret=60f817af-6437-4015-962f-cc3aefee0264')
44         #self.testee = LinkedInApi(self.gconf)
45         
46         # uncomment to see the raw xml feed for all connections
47         #xml = self.testee._make_api_request(LinkedInApi.LI_CONN_API_URL)
48         #open("/tmp/linkdata", "w").write(xml)
49         
50         # uncomment to see the raw xml feed for a connection (maemohermes)
51         #xml = self.testee.get_friend_details('http://api.linkedin.com/v1/people/V8pEL-382L:full', 'name:eaU4')
52         #open("/tmp/linkdata2", "w").write(xml)
53         
54         # uncomment if you want to inspect the friend objects returned
55         friends = self.testee.get_friends()
56         for f in friends:
57             photo = f.get_photo_url()
58             if photo: print photo
59         
61     def _need_auth_cb(self):
62         self.need_auth_called = True
65     def _block_for_auth(self, url):
66         import os, time
67         file = "/tmp/verifier"
68         verifier = None
69         msg = "Now open a browser to " + url + " and put the verification code into " + file + " like 'echo 01234 > " + file + "'"
70         log(msg)
71         while True:
72             if os.path.exists(file):
73                 verifier = open(file).read().strip()
74                 os.remove(file)
75                 break
76             time.sleep(2)
77         log("verifier: <" + verifier + ">")
78         return verifier
80     
81 if __name__ == '__main__':
82     unittest.main()

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment