#NEWLINE# def test_read_socket_body( self ) : #NEWLINE# #INDENT# expected_body = testing . rand_string ( ( SIZE_1_KB / 2 ) , SIZE_1_KB ) #NEWLINE# def server( ) : #NEWLINE# #INDENT# class Echo ( object ) : #NEWLINE# #INDENT# def on_post( self , req , resp ) : #NEWLINE# #INDENT# body = req . stream . read ( ) #NEWLINE# resp . body = body #NEWLINE# #UNINDENT# def on_put( self , req , resp ) : #NEWLINE# #INDENT# body = req . stream . read ( ( req . content_length + 1 ) ) #NEWLINE# resp . body = body #NEWLINE# #UNINDENT# #UNINDENT# api = falcon . API ( ) #NEWLINE# api . add_route ( '/echo' , Echo ( ) ) #NEWLINE# httpd = simple_server . make_server ( '127.0.0.1' , 8989 , api ) #NEWLINE# httpd . serve_forever ( ) #NEWLINE# #UNINDENT# thread = threading . Thread ( target = server ) #NEWLINE# thread . daemon = True #NEWLINE# thread . start ( ) #NEWLINE# thread . join ( 1 ) #NEWLINE# url = 'http://127.0.0.1:8989/echo' #NEWLINE# resp = requests . post ( url , data = expected_body ) #NEWLINE# self . assertEqual ( resp . text , expected_body ) #NEWLINE# resp = requests . put ( url , data = expected_body ) #NEWLINE# self . assertEqual ( resp . text , expected_body )