#NEWLINE# def test_redirectsession_rebuilt_auth_called( ) : #NEWLINE# #INDENT# 'verify our hacking around with Session behavior works' #NEWLINE# session = RedirectSession ( ) #NEWLINE# with requests_mock . Mocker ( ) as m : #NEWLINE# #INDENT# m . get ( 'http://redirect.com' , status_code = 302 , headers = { #NEWLINE# #INDENT# 'Location' : 'http://newredirect.com' , #NEWLINE# #UNINDENT# } ) #NEWLINE# m . get ( 'http://newredirect.com' , text = 'redirected!' ) #NEWLINE# resp = session . get ( 'http://redirect.com' ) . result ( ) #NEWLINE# assert ( resp . url == 'http://newredirect.com' ) #NEWLINE# assert ( resp . text == 'redirected!' ) #NEWLINE# resp = session . get ( 'http://redirect.com' , headers = { #NEWLINE# #INDENT# 'Authorization' : 'api-key foobar' , #NEWLINE# #UNINDENT# } ) . result ( ) #NEWLINE# assert ( resp . url == 'http://newredirect.com/?api_key=foobar' ) #NEWLINE# assert ( resp . text == 'redirected!' ) #NEWLINE# m . get ( 'http://redirect.com' , status_code = 302 , headers = { #NEWLINE# #INDENT# 'Location' : 'http://newredirect.com?param=yep' , #NEWLINE# #UNINDENT# } ) #NEWLINE# m . get ( 'http://newredirect.com?param=yep' , text = 'param!' ) #NEWLINE# resp = session . get ( 'http://redirect.com?param=yep' , headers = { #NEWLINE# #INDENT# 'Authorization' : 'api-key foobar' , #NEWLINE# #UNINDENT# } ) . result ( ) #NEWLINE# assert ( session . url == 'http://newredirect.com/?param=yep&api_key=foobar' ) #NEWLINE# assert ( resp . text == 'param!' )