#NEWLINE# def test_file_upload_multipart( self ) : #NEWLINE# #INDENT# content = open ( path ( 'test.file' ) , 'rb' ) . read ( ) #NEWLINE# files = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# files [ 'test.file1' ] = ( b'test.file1' , b'test.file' , content ) #NEWLINE# files [ 'test.file3' ] = ( b'test.file3' , b'wangxiaobo' , content ) #NEWLINE# files [ 'test.file4' ] = ( b'test.file4' , b'wangtwo' , content ) #NEWLINE# data = testlib . randdict ( ) #NEWLINE# params = testlib . randdict ( 5 ) #NEWLINE# r = urlfetch . post ( testlib . test_server_host , data = data , params = params , files = { #NEWLINE# #INDENT# 'test.file1' : open ( path ( 'test.file' ) ) , #NEWLINE# 'test.file3' : ( 'wangxiaobo' , open ( path ( 'test.file' ) ) ) , #NEWLINE# 'test.file4' : ( 'wangtwo' , content ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# o = json . loads ( r . text ) #NEWLINE# self . assertEqual ( r . status , 200 ) #NEWLINE# self . assertTrue ( isinstance ( r . json , dict ) ) #NEWLINE# self . assertTrue ( isinstance ( r . text , urlfetch . unicode ) ) #NEWLINE# self . assertEqual ( o [ 'method' ] , 'POST' ) #NEWLINE# self . assertEqual ( o [ 'post' ] , data ) #NEWLINE# self . assertEqual ( sorted ( o [ 'files' ] . keys ( ) ) , sorted ( files . keys ( ) ) ) #NEWLINE# for i in files : #NEWLINE# #INDENT# self . assertEqual ( o [ 'files' ] [ i ] [ 0 ] . encode ( 'utf-8' ) , files [ i ] [ 0 ] ) #NEWLINE# self . assertEqual ( o [ 'files' ] [ i ] [ 1 ] . encode ( 'utf-8' ) , files [ i ] [ 1 ] ) #NEWLINE# self . assertEqual ( o [ 'files' ] [ i ] [ 2 ] . encode ( 'utf-8' ) , md5sum ( files [ i ] [ 2 ] ) ) #NEWLINE# #UNINDENT# for ( k , v ) in params . items ( ) : #NEWLINE# #INDENT# self . assertTrue ( ( ( '%s=%s' % ( k , data ) ) in r . url ) )