def test_layout_for_route(self): from ptah.layout import query_layout, LayoutRenderer self.config.add_route('test-route', '/test/', use_global_views=False) ptah.register_layout('test', route_name='test-route') self.init_ptah() layout, context = query_layout(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(Context(), self.request, 'test') self.assertIsNotNone(layout)
def test_layout_for_route(self): from ptah.layout import query_layout, LayoutRenderer self.config.add_route('test-route', '/test/', use_global_views=False) ptah.register_layout('test', route_name='test-route') self.init_ptah() layout, context = query_layout(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(Context(), self.request, 'test') self.assertIsNotNone(layout)
def test_layout_root(self): from ptah.layout import query_layout class Root1(object): pass class Root2(object): pass ptah.layout.register('test', root=Root1) self.init_ptah() 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_register_simple(self): from ptah.layout import query_layout ptah.register_layout('test') self.init_ptah() layout, context = query_layout(object(), self.request, 'test') self.assertEqual(layout.name, 'test') self.assertIs(layout.original, ptah.View)
def test_layout_register_custom_class(self): from ptah.layout import query_layout class MyLayout(ptah.View): pass ptah.register_layout('test', view=MyLayout) self.init_ptah() layout, context = query_layout(object(), self.request, 'test') self.assertIs(layout.original, MyLayout)
def test_layout_for_route_global_views(self): from ptah.layout import query_layout self.config.add_route('test-route', '/test/', use_global_views=False) ptah.layout.register('test', use_global_views=True) self.init_ptah() request_iface = self.registry.getUtility( IRouteRequest, name='test-route') self.request.request_iface = request_iface layout, context = query_layout(object(), object(), self.request, 'test') self.assertIsNotNone(layout)
def test_layout_simple_notfound(self): from ptah.layout import query_layout v = ptah.View(Context(Context()), self.request) layout, context = query_layout(v.context, self.request, 'test') self.assertTrue(layout is None)