def testUnlinkContacts(self):
    """Test unlinking identity that is referenced by contacts."""
    for i in xrange(3):
      contact_dict = Contact.CreateContactDict(self._users[i].user_id,
                                               [('FacebookGraph:100', None)],
                                               util._TEST_TIME,
                                               Contact.FACEBOOK,
                                               rank=i)
      self._UpdateOrAllocateDBObject(Contact, **contact_dict)

    self._tester.LinkFacebookUser({'id': 100}, user_cookie=self._cookie)
    response_dict = self._tester.QueryContacts(self._cookie2, start_key=Contact.CreateSortKey(None, util._TEST_TIME))
    self.assertEqual(len(response_dict['contacts']), 1)

    # Now unlink the identity and make sure contacts are updated.
    util._TEST_TIME += 1
    self._tester.UnlinkIdentity(self._cookie, 'FacebookGraph:100')
    response_dict = self._tester.QueryContacts(self._cookie2, start_key=Contact.CreateSortKey(None, util._TEST_TIME))
    self.assertEqual(len(response_dict['contacts']), 1)

    # Now repeat, but with older contacts.
    util._TEST_TIME += 1
    timestamp = time.time() - 100
    for i in xrange(3):
      contact_dict = Contact.CreateContactDict(self._users[i].user_id,
                                               [('FacebookGraph:101', None)],
                                               timestamp,
                                               Contact.FACEBOOK,
                                               rank=i)
      contact = self._UpdateOrAllocateDBObject(Contact, **contact_dict)

    self._tester.LinkFacebookUser({'id': 101}, user_cookie=self._cookie)
    self._tester.UnlinkIdentity(self._cookie, 'FacebookGraph:101')
    response_dict = self._tester.QueryContacts(self._cookie3, start_key=Contact.CreateSortKey(None, util._TEST_TIME))
    self.assertEqual(len(response_dict['contacts']), 1)
dataset/ETHPy150Open viewfinderco/viewfinder/backend/www/test/unlink_identity_test.py/UnlinkIdentityTestCase.testUnlinkContacts/original