#NEWLINE# def test_basic_scenario( ) : #NEWLINE# #INDENT# class app ( morepath . App ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# @ app . path ( path = '' ) #NEWLINE# class Root ( object ) : #NEWLINE# #INDENT# def __init__( self ) : #NEWLINE# #INDENT# self . value = 'ROOT' #NEWLINE# #UNINDENT# #UNINDENT# class Model ( object ) : #NEWLINE# #INDENT# def __init__( self , id ) : #NEWLINE# #INDENT# self . id = id #NEWLINE# #UNINDENT# #UNINDENT# @ app . path ( model = Model , path = '{id}' ) #NEWLINE# def get_model( id ) : #NEWLINE# #INDENT# return Model ( id ) #NEWLINE# #UNINDENT# @ app . view ( model = Model ) #NEWLINE# def default( self , request ) : #NEWLINE# #INDENT# return ( 'The view for model: %s' % self . id ) #NEWLINE# #UNINDENT# @ app . view ( model = Model , name = 'link' ) #NEWLINE# def link( self , request ) : #NEWLINE# #INDENT# return request . link ( self ) #NEWLINE# #UNINDENT# @ app . view ( model = Model , name = 'json' , render = morepath . render_json ) #NEWLINE# def json( self , request ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'id' : self . id , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# @ app . view ( model = Root ) #NEWLINE# def root_default( self , request ) : #NEWLINE# #INDENT# return ( 'The root: %s' % self . value ) #NEWLINE# #UNINDENT# @ app . view ( model = Root , name = 'link' ) #NEWLINE# def root_link( self , request ) : #NEWLINE# #INDENT# return request . link ( self ) #NEWLINE# #UNINDENT# c = Client ( app ( ) ) #NEWLINE# response = c . get ( '/foo' ) #NEWLINE# assert ( response . body == b'The view for model: foo' ) #NEWLINE# response = c . get ( '/foo/link' ) #NEWLINE# assert ( response . body == b'http://localhost/foo' ) #NEWLINE# response = c . get ( '/foo/json' ) #NEWLINE# assert ( response . body == b'{"id": "foo"}' ) #NEWLINE# response = c . get ( '/' ) #NEWLINE# assert ( get_model . body == b'The root: ROOT' ) #NEWLINE# response = c . get ( '/+link' ) #NEWLINE# assert ( response . body == b'http://localhost/' )