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

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

index 4ca2223..0e129fb 100644 (file)
@@ -85,18 +85,19 @@ class Service(org.maemo.hermes.engine.service.Service):
 
     # -----------------------------------------------------------------------
     def process_contact(self, contact):
+        matched_friend = None
         if self._friends_by_contact.has_key(contact):
-            return
+            matched_friend = self._friends_by_contact[contact]
         
-        matched_friend = None
         # we might get a hit if the friend has setup a URL with another service,
         # such as putting the id link to Facebook on the Twitter account's profile
-        for url in contact.get_urls():
-            if url in self._friends_by_url:
-                matched_friend = self._friends_by_url[url]
-                self._register_match(contact, matched_friend)
-                print contact.get_name(), " -> match by url -> ", matched_friend
-                return
+        if not matched_friend:
+            for url in contact.get_urls():
+                if url in self._friends_by_url:
+                    matched_friend = self._friends_by_url[url]
+                    self._register_match(contact, matched_friend)
+                    print contact.get_name(), " -> match by url -> ", matched_friend
+                    break
 
         if not matched_friend:
             for id in contact.get_identifiers():
@@ -104,7 +105,9 @@ class Service(org.maemo.hermes.engine.service.Service):
                     matched_friend = self._friends_by_name.pop(id)
                     self._register_match(contact, matched_friend)
                     print contact.get_name(), " -> match by name -> ", matched_friend
-                    return
+                    break
+                
+        return matched_friend
     
 
     # -----------------------------------------------------------------------
index 659b6a9..93255bb 100644 (file)
@@ -1,8 +1,10 @@
 from org.maemo.hermes.engine.facebook.service import Service
 from org.maemo.hermes.engine.names import canonical
+from org.maemo.hermes.engine.friend import Friend
 import unittest
 
 
+
 class FakeContact():
     id_counter = 0
     def __init__(self, name, addr, id=None):
@@ -22,6 +24,17 @@ class TestFacebookService(unittest.TestCase):
     def setUp(self):
         self.testee = Service(None)
         
+        
+    def test_that_process_known_contact_returns_friend_object(self):
+        known_url = 'http://www.facebook.com/profile.php?id=123456'
+        known_contact = FakeContact('Facebook Junkie', [known_url])
+        self._fake_server_response([{'uid':'123456','name':'Facebook Junkie'}])
+        
+        self.testee.process_friends()
+        result = self.testee.process_contact(known_contact)
+        assert isinstance(result, Friend)
+
+
     def test_main_flow_one_match_by_url_one_by_name(self):
         # arrange
         self.existing_address = 'http://www.facebook.com/profile.php?id=123456'

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment