From: Fredrik Wendt Date: Wed, 9 Jun 2010 19:47:23 +0000 (+0100) Subject: updated and cleaned up Gravatar X-Git-Tag: 0.8.0~19 X-Git-Url: http://vcs.maemo.org/git/?p=hermes;a=commitdiff_plain;h=f21472351eb9de2d3a3ccf8e355cafa3ec2dd13f updated and cleaned up Gravatar Signed-off-by: Fredrik Wendt --- diff --git a/package/src/org/maemo/hermes/engine/gravatar/service.py b/package/src/org/maemo/hermes/engine/gravatar/service.py index 6c4880b..f3bb225 100644 --- a/package/src/org/maemo/hermes/engine/gravatar/service.py +++ b/package/src/org/maemo/hermes/engine/gravatar/service.py @@ -20,13 +20,12 @@ class Service(org.maemo.hermes.engine.service.Service): 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 = {} @@ -37,13 +36,20 @@ class Service(org.maemo.hermes.engine.service.Service): # ----------------------------------------------------------------------- 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(): @@ -58,25 +64,24 @@ class Service(org.maemo.hermes.engine.service.Service): # ----------------------------------------------------------------------- - 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 # ----------------------------------------------------------------------- @@ -118,7 +123,6 @@ class Service(org.maemo.hermes.engine.service.Service): # ----------------------------------------------------------------------- def _set_hash_information(self, hash_info): self._hash_has_gravatar = hash_info - self._empty_cache = False # ----------------------------------------------------------------------- diff --git a/package/test/integration/test_gravatar.py b/package/test/integration/test_gravatar.py index 5f828e6..f4b3391 100644 --- a/package/test/integration/test_gravatar.py +++ b/package/test/integration/test_gravatar.py @@ -31,11 +31,14 @@ class IntegrationTestGravatarService(unittest.TestCase): 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() diff --git a/package/test/unit/test_gravatar.py b/package/test/unit/test_gravatar.py index ffc70bd..99671a8 100644 --- a/package/test/unit/test_gravatar.py +++ b/package/test/unit/test_gravatar.py @@ -18,6 +18,20 @@ class TestGravatarService(unittest.TestCase): 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/'}) @@ -46,8 +60,8 @@ class TestGravatarService(unittest.TestCase): 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