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):
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/"})
22 self.testee.pre_process_contact(self.multiple_contact)
23 self.testee.process_friends()
24 self.testee.process_contact(self.multiple_contact)
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()
36 def _fake_server_response(self, map):
37 self.testee._get_hash_info_from_server = self._get_hash_info_from_server
38 # in real results the addresses hashed, so we'll add that here, and keep originals for easier debugging/inspection
39 for key in map.keys():
40 hash = self.testee._get_hash_for_address(key)
42 self._server_response = map
44 def _get_hash_info_from_server(self, args, url):
45 self._server_args = args
46 self._server_url = url
47 return self._server_response
49 def _setUp(self, email, key):
50 self.testee = Service(email, key)
52 self.existing_address = 'fredrik@wendt.se'
53 self.existing_contact = FakeContact([self.existing_address])
54 self.existing_friend = Friend("Fredrik Wendt")
56 self.missing_address = 'will_not_ever_exist_i_truly_hope_at_least@wendt.se'
57 self.missing_contact = FakeContact([self.missing_address])
58 self.missing_friend = Friend("Unknown Person")
60 self.multiple_contact = FakeContact([self.existing_address, self.missing_address])
61 self.multiple_friend = Friend("Another Person")
64 if __name__ == '__main__':