Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
authorFredrik Wendt <fredrik@wendt.se>
Wed, 9 Jun 2010 22:08:19 +0000 (23:08 +0100)
committerFredrik Wendt <fredrik@wendt.se>
Wed, 9 Jun 2010 22:08:19 +0000 (23:08 +0100)
Signed-off-by: Fredrik Wendt <fredrik@wendt.se>

package/src/org/maemo/hermes/engine/facebook/service.py
package/src/org/maemo/hermes/engine/linkedin/service.py
package/test/unit/test_linkedin.py

index 077c37e..d9b0b4c 100644 (file)
@@ -57,7 +57,7 @@ class Service(org.maemo.hermes.engine.service.Service):
     def get_unmatched_friends(self):
         """Returns a list of all friends that didn't match a contact."""
          
-        return self._friends_by_name.values()
+        return self._friends_without_contact
 
 
     # -----------------------------------------------------------------------
@@ -80,7 +80,6 @@ class Service(org.maemo.hermes.engine.service.Service):
         
         friends_data = self._get_friends_data()
         for data in friends_data:
-            key = canonical(data['name']) # FIXME: deal with name collision
             friend = Friend(data['name'])
         
             if 'profile_url' not in data:
@@ -93,11 +92,8 @@ class Service(org.maemo.hermes.engine.service.Service):
             if_defined(data, 'pic_big', friend.set_photo_url)
             
             url = data['profile_url']
-            self._friends_without_contact.add(friend)
-            self._friends_by_url[url] = friend
-            
-            if url not in self._known_urls:
-                self._friends_by_name[key] = friend
+            friend.add_url(url)
+            self._register_friend(friend)
 
 
     # -----------------------------------------------------------------------
@@ -129,6 +125,26 @@ class Service(org.maemo.hermes.engine.service.Service):
     
 
     # -----------------------------------------------------------------------
+    def _register_friend(self, friend):
+        self._friends_without_contact.add(friend)
+        
+        for url in friend.get_urls():
+            self._friends_by_url[url] = friend
+
+        if self._allow_friend_to_match_by_name(friend):
+            key = canonical(friend.get_name())
+            self._friends_by_name[key] = friend
+
+
+    # -----------------------------------------------------------------------
+    def _allow_friend_to_match_by_name(self, friend):
+        for url in friend.get_urls():
+            if url in self._known_urls:
+                return False
+        return True
+
+
+    # -----------------------------------------------------------------------
     def _register_match(self, contact, friend):
         friend.set_contact(contact)
         self._friends_without_contact.discard(friend)
index d3d9666..86650a2 100644 (file)
@@ -12,9 +12,6 @@ class Service(org.maemo.hermes.engine.facebook.service.Service):
        
     # -----------------------------------------------------------------------
     def __init__(self, service_id, linkedInApi):
-        """Initialize the LinkedIn service, finding LinkedIn API keys in gconf and
-           having a gui_callback available."""
-        
         org.maemo.hermes.engine.facebook.service.Service.__init__(self, service_id, None)
         self.linkedInApi = linkedInApi
 
@@ -23,19 +20,4 @@ class Service(org.maemo.hermes.engine.facebook.service.Service):
     def process_friends(self):
         friends = self.linkedInApi.get_friends()
         for friend in friends:
-            for url in friend.get_urls():
-                self._friends_by_url[url] = friend
-            if self._allow_friend_to_match_by_name(friend):
-                key = canonical(friend.get_name())
-                self._friends_by_name[key] = friend
-
-
-    # -----------------------------------------------------------------------
-    def _allow_friend_to_match_by_name(self, friend):
-        for url in friend.get_urls():
-            if url in self._known_urls:
-                return False
-        return True
-    
-    
-
+            self._register_friend(friend)
index 5f6f4c0..67b2ba0 100644 (file)
@@ -34,6 +34,18 @@ class TestLinkedInService(unittest.TestCase):
     def setUp(self):
         self.linkedInApi = FakeLinkedInApi()
         self.testee = Service('linkedin', self.linkedInApi)
+        
+        
+    def test_that_get_unmatched_friends_works(self):
+        self._fake_server_response([Friend("1"), Friend("2")])
+        
+        self._run_service([])
+        
+        friends = self.testee.get_unmatched_friends()
+        assert len(friends) == 2
+        names = "1.2".split(".")
+        for f in friends: names.remove(f.get_name())
+        assert len(names) == 0
 
 
     def test_that_process_contact_returns_None_for_unknown_contact(self):

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment