Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
f2e51412525520f45ac024d6806019cdf548f00a
1 from org.maemo.hermes.engine.gravatar.service import Service
2 from org.maemo.hermes.engine.friend import Friend 
3 import unittest
5 class FakeContact():
6     def __init__(self, addr):
7         self.urls = addr
8     def get_emails(self):
9         return self.urls
10     def get_name(self):
11         return self.urls[0]
12     
13 class TestGravatarService(unittest.TestCase):
14     
15     def setUp(self):
16         self._setUp('', '')
17         
18     def test_that_a_person_with_two_addresses_and_one_gravatar_works(self):
19         self._fake_server_response({self.missing_address: None,
20                                     self.existing_address: "http://url.to.img/"})
21         
22         self.testee.pre_process_contact(self.multiple_contact)
23         self.testee.process_friends()
24         self.testee.process_contact(self.multiple_contact)
25         
26         friends = self.testee.get_friends()
27         contacts = self.testee.get_contacts_with_match()
28         assert len(friends) == 1
29         assert len(contacts) == 1
30         assert self.multiple_contact in contacts
31         assert self.missing_contact not in contacts
32         assert self.existing_contact not in contacts.keys()
33         assert friends[0].get_name() == self.existing_contact.get_name()
34         assert friends[0].get_contact() == self.multiple_contact
35         
36         
37     def _fake_server_response(self, map):
38         self.testee._get_hash_info_from_server = self._get_hash_info_from_server
39         # in real results the addresses hashed, so we'll add that here, and keep originals for easier debugging/inspection
40         for key in map.keys():
41             hash = self.testee._get_hash_for_address(key)
42             map[hash] = map[key]
43         self._server_response = map
44     
45     def _get_hash_info_from_server(self, args, url):
46         self._server_args = args
47         self._server_url = url
48         return self._server_response
50     def _setUp(self, email, key):
51         self.testee = Service(email, key)
52         
53         self.existing_address = 'fredrik@wendt.se'
54         self.existing_contact = FakeContact([self.existing_address])
55         self.existing_friend = Friend("Fredrik Wendt")
56         
57         self.missing_address = 'will_not_ever_exist_i_truly_hope_at_least@wendt.se'
58         self.missing_contact = FakeContact([self.missing_address])
59         self.missing_friend = Friend("Unknown Person")
60         
61         self.multiple_contact = FakeContact([self.existing_address, self.missing_address])
62         self.multiple_friend = Friend("Another Person")
64     
65 if __name__ == '__main__':
66     unittest.main()

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment