Re-implement Facebook service to use OAuth2 and Graph API. This allows
[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('gravatar', '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         existing_friend = self.testee.process_contact(self.existing_contact)
35         missing_friend = self.testee.process_contact(self.missing_contact)
36         
37         assert isinstance(existing_friend, Friend)
38         assert missing_friend is None
39         
40         friends = self.testee._get_friends()
41         contacts = self.testee._get_contacts_with_match()
42         assert len(friends) == 1
43         assert len(contacts) == 1
44         assert self.missing_contact not in contacts.keys()
45         assert self.existing_contact in contacts.keys()
46         friend = friends[0]
47         assert friend.get_name() == self.existing_contact.get_name()
48
49
50     
51 if __name__ == '__main__':
52     unittest.main()