org.maemo.hermes.engine.service.Service.__init__(self, service_id)
- self._api_email = api_email
- self._api_key = api_key
+ self._api_email = api_email
+ self._api_key = api_key
self._address_to_contact = {}
self._hash_to_address = {}
self._hash_has_gravatar = {}
- self._empty_cache = True
self._friends_by_contact = {}
self._contacts_by_friend = {}
# -----------------------------------------------------------------------
def pre_process_contact(self, contact):
"""Extracts addresses from the contact."""
+
for address in contact.get_emails():
self._address_to_contact[address] = contact
# -----------------------------------------------------------------------
+ def process_friends(self):
+ self._lookup_addresses()
+
+
+ # -----------------------------------------------------------------------
def process_contact(self, contact):
- """On first call (with a contact missing a photo), go get data from Gravatar's servers."""
+ """On first call (with a contact missing a photo), go get data from
+ Gravatar's servers."""
if not self._has_photo(contact):
for address in contact.get_emails():
# -----------------------------------------------------------------------
- def process_friends(self):
- self._lookup_addresses()
+ def get_unmatched_friends(self):
+ """Will always return empty list - Gravatar only reacts on e-mail
+ addresses from existing contacts."""
+ return []
+
# -----------------------------------------------------------------------
- def get_friends(self):
+ def _get_friends(self):
return self._contacts_by_friend.keys()
-
- def get_contacts_with_match(self):
- """Returns a dict with Contact objects as keys and Friend objects as values"""
- return self._friends_by_contact
-
- def get_unmatched_friends(self):
- """Will always return None - Gravatar only reacts on e-mail address input."""
- return None
-
-
+ # -----------------------------------------------------------------------
+ def _get_contacts_with_match(self):
+ """Returns a dict with Contact objects as keys and Friend objects as
+ values"""
+
+ return self._friends_by_contact
# -----------------------------------------------------------------------
# -----------------------------------------------------------------------
def _set_hash_information(self, hash_info):
self._hash_has_gravatar = hash_info
- self._empty_cache = False
# -----------------------------------------------------------------------
self.testee.pre_process_contact(self.existing_contact)
self.testee.pre_process_contact(self.missing_contact)
self.testee.process_friends()
- self.testee.process_contact(self.existing_contact)
- self.testee.process_contact(self.missing_contact)
+ existing_friend = self.testee.process_contact(self.existing_contact)
+ missing_friend = self.testee.process_contact(self.missing_contact)
- friends = self.testee.get_friends()
- contacts = self.testee.get_contacts_with_match()
+ assert isinstance(existing_friend, Friend)
+ assert missing_friend is None
+
+ friends = self.testee._get_friends()
+ contacts = self.testee._get_contacts_with_match()
assert len(friends) == 1
assert len(contacts) == 1
assert self.missing_contact not in contacts.keys()
self._setUp('', '')
+ def test_several_things(self):
+ contact = FakeContact([known_address])
+ self._fake_server_response({known_address: 'http://image.exists.here/',
+ 'extra@here': 'http://nowhere'})
+
+ self.testee.pre_process_contact(contact);
+ self.testee.process_friends()
+ friend = self.testee.process_contact(contact)
+
+ assert isinstance(friend, Friend)
+ assert len(self.testee.get_friends_to_create_contacts_for()) == 0
+ assert len(self.testee.get_unmatched_friends()) == 0 # doesn't matter should always
+
+
def test_that_process_contact_returns_friend_object_if_contact_is_known(self):
contact = FakeContact([known_address])
self._fake_server_response({known_address: 'http://image.exists.here/'})
self.testee.process_friends()
self.testee.process_contact(self.multiple_contact)
- friends = self.testee.get_friends()
- contacts = self.testee.get_contacts_with_match()
+ friends = self.testee._get_friends()
+ contacts = self.testee._get_contacts_with_match()
assert len(friends) == 1
assert len(contacts) == 1
assert self.multiple_contact in contacts