<s> from smisk . test import * <EOL> from smisk . mvc import * <EOL> from smisk . mvc . routing import * <EOL> from smisk . mvc . control import * <EOL> import smisk . mvc . http as http <EOL> from test_matter import * <EOL> echo = False <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print '<STR_LIT>' <EOL> class RoutingTests ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def setUp ( self ) : <EOL> self . router = Router ( ) <EOL> self . router . filter ( r'<STR_LIT>' , '<STR_LIT>' ) <EOL> self . router . filter ( r'<STR_LIT>' , '<STR_LIT>' , regexp_flags = <NUM_LIT:0> ) <EOL> self . router . filter ( r'<STR_LIT>' , '<STR_LIT>' ) <EOL> def test1_basic ( self ) : <EOL> self . assertRoute ( '<STR_LIT:/>' , '<STR_LIT:/>' ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test2_filtered ( self ) : <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test3_non_delegating ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> def test4_delegating ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test5_renamed ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> def test6_hidden ( self ) : <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> def test7_protected_on_Controller ( self ) : <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> def test8_explicitly_named_args ( self ) : <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> def test9_special_builtins ( self ) : <EOL> special_names = Controller . special_methods ( ) . keys ( ) <EOL> not_found_tests = [ ] <EOL> for name in special_names : <EOL> not_found_tests . append ( ( '<STR_LIT>' % name , http . NotFound ) ) <EOL> dest , args , params = self . router ( '<STR_LIT:GET>' , URL ( '<STR_LIT>' % name ) , [ ] , { } ) <EOL> self . assertTrue ( dest ( ) ) <EOL> self . assertRoutes ( * not_found_tests ) <EOL> def test10_params ( self ) : <EOL> self . assertRoute ( '<STR_LIT>' , http . BadRequest ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT:user>' : '<STR_LIT>' } ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRoute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRoute ( '<STR_LIT>' , http . NotFound ) <EOL> def assertRoutes ( self , router = None , * urls ) : <EOL> for t in urls : <EOL> self . assertRoute ( * t ) <EOL> def assertRoute ( self , url , expected_return , params = { } , router = None , method = '<STR_LIT:GET>' ) : <EOL> if router is None : <EOL> r = self . router <EOL> else : <EOL> r = router <EOL> url = URL ( url ) <EOL> if echo : <EOL> print '<STR_LIT>' % ( url , expected_return , params ) <EOL> dest , args , params = r ( method , url , [ ] , params ) <EOL> if isinstance ( expected_return , http . Status ) : <EOL> try : <EOL> dest_returned = dest ( ) <EOL> assert r == <NUM_LIT:0> , '<STR_LIT>' '<STR_LIT>' % ( expected_return , dest_returned ) <EOL> except http . HTTPExc , e : <EOL> self . assertEquals ( e . status . __class__ , expected_return . __class__ , '<STR_LIT>' % ( expected_return , id ( expected_return ) , e . status , id ( e . status ) ) ) <EOL> except AssertionError : <EOL> raise <EOL> except Exception , e : <EOL> assert <NUM_LIT:0> , '<STR_LIT>' % ( expected_return , e ) <EOL> else : <EOL> if dest is not None : <EOL> if echo : <EOL> print '<STR_LIT>' % ( dest , args , params ) <EOL> returned = dest ( * args , ** params ) <EOL> else : <EOL> returned = Nothing <EOL> assert returned == expected_return , '<STR_LIT>' % ( returned , expected_return ) <EOL> def suite ( ) : <EOL> return unittest . TestSuite ( [ <EOL> unittest . makeSuite ( RoutingTests ) , <EOL> ] ) <EOL> def test ( ) : <EOL> runner = unittest . TextTestRunner ( ) <EOL> return runner . run ( suite ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test ( ) </s>
