<s> from morepath . app import App <EOL> from webtest import TestApp as Client <EOL> import morepath <EOL> from morepath import generic <EOL> from reg import KeyIndex <EOL> def setup_module ( module ) : <EOL> morepath . disable_implicit ( ) <EOL> def test_view_predicates ( ) : <EOL> class app ( App ) : <EOL> pass <EOL> @ app . path ( path = '<STR_LIT>' ) <EOL> class Root ( object ) : <EOL> pass <EOL> @ app . view ( model = Root , name = '<STR_LIT:foo>' , request_method = '<STR_LIT:GET>' ) <EOL> def get ( self , request ) : <EOL> return '<STR_LIT:GET>' <EOL> @ app . view ( model = Root , name = '<STR_LIT:foo>' , request_method = '<STR_LIT:POST>' ) <EOL> def post ( self , request ) : <EOL> return '<STR_LIT:POST>' <EOL> c = Client ( app ( ) ) <EOL> response = c . get ( '<STR_LIT>' ) <EOL> assert response . body == b'<STR_LIT:GET>' <EOL> response = c . post ( '<STR_LIT>' ) <EOL> assert response . body == b'<STR_LIT:POST>' <EOL> def test_extra_predicates ( ) : <EOL> class app ( App ) : <EOL> pass <EOL> @ app . path ( path = '<STR_LIT>' ) <EOL> class Model ( object ) : <EOL> def __init__ ( self , id ) : <EOL> self . id = id <EOL> @ app . view ( model = Model , name = '<STR_LIT:foo>' , id = '<STR_LIT:a>' ) <EOL> def get_a ( self , request ) : <EOL> return '<STR_LIT:a>' <EOL> @ app . view ( model = Model , name = '<STR_LIT:foo>' , id = '<STR_LIT:b>' ) <EOL> def get_b ( self , request ) : <EOL> return '<STR_LIT:b>' <EOL> @ app . predicate ( generic . view , name = '<STR_LIT:id>' , default = '<STR_LIT>' , index = KeyIndex , <EOL> after = morepath . request_method_predicate ) <EOL> def id_predicate ( obj ) : <EOL> return obj . id <EOL> c = Client ( app ( ) ) <EOL> response = c . get ( '<STR_LIT>' ) <EOL> assert response . body == b'<STR_LIT:a>' <EOL> response = c . get ( '<STR_LIT>' ) <EOL> assert response . body == b'<STR_LIT:b>' </s>
