class FixtureFixtureLinkManagementTest(TestCase):
    
    def setUp(self):
        self._facebook_fixture = FaceBookFixture(APP_ID, CLIENT_SECRET)
        self._link_user    = self._facebook_fixture.add_user(permissions='read_stream,share_item', user_key="link_user")
        self._friend_user = self._facebook_fixture.add_user(permissions='read_stream, publish_stream', user_key="friend_user")
        self._facebook_fixture.create_friends(self._link_user, self._friend_user)
        self._facebook_link_repository = FaceBookLinkRepository()
        
    def tearDown(self):
        self._facebook_fixture.delete_all_users()
        
    def _create_test_link(self):
        facebook_link = self._facebook_fixture.create_link(self._link_user,
                                           'Article Title',
                                           'http://www.example.com/article.html',
                                           'http://www.example.com/article-thumbnail.jpg',
                                           'Caption for the link',
                                           'Longer description of the link',
                                           'User Message')
        return facebook_link
    
    def test_create_link(self):        
        #SUT
        facebook_link = self._create_test_link()
        
        #Assertions
        user_links = self._facebook_link_repository.find_links(self._link_user)
        self.assertTrue(facebook_link in user_links)
                
    def test_create_comment(self):
        #Fixture
        facebook_link = self._create_test_link()
        
        #SUT
        comment_id = self._facebook_fixture.create_comment(facebook_link, self._friend_user, "My 2 cents")
        
        #Assertions
        updated_link = self._facebook_link_repository.find_link(self._link_user, facebook_link.id)
        
        self.assertTrue(comment_id in [comment.id for comment in updated_link.comments],
                         "Comment %s not found in %s" % (comment_id, [comment.id for comment in updated_link.comments]))
class FacebookFixtureUserManagementTest(TestCase):
    
    def setUp(self):
        self._facebook_fixture = FaceBookFixture(APP_ID, CLIENT_SECRET)
    
    def tearDown(self):
        self._facebook_fixture.delete_all_users()
        
    def test_add_user(self):
        #SUT
        test_user = self._facebook_fixture.add_user()
              
        #Assertions
        self.assertTrue(isinstance(test_user, TestUser))
        
        list_users = self._facebook_fixture.list_test_users()
        self.assertTrue(list_users is not None and len(list_users) > 0)
        for test_user in list_users:
            self.assertTrue(isinstance(test_user, TestUser))
        
    def test_delete_all_users(self):
        #Fixture
        self._facebook_fixture.add_user()
        self._facebook_fixture.add_user()
        self._facebook_fixture.add_user()
        
        #SUT
        return_value = self._facebook_fixture.delete_all_users()
        
        #Assertions
        self.assertTrue(return_value is True)
        list_users = self._facebook_fixture.list_test_users()
        self.assertTrue(list_users is not None and len(list_users) == 0)
        
    def test_delete_user(self):
        #Fixture
        self._facebook_fixture.delete_all_users()
        user1 = self._facebook_fixture.add_user()
        user2 = self._facebook_fixture.add_user()
        user3 = self._facebook_fixture.add_user()
        
        #SUT
        return_value = self._facebook_fixture.delete_user(user2)
        
        #Assertions
        self.assertTrue(return_value is True)
        list_users = self._facebook_fixture.list_test_users()
        self.assertEqual(len(list_users), 2)
        self.assertTrue(user1 in list_users)
        self.assertTrue(user2 not in list_users)
        self.assertTrue(user3 in list_users)
        
    def test_create_friends(self):
        #Fixture
        user1 = self._facebook_fixture.add_user()
        user2 = self._facebook_fixture.add_user()
        
        #SUT
        return_value = self._facebook_fixture.create_friends(user1, user2)
        
        #Assertions
        self.assertTrue(return_value)