def test_query_layout_no_request_iface(self): from ptah.renderer.layout_impl import query_layout self.config.add_layout('test') l1 = query_layout(Root(), Context(), self.request, 'test')[0] del self.request.request_iface l2 = query_layout(Root(), Context(), self.request, 'test')[0] self.assertIs(l1, l2)
def test_layout_simple_notfound(self): from ptah.renderer.layout_impl import query_layout v = View(Context(Context()), self.request) layout, context = query_layout(object(), v.context, self.request, 'test') self.assertTrue(layout is None)
def test_layout_renderer_layout_info(self): from ptah.renderer.layout_impl import query_layout, LayoutRenderer self.config.add_layout('test') self.config.add_layout('test2', view=View) rendr = LayoutRenderer('test') l = query_layout(Root(), Context(), self.request, 'test')[0] res = rendr.layout_info(l, Context(), self.request, 'content') self.assertIn('"layout-factory": "None"', res) self.assertIn('content</div>', res) rendr = LayoutRenderer('test2') l = query_layout(Root(), Context(), self.request, 'test2')[0] res = rendr.layout_info(l, Context(), self.request, 'content') self.assertIn('"layout-factory": "test_layout.View"', res)
def test_layout_root(self): from ptah.renderer.layout_impl import query_layout class Root1(object): pass class Root2(object): pass self.config.add_layout('test', root=Root1) layout, context = query_layout(Root1(), object(), self.request, 'test') self.assertIsNotNone(layout) layout, context = query_layout(Root2(), object(), self.request, 'test') self.assertIsNone(layout)
def test_layout_for_route(self): from ptah.renderer.layout_impl import query_layout self.config.add_route('test-route', '/test/', use_global_views=False) self.config.add_layout('test', route_name='test-route', use_global_views=False) layout, context = query_layout(None, Context(), self.request, 'test') self.assertIsNone(layout) request_iface = self.registry.getUtility(IRouteRequest, name='test-route') self.request.request_iface = request_iface layout = query_layout(None, Context(), self.request, 'test') self.assertIsNotNone(layout)
def test_layout_register_simple(self): from ptah.renderer.layout_impl import query_layout self.config.add_layout('test') layout, context = query_layout(object(), object(), self.request, 'test') self.assertEqual(layout.name, 'test') self.assertIs(layout.original, None)
def test_layout_register_custom_class(self): from ptah.renderer.layout_impl import query_layout class MyLayout(object): pass self.config.add_layout('test', view=MyLayout) layout, context = query_layout(object(), object(), self.request, 'test') self.assertIs(layout.original, MyLayout)