def test_view_with_template(self): view.registerView( 'index.html', view.View, Context, template=view.template('memphis.view.tests:templates/test.pt')) self._init_memphis() res = view.renderView('index.html', Context(), self.request) self.assertEqual(res.body, '<div>My pagelet</div>\n')
def test_view_register_view_err1(self): # default 'render' implementation class MyView(view.View): pass view.registerView('index.html', MyView, Context) self._init_memphis() context = Context() self.assertTrue( view.renderView('index.html', context, self.request).content_length ==0)
def test_view_custom_response(self): class MyView(view.View): def render(self): response = self.request.response response.status = '202' return 'test' view.registerView('index.html', MyView, Context) self._init_memphis() res = view.renderView('index.html', Context(), self.request) self.assertEqual(res.status, '202 Accepted') self.assertEqual(res.body, 'test')
def test_view_register_view_layout(self): class MyLayout(view.Layout): def render(self, rendered): return '<html>%s</html>'%rendered class MyView(view.View): def render(self): return 'test' view.registerView('index.html', MyView, Context) view.registerLayout('', Context, klass=MyLayout) self._init_memphis() context = Context() res = view.renderView('index.html', context, self.request) self.assertTrue('<html>test</html>' in res.body)
def test_view_with_decorator(self): def deco(func): def func(context, request): return 'decorator' return func global DecoView @deco class DecoView(view.View): view.pyramidView('index.html', Context) self._init_memphis() res = view.renderView('index.html', Context(), self.request) self.assertEqual(res.body, 'decorator')
def test_view_register_view_disable_layout1(self): class MyLayout(view.Layout): def render(self, rendered): return '<html>%s</html>'%rendered class MyView(view.View): def render(self): return 'test' view.registerView('index.html', MyView, Context, layout=None) view.registerLayout('', Context, klass=MyLayout) self._init_memphis() context = Context() res = view.renderView('index.html', context, self.request) self.assertEqual(res.body, 'test') v = MyView(None, self.request) self.assertEqual(MyLayout(v, self.request).render( v.render()), '<html>test</html>')
def __call__(self): request = self.request if request.subpath: context = self.context name = request.subpath[0] factory = getattr(context, '__factories__', {}).get(name) if factory is None: factory = component.queryAdapter( context, interfaces.IFactory, name=name) if factory is None: for pname, provider in \ getAdapters((context,), interfaces.IFactoryProvider): factory = provider.get(name) if factory is not None: break if factory is not None: return view.renderView( '', LocationProxy(factory, context, name), request) raise NotFound