#NEWLINE# def test_transaction_hook_with_transactional_class_decorator( self ) : #NEWLINE# #INDENT# run_hook = [ ] #NEWLINE# @ transactional ( ) #NEWLINE# class RootController ( object ) : #NEWLINE# #INDENT# @ expose ( ) #NEWLINE# def index( self ) : #NEWLINE# #INDENT# run_hook . append ( 'inside' ) #NEWLINE# return 'Hello, World!' #NEWLINE# #UNINDENT# @ expose ( ) #NEWLINE# def redirect( self ) : #NEWLINE# #INDENT# redirect ( '/' ) #NEWLINE# #UNINDENT# @ expose ( ) #NEWLINE# @ transactional ( False ) #NEWLINE# def redirect_rollback( self ) : #NEWLINE# #INDENT# redirect ( '/' ) #NEWLINE# #UNINDENT# @ expose ( ) #NEWLINE# def error( self ) : #NEWLINE# #INDENT# return [ ] [ 1 ] #NEWLINE# #UNINDENT# @ expose ( generic = True ) #NEWLINE# def generic( self ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# @ generic . when ( method = 'GET' ) #NEWLINE# def generic_get( self ) : #NEWLINE# #INDENT# run_hook . append ( 'inside' ) #NEWLINE# return 'generic get' #NEWLINE# #UNINDENT# @ generic . when ( method = 'POST' ) #NEWLINE# def generic_post( self ) : #NEWLINE# #INDENT# run_hook . append ( 'inside' ) #NEWLINE# return 'generic post' #NEWLINE# #UNINDENT# #UNINDENT# def gen( event ) : #NEWLINE# #INDENT# return ( lambda : run_hook . append ( event ) ) #NEWLINE# #UNINDENT# app = TestApp ( make_app ( RootController ( ) , hooks = [ TransactionHook ( start = gen ( 'start' ) , start_ro = gen ( 'start_ro' ) , commit = gen ( 'commit' ) , rollback = gen ( 'rollback' ) , clear = gen ( 'clear' ) ) ] ) ) #NEWLINE# response = app . get ( '/' ) #NEWLINE# assert ( response . status_int == 200 ) #NEWLINE# assert ( response . body == b_ ( 'Hello, World!' ) ) #NEWLINE# assert ( len ( run_hook ) == 6 ) #NEWLINE# assert ( run_hook [ 0 ] == 'start_ro' ) #NEWLINE# assert ( run_hook [ 1 ] == 'clear' ) #NEWLINE# assert ( run_hook [ 2 ] == 'start' ) #NEWLINE# assert ( run_hook [ 3 ] == 'inside' ) #NEWLINE# assert ( run_hook [ 4 ] == 'commit' ) #NEWLINE# assert ( run_hook [ 5 ] == 'clear' ) #NEWLINE# run_hook = [ ] #NEWLINE# response = app . post ( '/' ) #NEWLINE# assert ( response . status_int == 200 ) #NEWLINE# assert ( response . body == b_ ( 'Hello, World!' ) ) #NEWLINE# assert ( len ( run_hook ) == 4 ) #NEWLINE# assert ( run_hook [ 0 ] == 'start' ) #NEWLINE# assert ( run_hook [ 1 ] == 'inside' ) #NEWLINE# assert ( run_hook [ 2 ] == 'commit' ) #NEWLINE# assert ( run_hook [ 3 ] == 'clear' ) #NEWLINE# run_hook = [ ] #NEWLINE# response = app . get ( '/redirect' ) #NEWLINE# assert ( response . status_int == 302 ) #NEWLINE# assert ( len ( run_hook ) == 5 ) #NEWLINE# assert ( run_hook [ 0 ] == 'start_ro' ) #NEWLINE# assert ( run_hook [ 1 ] == 'clear' ) #NEWLINE# assert ( run_hook [ 2 ] == 'start' ) #NEWLINE# assert ( run_hook [ 3 ] == 'commit' ) #NEWLINE# assert ( run_hook [ 4 ] == 'clear' ) #NEWLINE# run_hook = [ ] #NEWLINE# response = app . post ( '/redirect' ) #NEWLINE# assert ( response . status_int == 302 ) #NEWLINE# assert ( len ( run_hook ) == 3 ) #NEWLINE# assert ( run_hook [ 0 ] == 'start' ) #NEWLINE# assert ( run_hook [ 1 ] == 'commit' ) #NEWLINE# assert ( run_hook [ 2 ] == 'clear' ) #NEWLINE# run_hook = [ ] #NEWLINE# response = app . get ( '/redirect_rollback' ) #NEWLINE# assert ( response . status_int == 302 ) #NEWLINE# assert ( len ( run_hook ) == 5 ) #NEWLINE# assert ( run_hook [ 0 ] == 'start_ro' ) #NEWLINE# assert ( run_hook [ 1 ] == 'clear' ) #NEWLINE# assert ( run_hook [ 2 ] == 'start' ) #NEWLINE# assert ( run_hook [ 3 ] == 'rollback' ) #NEWLINE# assert ( run_hook [ 4 ] == 'clear' ) #NEWLINE# run_hook = [ ] #NEWLINE# response = app . post ( '/redirect_rollback' ) #NEWLINE# assert ( response . status_int == 302 ) #NEWLINE# assert ( len ( run_hook ) == 3 ) #NEWLINE# assert ( run_hook [ 0 ] == 'start' ) #NEWLINE# assert ( run_hook [ 1 ] == 'rollback' ) #NEWLINE# assert ( run_hook [ 2 ] == 'clear' ) #NEWLINE# run_hook = [ ] #NEWLINE# try : #NEWLINE# #INDENT# response = app . post ( '/error' ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# assert ( len ( run_hook ) == 3 ) #NEWLINE# assert ( run_hook [ 0 ] == 'start' ) #NEWLINE# assert ( run_hook [ 1 ] == 'rollback' ) #NEWLINE# assert ( run_hook [ 2 ] == 'clear' ) #NEWLINE# run_hook = [ ] #NEWLINE# try : #NEWLINE# #INDENT# response = app . get ( '/error' ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# assert ( len ( run_hook ) == 5 ) #NEWLINE# assert ( run_hook [ 0 ] == 'start_ro' ) #NEWLINE# assert ( run_hook [ 1 ] == 'clear' ) #NEWLINE# assert ( run_hook [ 2 ] == 'start' ) #NEWLINE# assert ( run_hook [ 3 ] == 'rollback' ) #NEWLINE# assert ( run_hook [ 4 ] == 'clear' ) #NEWLINE# run_hook = [ ] #NEWLINE# response = app . get ( '/generic' ) #NEWLINE# assert ( response . status_int == 200 ) #NEWLINE# assert ( response . body == b_ ( 'generic get' ) ) #NEWLINE# assert ( len ( run_hook ) == 6 ) #NEWLINE# assert ( run_hook [ 0 ] == 'start_ro' ) #NEWLINE# assert ( run_hook [ 1 ] == 'clear' ) #NEWLINE# assert ( run_hook [ 2 ] == 'start' ) #NEWLINE# assert ( run_hook [ 3 ] == 'inside' ) #NEWLINE# assert ( run_hook [ 4 ] == 'commit' ) #NEWLINE# assert ( run_hook [ 5 ] == 'clear' ) #NEWLINE# run_hook = [ ] #NEWLINE# response = app . post ( '/generic' ) #NEWLINE# assert ( response . status_int == 200 ) #NEWLINE# assert ( response . body == b_ ( 'generic post' ) ) #NEWLINE# assert ( len ( run_hook ) == 4 ) #NEWLINE# assert ( run_hook [ 0 ] == 'start' ) #NEWLINE# assert ( run_hook [ 1 ] == 'inside' ) #NEWLINE# assert ( run_hook [ 2 ] == 'commit' ) #NEWLINE# assert ( run_hook [ 3 ] == 'clear' )