#NEWLINE# @ mock . patch ( 'st2actions.runners.httprunner.requests' ) #NEWLINE# def test_parse_response_body( self , mock_requests ) : #NEWLINE# #INDENT# client = HTTPClient ( url = 'http://127.0.0.1' ) #NEWLINE# mock_result = MockResult ( ) #NEWLINE# mock_result . text = 'foo bar ponies' #NEWLINE# mock_result . headers = { #NEWLINE# #INDENT# 'Content-Type' : 'text/html' , #NEWLINE# #UNINDENT# } #NEWLINE# mock_result . status_code = 200 #NEWLINE# mock_requests . request . return_value = mock_result #NEWLINE# result = client . run ( ) #NEWLINE# self . assertEqual ( result [ 'body' ] , mock_result . text ) #NEWLINE# self . assertEqual ( result [ 'status_code' ] , mock_result . status_code ) #NEWLINE# self . assertEqual ( result [ 'headers' ] , mock_result . headers ) #NEWLINE# mock_result . text = '{"test1": "val1"}' #NEWLINE# mock_result . headers = { #NEWLINE# #INDENT# 'Content-Type' : 'text/html' , #NEWLINE# #UNINDENT# } #NEWLINE# mock_requests . request . return_value = mock_result #NEWLINE# result = client . run ( ) #NEWLINE# self . assertEqual ( result [ 'body' ] , mock_result . text ) #NEWLINE# mock_result . text = '{"test1": "val1"}' #NEWLINE# mock_result . headers = { #NEWLINE# #INDENT# 'Content-Type' : 'application/json' , #NEWLINE# #UNINDENT# } #NEWLINE# mock_requests . request . return_value = mock_result #NEWLINE# result = client . run ( ) #NEWLINE# self . assertTrue ( isinstance ( result [ 'body' ] , dict ) ) #NEWLINE# self . assertEqual ( result [ 'body' ] , { #NEWLINE# #INDENT# 'test1' : 'val1' , #NEWLINE# #UNINDENT# } ) #NEWLINE# mock_result . text = '{"test1": "val1"}' #NEWLINE# mock_result . headers = { #NEWLINE# #INDENT# 'Content-Type' : 'application/json; charset=UTF-8' , #NEWLINE# #UNINDENT# } #NEWLINE# mock_requests . request . return_value = mock_result #NEWLINE# result = client . run ( ) #NEWLINE# self . assertTrue ( isinstance ( result [ 'body' ] , dict ) ) #NEWLINE# self . assertEqual ( result [ 'body' ] , { #NEWLINE# #INDENT# 'test1' : 'val1' , #NEWLINE# #UNINDENT# } ) #NEWLINE# mock_result . text = 'not json' #NEWLINE# mock_result . headers = { #NEWLINE# #INDENT# 'Content-Type' : 'application/json' , #NEWLINE# #UNINDENT# } #NEWLINE# mock_requests . request . return_value = mock_result #NEWLINE# result = client . run ( ) #NEWLINE# self . assertFalse ( isinstance ( result [ 'body' ] , dict ) ) #NEWLINE# self . assertEqual ( result [ 'body' ] , mock_result . text )