#NEWLINE# def test_prioritized_hooks( self ) : #NEWLINE# #INDENT# run_hook = [ ] #NEWLINE# class RootController ( object ) : #NEWLINE# #INDENT# @ expose ( ) #NEWLINE# def index( self , req , resp ) : #NEWLINE# #INDENT# run_hook . append ( 'inside' ) #NEWLINE# return 'Hello, World!' #NEWLINE# #UNINDENT# #UNINDENT# class SimpleHook ( PecanHook ) : #NEWLINE# #INDENT# def __init__( self , id , priority = None ) : #NEWLINE# #INDENT# self . id = str ( id ) #NEWLINE# if priority : #NEWLINE# #INDENT# self . priority = priority #NEWLINE# #UNINDENT# #UNINDENT# def on_route( self , state ) : #NEWLINE# #INDENT# run_hook . append ( ( 'on_route' + self . id ) ) #NEWLINE# #UNINDENT# def before( self , state ) : #NEWLINE# #INDENT# run_hook . append ( ( 'before' + self . id ) ) #NEWLINE# #UNINDENT# def after( self , state ) : #NEWLINE# #INDENT# run_hook . append ( ( 'after' + self . id ) ) #NEWLINE# #UNINDENT# def on_error( self , state , e ) : #NEWLINE# #INDENT# run_hook . append ( ( 'error' + self . id ) ) #NEWLINE# #UNINDENT# #UNINDENT# papp = Pecan ( RootController ( ) , hooks = [ SimpleHook ( 1 , 3 ) , SimpleHook ( 2 , 2 ) , SimpleHook ( 3 , 1 ) ] , use_context_locals = False ) #NEWLINE# app = TestApp ( papp ) #NEWLINE# response = app . get ( '/' ) #NEWLINE# assert ( response . status_int == 200 ) #NEWLINE# assert ( response . body == b_ ( 'Hello, World!' ) ) #NEWLINE# assert ( len ( papp ) == 10 ) #NEWLINE# assert ( run_hook [ 0 ] == 'on_route3' ) #NEWLINE# assert ( run_hook [ 1 ] == 'on_route2' ) #NEWLINE# assert ( run_hook [ 2 ] == 'on_route1' ) #NEWLINE# assert ( run_hook [ 3 ] == 'before3' ) #NEWLINE# assert ( run_hook [ 4 ] == 'before2' ) #NEWLINE# assert ( run_hook [ 5 ] == 'before1' ) #NEWLINE# assert ( run_hook [ 6 ] == 'inside' ) #NEWLINE# assert ( run_hook [ 7 ] == 'after1' ) #NEWLINE# assert ( run_hook [ 8 ] == 'after2' ) #NEWLINE# assert ( run_hook [ 9 ] == 'after3' )