#NEWLINE# @ patch . object ( rauth . session . HmacSha1Signature , 'sign' ) #NEWLINE# @ patch . object ( rauth . session , 'time' ) #NEWLINE# @ patch . object ( rauth . session , 'random' ) #NEWLINE# @ patch . object ( requests . Session , 'request' ) #NEWLINE# def fake_request( self , method , url , mock_request , mock_random , mock_time , mock_sig , header_auth = False , realm = '' , **kwargs ) : #NEWLINE# #INDENT# fake_random = 1 #NEWLINE# fake_time = 1 #NEWLINE# fake_sig = 'foo' #NEWLINE# fake_sig_meth = 'HMAC-SHA1' #NEWLINE# fake_nonce = sha1 ( str ( fake_random ) . encode ( 'ascii' ) ) . hexdigest ( ) #NEWLINE# mock_request . return_value = self . response #NEWLINE# mock_random . return_value = fake_random #NEWLINE# mock_time . return_value = fake_time #NEWLINE# mock_sig . return_value = fake_sig #NEWLINE# method = method #NEWLINE# url = self . session . _set_url ( url ) #NEWLINE# service = OAuth1Service ( self . consumer_key , self . consumer_secret , name = 'service' , request_token_url = self . request_token_url , access_token_url = self . access_token_url , authorize_url = self . authorize_url , base_url = self . base_url ) #NEWLINE# session = service . get_session ( ( self . access_token , self . access_token_secret ) ) #NEWLINE# r = session . request ( method , url , header_auth = header_auth , realm = realm , ** deepcopy ( kwargs ) ) #NEWLINE# kwargs . setdefault ( 'headers' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# kwargs [ 'headers' ] = CaseInsensitiveDict ( kwargs [ 'headers' ] ) #NEWLINE# entity_method = ( method . upper ( ) in ENTITY_METHODS ) #NEWLINE# if entity_method : #NEWLINE# #INDENT# kwargs [ 'headers' ] . setdefault ( 'Content-Type' , FORM_URLENCODED ) #NEWLINE# #UNINDENT# form_urlencoded = ( kwargs [ 'headers' ] . get ( 'Content-Type' ) == FORM_URLENCODED ) #NEWLINE# if is_basestring ( kwargs . get ( 'params' ) ) : #NEWLINE# #INDENT# kwargs [ 'params' ] = dict ( parse_qsl ( kwargs [ 'params' ] ) ) #NEWLINE# #UNINDENT# if ( is_basestring ( kwargs . get ( 'data' ) ) and form_urlencoded ) : #NEWLINE# #INDENT# kwargs [ 'data' ] = dict ( parse_qsl ( kwargs [ 'data' ] ) ) #NEWLINE# #UNINDENT# oauth_params = { #NEWLINE# #INDENT# 'oauth_consumer_key' : session . consumer_key , #NEWLINE# 'oauth_nonce' : fake_nonce , #NEWLINE# 'oauth_signature_method' : fake_sig_meth , #NEWLINE# 'oauth_timestamp' : fake_time , #NEWLINE# 'oauth_token' : self . access_token , #NEWLINE# 'oauth_version' : session . VERSION , #NEWLINE# 'oauth_signature' : fake_sig , #NEWLINE# #UNINDENT# } #NEWLINE# if header_auth : #NEWLINE# #INDENT# auth = mock_request . call_args [ 1 ] [ 'auth' ] #NEWLINE# auth_header = self . fake_get_auth_header ( oauth_params , realm = realm ) #NEWLINE# self . assertEqual ( auth ( requests . Request ( ) ) . headers [ 'Authorization' ] , auth_header ) #NEWLINE# kwargs [ 'auth' ] = auth #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if entity_method : #NEWLINE# #INDENT# kwargs [ 'data' ] = ( kwargs . get ( 'data' ) or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# if form_urlencoded : #NEWLINE# #INDENT# kwargs [ 'data' ] . update ( oauth_params ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# kwargs . setdefault ( 'params' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# kwargs [ 'params' ] . update ( oauth_params ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# kwargs . setdefault ( 'params' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# kwargs [ 'params' ] . update ( ** oauth_params ) #NEWLINE# #UNINDENT# #UNINDENT# mock_request . assert_called_with ( method , url , timeout = OAUTH1_DEFAULT_TIMEOUT , ** kwargs ) #NEWLINE# return r