def test_layout_chain_same_layer_id_on_different_levels(self): class View(view.View): def render(self): return "View: test" class Layout1(view.Layout): def render(self, content): return "<div>%s</div>" % content class Layout2(view.Layout): def render(self, content): return "<html>%s</html>" % content view.register_layout("", klass=Layout1, context=Context, parent=".") view.register_layout("", klass=Layout2, context=Root, parent=None) self._init_ptah() root = Root() context1 = Context2(root) context2 = Context(context1) renderer = SimpleRenderer() res = renderer(context2, self.request, viewMapper(View, "render")) self.assertTrue("<html><div>View: test</div></html>" in res.body)
def test_layout_simple_chain_multi_level(self): class View(view.View): def render(self): return "View: test" class LayoutTest(view.Layout): def render(self, content): return "<div>%s</div>" % content class LayoutPage(view.Layout): def render(self, content): return "<html>%s</html>" % content view.register_layout("", klass=LayoutPage, context=Root, parent=None) view.register_layout("test", klass=LayoutTest, parent=".") self._init_ptah() root = Root() context = Context(root) v = View(context, self.request) renderer = SimpleRenderer("test") res = renderer(context, self.request, viewMapper(View, "render")) self.assertTrue("<html><div>View: test</div></html>" in res.body) layout = query_layout(self.request, v.context, "test") self.assertTrue(isinstance(layout, LayoutTest)) rootlayout = query_layout(self.request, context, "") self.assertTrue(isinstance(rootlayout, LayoutPage)) rootlayout = query_layout(self.request, root, "") self.assertTrue(isinstance(rootlayout, LayoutPage))
def test_layout_chain_parent_notfound(self): class View(view.View): def __call__(self): return "View: test" class Layout(view.Layout): def render(self, content): return "<div>%s</div>" % content view.register_layout("", klass=Layout, context=Context, parent="page") self._init_ptah() root = Root() context = Context(root) renderer = SimpleRenderer(layout="") res = renderer(context, self.request, viewMapper(View)) self.assertTrue("<div>View: test</div>" in res.body)
def test_layout_simple_view_with_template(self): class View(view.View): def __call__(self): return "View: test" fn = os.path.join(self.dir, "test.pt") tmpl = open(fn, "wb") tmpl.write("<html>${content}</html>") tmpl.close() view.register_layout("test", template=view.template(fn)) self._init_ptah() renderer = SimpleRenderer(layout="test") context = Context() res = renderer(context, self.request, viewMapper(View)) self.assertTrue("<html>View: test</html>" in res.body)
def test_layout_simple_chain_one_level(self): class View(view.View): def render(self): return "View: test" class LayoutTest(view.Layout): def render(self, content): return "<div>%s</div>" % content class LayoutPage(view.Layout): def render(self, content): return "<html>%s</html>" % content view.register_layout("", klass=LayoutPage, parent=None) view.register_layout("test", klass=LayoutTest, parent=".") self._init_ptah() context = Context() renderer = SimpleRenderer("test") res = renderer(context, self.request, viewMapper(View, "render")) self.assertTrue("<html><div>View: test</div></html>" in res.body)
def test_layout_simple_multilevel(self): class View(view.View): def __call__(self): return "View: test" class Layout(view.Layout): def render(self, content): return "<html>%s</html>" % content view.register_layout("", klass=Layout, context=Root) self._init_ptah() root = Root() context = Context(root) v = View(context, self.request) # find layout for view layout = query_layout(self.request, context, "") self.assertTrue(isinstance(layout, Layout)) renderer = SimpleRenderer(layout="") res = renderer(context, self.request, viewMapper(View)) self.assertTrue("<html>View: test</html>" in res.body)