<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> from copy import deepcopy <EOL> from viewfinder . backend . base . testing import async_test <EOL> from viewfinder . backend . db . friend import Friend <EOL> from viewfinder . backend . www . test import service_base_test <EOL> class UpdateFriendTestCase ( service_base_test . ServiceBaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( UpdateFriendTestCase , self ) . setUp ( ) <EOL> self . _CreateSimpleTestAssets ( ) <EOL> self . _tester . ShareNew ( self . _cookie , <EOL> [ ( self . _episode_id , self . _photo_ids ) ] , <EOL> [ self . _user2 . user_id ] ) <EOL> def testUpdateFriend ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _tester . UpdateFriend ( self . _cookie , user_id = self . _user2 . user_id , nickname = '<STR_LIT>' ) <EOL> response = self . _tester . QueryUsers ( self . _cookie , [ self . _user2 . user_id ] ) <EOL> self . assertEqual ( response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def testUpdateSelf ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _tester . UpdateFriend ( self . _cookie , user_id = self . _user . user_id , nickname = '<STR_LIT>' ) <EOL> response = self . _tester . QueryUsers ( self . _cookie , [ self . _user . user_id ] ) <EOL> self . assertEqual ( response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def testMultipleUpdates ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _tester . UpdateFriend ( self . _cookie , user_id = self . _user2 . user_id ) <EOL> self . _tester . UpdateFriend ( self . _cookie , user_id = self . _user2 . user_id , nickname = '<STR_LIT>' ) <EOL> self . _tester . UpdateFriend ( self . _cookie , user_id = self . _user2 . user_id , nickname = '<STR_LIT>' ) <EOL> response = self . _tester . QueryUsers ( self . _cookie , [ self . _user2 . user_id ] ) <EOL> self . assertEqual ( response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def testClearNickname ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _tester . UpdateFriend ( self . _cookie , user_id = self . _user2 . user_id , nickname = '<STR_LIT>' ) <EOL> self . _tester . UpdateFriend ( self . _cookie , user_id = self . _user2 . user_id , nickname = None ) <EOL> response = self . _tester . QueryUsers ( self . _cookie , [ self . _user2 . user_id ] ) <EOL> self . assertNotIn ( '<STR_LIT>' , response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def testUpdateNonFriend ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _tester . UpdateFriend ( self . _cookie , user_id = self . _user3 . user_id , nickname = '<STR_LIT>' ) <EOL> response = self . _tester . QueryUsers ( self . _cookie , [ self . _user3 . user_id ] ) <EOL> self . assertEqual ( response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , { '<STR_LIT>' : self . _user3 . user_id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] } ) <EOL> def testUpdateNonUser ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaisesHttpError ( <NUM_LIT> , self . _tester . UpdateFriend , self . _cookie , user_id = <NUM_LIT:1000> , nickname = '<STR_LIT>' ) <EOL> def testBadRequests ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaisesHttpError ( <NUM_LIT> , self . _tester . UpdateFriend , self . _cookie ) <EOL> self . assertRaisesHttpError ( <NUM_LIT> , self . _tester . UpdateFriend , self . _cookie , user_id = self . _user2 . user_id , friend_id = <NUM_LIT:100> ) <EOL> self . assertRaisesHttpError ( <NUM_LIT> , self . _tester . UpdateFriend , self . _cookie , user_id = self . _user2 . user_id , nickname = <NUM_LIT:5> ) <EOL> def _TestUpdateFriend ( 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> friend_dict = request_dict [ '<STR_LIT>' ] <EOL> friend_dict [ '<STR_LIT>' ] = friend_dict . pop ( '<STR_LIT>' ) <EOL> friend_dict [ '<STR_LIT>' ] = user_id <EOL> validator . ValidateUpdateDBObject ( Friend , ** friend_dict ) <EOL> invalidate = { '<STR_LIT>' : [ friend_dict [ '<STR_LIT>' ] ] } <EOL> validator . ValidateNotification ( '<STR_LIT>' , user_id , op_dict , invalidate ) <EOL> tester . _CompareResponseDicts ( '<STR_LIT>' , user_id , request_dict , { } , actual_dict ) <EOL> return actual_dict </s>
