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 17:19:03 +0000 (18:19 +0100)
committerFredrik Wendt <fredrik@wendt.se>
Wed, 9 Jun 2010 17:19:03 +0000 (18:19 +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 b227277..077c37e 100644 (file)
@@ -17,6 +17,7 @@ class Service(org.maemo.hermes.engine.service.Service):
     def __init__(self, service_id, facebook, create_birthday_only = False):
         self.fb = facebook
         self._service_id = service_id
+        self._create_birthday_only = create_birthday_only
         
         self._friends_by_name = {}
         self._friends_by_url = {}
@@ -27,10 +28,21 @@ class Service(org.maemo.hermes.engine.service.Service):
 
 
     # -----------------------------------------------------------------------
+    def get_friends_to_create_contacts_for(self):
+        friends = []
+        if self._create_birthday_only:
+            for friend in self._friends_without_contact:
+                if friend.has_birthday_date():
+                    friends.append(friend)
+                    
+        return friends
+    
+    
+    # -----------------------------------------------------------------------
     def get_friends(self):
         """Returns all friends on Facebook"""
         
-        return self._contacts_by_friend.keys()
+        return self._friends_by_url.values()
     
     
     # -----------------------------------------------------------------------
@@ -80,9 +92,8 @@ class Service(org.maemo.hermes.engine.service.Service):
 
             if_defined(data, 'pic_big', friend.set_photo_url)
             
-            if friend.has_birthday_date(): # FIXME: remove this, either you want to add your contacts or not? 
-                self._friends_without_contact.add(friend)
             url = data['profile_url']
+            self._friends_without_contact.add(friend)
             self._friends_by_url[url] = friend
             
             if url not in self._known_urls:
index c1725b9..b766d2f 100644 (file)
@@ -24,6 +24,41 @@ class TestFacebookService(unittest.TestCase):
     def setUp(self):
         self.testee = Service("facebook", None)
         
+    
+    def test_that_get_friends_to_create_contacts_for_works(self):
+        def run_test(expected_length):
+            self._fake_server_response([{'uid':'123456','name':'Facebook Junkie', 'birthday_date':'now'}])
+            self._run_service([])
+            friends = self.testee.get_friends_to_create_contacts_for()
+            assert len(friends) == expected_length
+            
+        # default is to NOT create contacts
+        self.testee = Service("facebook", None)
+        run_test(0)
+        
+        # passing False explicitly
+        self.testee = Service("facebook", None, False)
+        run_test(0)
+        
+        # passing True to constructor
+        self.testee = Service("facebook", None, True)
+        run_test(1)
+        
+    
+    def test_that_gftccf_returns_friends_with_birth_date(self):
+        self.testee = Service("facebook", None, True)
+        bday = '1980-10-15'
+        props_with_bday = {'uid':'123456','name':'Facebook Junkie', 'birthday_date':bday}
+        props_without = {'uid':'123457','name':'Johnny Secret'}
+        self._fake_server_response([props_with_bday, props_without])
+        self._run_service([])
+        
+        assert len(self.testee.get_friends()) == 2
+        friends = self.testee.get_friends_to_create_contacts_for()
+        assert len(friends) == 1
+        assert friends[0].has_birthday_date()
+        assert friends[0].get_birthday_date() == bday 
+        
         
     def test_that_process_contact_returns_friend_object_for_known_contact(self):
         known_url = 'http://www.facebook.com/profile.php?id=123456'

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment