#NEWLINE# def test_create_json_response( self ) : #NEWLINE# #INDENT# request = Mock ( url = 'http://example.com' , client_addr = '127.0.0.1' , remote_addr = '127.0.0.2' ) #NEWLINE# obj = Mock ( status_int = 401 , location = 'http://example.com/api' ) #NEWLINE# obj2 = jsonex . create_json_response ( obj , request , encoder = _JSONEncoder , status_code = 402 , explanation = 'success' , message = 'foo' , title = 'bar' ) #NEWLINE# assert ( obj2 . content_type == 'application/json' ) #NEWLINE# assert isinstance ( obj2 . body , six . binary_type ) #NEWLINE# body = json . loads ( obj2 . body . decode ( 'utf-8' ) ) #NEWLINE# assert ( sorted ( body . keys ( ) ) == [ '_pk' , 'client_addr' , 'explanation' , 'message' , 'remote_addr' , 'request_url' , 'status_code' , 'timestamp' , 'title' ] ) #NEWLINE# assert ( body [ 'remote_addr' ] == '127.0.0.2' ) #NEWLINE# assert ( body [ 'client_addr' ] == '127.0.0.1' ) #NEWLINE# assert ( body [ 'status_code' ] == 402 ) #NEWLINE# assert ( body [ 'explanation' ] == 'success' ) #NEWLINE# assert ( body [ 'title' ] == 'bar' ) #NEWLINE# assert ( body [ 'message' ] == 'foo' ) #NEWLINE# assert ( body [ '_pk' ] == 'api' ) #NEWLINE# assert ( body [ 'request_url' ] == 'http://example.com' )