#NEWLINE# def _test_basic_auth( self , opener , auth_handler , auth_header , realm , http_handler , password_manager , request_url , protected_url ) : #NEWLINE# #INDENT# import base64 #NEWLINE# ( user , password ) = ( 'wile' , 'coyote' ) #NEWLINE# auth_handler . add_password ( realm , request_url , user , password ) #NEWLINE# self . assertEqual ( realm , password_manager . realm ) #NEWLINE# self . assertEqual ( request_url , password_manager . url ) #NEWLINE# self . assertEqual ( user , password_manager . user ) #NEWLINE# self . assertEqual ( password , password_manager . password ) #NEWLINE# r = opener . open ( request_url ) #NEWLINE# self . assertEqual ( password_manager . target_realm , realm ) #NEWLINE# self . assertEqual ( password_manager . target_url , protected_url ) #NEWLINE# self . assertEqual ( len ( r . requests ) , 2 ) #NEWLINE# self . assertFalse ( http_handler . requests [ 0 ] . has_header ( auth_header ) ) #NEWLINE# userpass = ( '%s:%s' % ( user , password ) ) #NEWLINE# auth_hdr_value = ( 'Basic ' + base64 . encodestring ( userpass ) . strip ( ) ) #NEWLINE# self . assertEqual ( http_handler . requests [ 1 ] . get_header ( auth_header ) , auth_hdr_value ) #NEWLINE# self . assertEqual ( http_handler . requests [ 1 ] . unredirected_hdrs [ auth_header ] , auth_hdr_value ) #NEWLINE# password_manager . user = password_manager . password = None #NEWLINE# http_handler . reset ( ) #NEWLINE# r = opener . open ( request_url ) #NEWLINE# self . assertEqual ( len ( http_handler . requests ) , 1 ) #NEWLINE# self . assertFalse ( http_handler . requests [ 0 ] . has_header ( auth_header ) )