7a774d34c14680895a4eb19615e20ff6e1a4e03f
[hermes] / package / test / integration / test_gravatar.py
1 from org.maemo.hermes.engine.gravatar.service import Service
2 from org.maemo.hermes.engine.friend import Friend 
3 import unittest
4
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 IntegrationTestGravatarService(unittest.TestCase):
14     
15     def setUp(self):
16         self.testee = Service('maemohermes@wendt.se', 'b14ec179822b')
17         
18         self.existing_address = 'fredrik@wendt.se'
19         self.existing_contact = FakeContact([self.existing_address])
20         self.existing_friend = Friend("Fredrik Wendt")
21         
22         self.missing_address = 'will_not_ever_exist_i_truly_hope_at_least@wendt.se'
23         self.missing_contact = FakeContact([self.missing_address])
24         self.missing_friend = Friend("Unknown Person")
25         
26         self.multiple_contact = FakeContact([self.existing_address, self.missing_address])
27         self.multiple_friend = Friend("Another Person")
28         
29         
30     def test_main_flow(self):
31         self.testee.pre_process_contact(self.existing_contact)
32         self.testee.pre_process_contact(self.missing_contact)
33         self.testee.process_friends()
34         self.testee.process_contact(self.existing_contact)
35         self.testee.process_contact(self.missing_contact)
36         
37         friends = self.testee.get_friends()
38         contacts = self.testee.get_contacts_with_match()
39         assert len(friends) == 1
40         assert len(contacts) == 1
41         assert self.missing_contact not in contacts.keys()
42         assert self.existing_contact in contacts.keys()
43         friend = friends[0]
44         assert friend.get_name() == self.existing_contact.get_name()
45
46
47     
48 if __name__ == '__main__':
49     unittest.main()