#NEWLINE# def test_xhr_api( ) : #NEWLINE# #INDENT# ( em , app ) = _setup ( ) #NEWLINE# em . enable_xhr ( app ) #NEWLINE# with app . test_client ( ) as c : #NEWLINE# #INDENT# r = c . get ( '/' ) #NEWLINE# assert_in ( 'I am the index page' , em . data ) #NEWLINE# r = c . get ( '/xhr' , headers = [ ( 'X-Requested-With' , 'XMLHttpRequest' ) ] ) #NEWLINE# py_data = loads ( r . data ) #NEWLINE# assert_in ( 'data' , py_data . keys ( ) ) #NEWLINE# assert_in ( 'messages' , py_data . keys ( ) ) #NEWLINE# assert_equals ( len ( py_data [ 'data' ] ) , 2 ) #NEWLINE# assert_equals ( len ( py_data [ 'messages' ] ) , 5 ) #NEWLINE# r = c . get ( '/xhr-failure' ) #NEWLINE# py_data = loads ( r . data ) #NEWLINE# assert_in ( 'error' , py_data . keys ( ) ) #NEWLINE# r = c . get ( '/xhr-failure' , headers = [ ( 'X-Requested-With' , 'XMLHttpRequest' ) ] ) #NEWLINE# py_data = loads ( r . data ) #NEWLINE# assert_in ( 'error' , py_data . keys ( ) ) #NEWLINE# r = c . get ( '/xhr-failure-with-code' , headers = [ ( 'X-Requested-With' , 'XMLHttpRequest' ) ] ) #NEWLINE# assert_equals ( r . status_code , 500 ) #NEWLINE# py_data = loads ( r . data ) #NEWLINE# assert_in ( 'error' , py_data . keys ( ) ) #NEWLINE# assert_in ( 'code' , py_data . keys ( ) ) #NEWLINE# r = c . get ( '/xhr-that-allows-regular-http' ) #NEWLINE# py_data = loads ( r . data ) #NEWLINE# assert_in ( 'test' , py_data [ 'data' ] . keys ( ) ) #NEWLINE# assert_in ( 'A message in a bottle.' , py_data [ 'messages' ] [ 0 ] )