<s> """<STR_LIT>""" <EOL> __authors__ = [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> import time <EOL> from copy import deepcopy <EOL> from viewfinder . backend . base import util <EOL> from viewfinder . backend . db . contact import Contact <EOL> from viewfinder . backend . db . identity import Identity <EOL> from viewfinder . backend . www . test import service_base_test <EOL> class UnlinkIdentityTestCase ( service_base_test . ServiceBaseTestCase ) : <EOL> def testUnlinkIdentity ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _tester . LinkFacebookUser ( { '<STR_LIT:id>' : <NUM_LIT:100> } , user_cookie = self . _cookie ) <EOL> self . assertEqual ( len ( self . _tester . ListIdentities ( self . _cookie ) ) , <NUM_LIT:2> ) <EOL> self . _tester . UnlinkIdentity ( self . _cookie , '<STR_LIT>' ) <EOL> self . _tester . UnlinkIdentity ( self . _cookie , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( self . _tester . ListIdentities ( self . _cookie ) ) , <NUM_LIT:1> ) <EOL> def testUnlinkContacts ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in xrange ( <NUM_LIT:3> ) : <EOL> contact_dict = Contact . CreateContactDict ( self . _users [ i ] . user_id , <EOL> [ ( '<STR_LIT>' , None ) ] , <EOL> util . _TEST_TIME , <EOL> Contact . FACEBOOK , <EOL> rank = i ) <EOL> self . _UpdateOrAllocateDBObject ( Contact , ** contact_dict ) <EOL> self . _tester . LinkFacebookUser ( { '<STR_LIT:id>' : <NUM_LIT:100> } , user_cookie = self . _cookie ) <EOL> response_dict = self . _tester . QueryContacts ( self . _cookie2 , start_key = Contact . CreateSortKey ( None , util . _TEST_TIME ) ) <EOL> self . assertEqual ( len ( response_dict [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> util . _TEST_TIME += <NUM_LIT:1> <EOL> self . _tester . UnlinkIdentity ( self . _cookie , '<STR_LIT>' ) <EOL> response_dict = self . _tester . QueryContacts ( self . _cookie2 , start_key = Contact . CreateSortKey ( None , util . _TEST_TIME ) ) <EOL> self . assertEqual ( len ( response_dict [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> util . _TEST_TIME += <NUM_LIT:1> <EOL> timestamp = time . time ( ) - <NUM_LIT:100> <EOL> for i in xrange ( <NUM_LIT:3> ) : <EOL> contact_dict = Contact . CreateContactDict ( self . _users [ i ] . user_id , <EOL> [ ( '<STR_LIT>' , None ) ] , <EOL> timestamp , <EOL> Contact . FACEBOOK , <EOL> rank = i ) <EOL> contact = self . _UpdateOrAllocateDBObject ( Contact , ** contact_dict ) <EOL> self . _tester . LinkFacebookUser ( { '<STR_LIT:id>' : <NUM_LIT> } , user_cookie = self . _cookie ) <EOL> self . _tester . UnlinkIdentity ( self . _cookie , '<STR_LIT>' ) <EOL> response_dict = self . _tester . QueryContacts ( self . _cookie3 , start_key = Contact . CreateSortKey ( None , util . _TEST_TIME ) ) <EOL> self . assertEqual ( len ( response_dict [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def testLinkAfterUnlink ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _tester . LinkFacebookUser ( { '<STR_LIT:id>' : <NUM_LIT:100> } , user_cookie = self . _cookie ) <EOL> self . _tester . UnlinkIdentity ( self . _cookie , '<STR_LIT>' ) <EOL> self . _tester . LinkFacebookUser ( { '<STR_LIT:id>' : <NUM_LIT:100> } , user_cookie = self . _cookie2 ) <EOL> self . assertEqual ( len ( self . _tester . ListIdentities ( self . _cookie2 ) ) , <NUM_LIT:2> ) <EOL> def testUnlinkUnboundIdentity ( self ) : <EOL> """<STR_LIT>""" <EOL> identity_key = '<STR_LIT>' <EOL> self . _UpdateOrAllocateDBObject ( Identity , key = identity_key ) <EOL> self . assertRaisesHttpError ( <NUM_LIT> , self . _tester . UnlinkIdentity , self . _cookie , identity_key ) <EOL> def testNonCanonicalId ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaisesHttpError ( <NUM_LIT> , self . _tester . UnlinkIdentity , self . _cookie , '<STR_LIT>' ) <EOL> def testUnlinkLastAuthorizedIdentity ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaisesHttpError ( <NUM_LIT> , self . _tester . UnlinkIdentity , self . _cookie , '<STR_LIT>' ) <EOL> def testUnlinkIdentityWithoutPermission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _tester . LinkFacebookUser ( { '<STR_LIT:id>' : <NUM_LIT:100> } , user_cookie = self . _cookie ) <EOL> self . assertRaisesHttpError ( <NUM_LIT> , self . _tester . UnlinkIdentity , self . _cookie2 , '<STR_LIT>' ) <EOL> def testUnknownScheme ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaisesHttpError ( <NUM_LIT> , self . _tester . UnlinkIdentity , self . _cookie , '<STR_LIT>' ) <EOL> def _TestUnlinkIdentity ( tester , user_cookie , request_dict ) : <EOL> """<STR_LIT>""" <EOL> validator = tester . validator <EOL> user_id , device_id = tester . GetIdsFromCookie ( user_cookie ) <EOL> request_dict = deepcopy ( request_dict ) <EOL> actual_dict = tester . SendRequest ( '<STR_LIT>' , user_cookie , request_dict ) <EOL> op_dict = tester . _DeriveNotificationOpDict ( user_id , device_id , request_dict ) <EOL> validator . ValidateUnlinkIdentity ( op_dict , request_dict [ '<STR_LIT>' ] ) <EOL> tester . _CompareResponseDicts ( '<STR_LIT>' , user_id , request_dict , { } , actual_dict ) <EOL> return actual_dict </s>
