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.names import canonical
3 from org.maemo.hermes.engine.friend import Friend
4 import unittest
7 class FakeContact():
8     id_counter = 0
9     def __init__(self, name, addr, id=None):
10         self.name = name;
11         self.urls = addr
12         self.id = id or FakeContact.id_counter
13         FakeContact.id_counter = FakeContact.id_counter + 1;
14     def get_urls(self):
15         return self.urls
16     def get_name(self):
17         return self.name
18     def get_identifiers(self):
19         return [canonical(self.name)]
20     
21 class FakeLinkedInApi():
22     def get_friends(self):
23         return self._friends
24     def set_friends(self, data):
25         self._friends = data
26         
27 class UrlFriend(Friend):
28     def __init__(self, name, url):
29         Friend.__init__(self, name)
30         self.add_url(url)
31     
32 class TestLinkedInService(unittest.TestCase):
33     
34     def setUp(self):
35         self.linkedInApi = FakeLinkedInApi()
36         self.testee = Service(self.linkedInApi)
37         
38     def test_main_flow_one_match_by_url_one_by_name(self):
39         known_url = "http://linkedin/id=1"
40         contact_by_url = FakeContact("By Url", [known_url], 1)
41         friend_by_url = UrlFriend("Unimportant", known_url)
42         
43         known_name = "By Name"
44         contact_by_name = FakeContact(known_name, [], 2)
45         friend_by_name = Friend(known_name)
46         
47         self._fake_server_response([friend_by_name, friend_by_url])
48         
49         self._run_service([contact_by_name, contact_by_url])
50         
51         assert len(self.testee.get_unmatched_friends()) == 0
52         matchers = self.testee.get_contacts_with_match()
53         assert contact_by_name in matchers
54         assert contact_by_url in matchers
55         assert known_url in matchers[contact_by_url].get_urls()
56         
57     def _run_service(self, contacts):
58         for contact in contacts:
59             self.testee.pre_process_contact(contact)
60         self.testee.process_friends()
61         for contact in contacts:
62             self.testee.process_contact(contact)
63         
64     def _fake_server_response(self, data):
65         self.linkedInApi.set_friends(data)
66     
67     
68 if __name__ == '__main__':
69     unittest.main()

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment