1 from org.maemo.hermes.engine.gravatar.service import Service
2 from org.maemo.hermes.engine.friend import Friend
6 def __init__(self, addr):
13 class TestGravatarService(unittest.TestCase):
16 self._setUp('maemohermes@wendt.se', 'b14ec179822b')
18 def test_main_flow(self):
19 self.testee.pre_process_contact(self.existing_contact)
20 self.testee.pre_process_contact(self.missing_contact)
21 self.testee.process_friends()
22 self.testee.process_contact(self.existing_contact)
23 self.testee.process_contact(self.missing_contact)
25 friends = self.testee.get_friends()
26 contacts = self.testee.get_contacts_with_match()
27 assert len(friends) == 1
28 assert len(contacts) == 1
29 assert self.missing_contact not in contacts.keys()
30 assert self.existing_contact in contacts.keys()
32 assert friend.get_name() == self.existing_contact.get_name()
33 print friend.get_photo_url()
36 def test_that_a_person_with_two_addresses_and_one_gravatar_works(self):
37 self._fake_server_response({self.missing_address: None, self.existing_address: "http://url.to.img/"})
39 self.testee.pre_process_contact(self.multiple_contact)
40 self.testee.process_friends()
41 self.testee.process_contact(self.multiple_contact)
43 friends = self.testee.get_friends()
44 contacts = self.testee.get_contacts_with_match()
45 assert len(friends) == 1
46 assert len(contacts) == 1
47 assert self.multiple_contact in contacts
48 assert self.missing_contact not in contacts
49 assert self.existing_contact not in contacts.keys()
50 assert friends[0].get_name() == self.existing_contact.get_name()
53 def _fake_server_response(self, map):
54 self.testee._get_hash_info_from_server = self._get_hash_info_from_server
55 # in real results the addresses hashed, so we'll add that here, and keep originals for easier debugging/inspection
56 for key in map.keys():
57 hash = self.testee._get_hash_for_address(key)
59 self._server_response = map
61 def _get_hash_info_from_server(self, args, url):
62 self._server_args = args
63 self._server_url = url
64 return self._server_response
66 def _setUp(self, email, key):
67 self.testee = Service(email, key)
69 self.existing_address = 'fredrik@wendt.se'
70 self.existing_contact = FakeContact([self.existing_address])
71 self.existing_friend = Friend("Fredrik Wendt")
73 self.missing_address = 'will_not_ever_exist_i_truly_hope_at_least@wendt.se'
74 self.missing_contact = FakeContact([self.missing_address])
75 self.missing_friend = Friend("Unknown Person")
77 self.multiple_contact = FakeContact([self.existing_address, self.missing_address])
78 self.multiple_friend = Friend("Another Person")
81 if __name__ == '__main__':