<s> import falcon <EOL> from falcon import testing <EOL> class TestCustomRouter ( testing . TestBase ) : <EOL> def test_custom_router_add_route_should_be_used ( self ) : <EOL> check = [ ] <EOL> class CustomRouter ( object ) : <EOL> def add_route ( self , uri_template , * args , ** kwargs ) : <EOL> check . append ( uri_template ) <EOL> api = falcon . API ( router = CustomRouter ( ) ) <EOL> api . add_route ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( check ) , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' , check ) <EOL> def test_custom_router_find_should_be_used ( self ) : <EOL> def resource ( req , resp , ** kwargs ) : <EOL> resp . body = '<STR_LIT>' <EOL> class CustomRouter ( object ) : <EOL> def __init__ ( self ) : <EOL> self . reached_backwards_compat = False <EOL> def find ( self , uri ) : <EOL> if uri == '<STR_LIT>' : <EOL> return resource , { '<STR_LIT:GET>' : resource } , { } <EOL> if uri == '<STR_LIT>' : <EOL> self . reached_backwards_compat = True <EOL> return ( None , None , None ) <EOL> return None <EOL> router = CustomRouter ( ) <EOL> self . api = falcon . API ( router = router ) <EOL> body = self . simulate_request ( '<STR_LIT>' ) <EOL> self . assertEqual ( body , [ b'<STR_LIT>' ] ) <EOL> for uri in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> body = self . simulate_request ( uri ) <EOL> self . assertFalse ( body ) <EOL> self . assertEqual ( self . srmock . status , falcon . HTTP_404 ) <EOL> self . assertTrue ( router . reached_backwards_compat ) <EOL> def test_can_pass_additional_params_to_add_route ( self ) : <EOL> check = [ ] <EOL> class CustomRouter ( object ) : <EOL> def add_route ( self , uri_template , method_map , resource , name ) : <EOL> self . _index = { name : uri_template } <EOL> check . append ( name ) <EOL> api = falcon . API ( router = CustomRouter ( ) ) <EOL> api . add_route ( '<STR_LIT>' , '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( check ) , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' , check ) <EOL> api . add_route ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( check ) , <NUM_LIT:2> ) <EOL> self . assertIn ( '<STR_LIT>' , check ) </s>
