Esempio n. 1
0
    def test_layout_renderer_layout_info(self):
        from player.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)
Esempio n. 2
0
    def test_layout_renderer_no_layouts(self, m):
        from player.layout_impl import LayoutRenderer
        m.return_value = []
        rendr = LayoutRenderer('test')

        o = object()
        res = rendr(o, Context(), self.request)

        self.assertIs(res, o)
Esempio n. 3
0
    def test_layout_renderer_layout_debug(self):
        from player.layout_impl import LayoutRenderer
        self.config.add_layout('test',
                               view=View,
                               renderer='player:tests/test-layout.jinja2')
        self.request.__layout_debug__ = True

        rendr = LayoutRenderer('test')
        res = rendr('<h1>text</h1>', Context(), self.request)

        self.assertIn('<!-- layout:', str(res))
        self.assertIn('<h1>text</h1>', str(res))
Esempio n. 4
0
    def test_layout_simple_declarative(self):
        from player.layout_impl import LayoutRenderer

        class Layout(View):
            def __call__(self):
                return None

        self.config.add_layout('test',
                               context=Context,
                               renderer='player:tests/test-layout-html.jinja2')

        renderer = LayoutRenderer('test')
        res = renderer('View: test', Context(), self.request)
        self.assertEqual(res.strip(), '<html>View: test</html>')
Esempio n. 5
0
    def test_layout_chain_parent_notfound(self):
        self.config.add_layout('',
                               context=Context,
                               parent='page',
                               renderer='player:tests/test-layout.jinja2')

        root = Root()
        context = Context(root)

        from player.layout_impl import LayoutRenderer
        renderer = LayoutRenderer('')

        res = renderer('View: test', context, self.request)
        self.assertTrue('<div>View: test</div>' in text_(res))
Esempio n. 6
0
    def test_layout_simple_chain_multi_level(self):
        from player.layout_impl import LayoutRenderer

        self.config.add_layout('test',
                               parent='.',
                               renderer='player:tests/test-layout.jinja2')
        self.config.add_layout('',
                               context=Root,
                               parent=None,
                               renderer='player:tests/test-layout-html.jinja2')

        root = Root()
        context = Context(root)
        renderer = LayoutRenderer('test')

        res = renderer('View: test', context, self.request)
        self.assertIn('<html><div>View: test</div></html>', text_(res))
Esempio n. 7
0
    def test_layout_chain_same_layer_id_on_different_levels(self):
        from player.layout_impl import LayoutRenderer

        self.config.add_layout('',
                               context=Context,
                               parent='.',
                               renderer='player:tests/test-layout.jinja2')
        self.config.add_layout('',
                               context=Root,
                               parent=None,
                               renderer='player:tests/test-layout-html.jinja2')

        root = Root()
        context1 = Context2(root)
        context2 = Context(context1)
        renderer = LayoutRenderer('')

        res = renderer('View: test', context2, self.request)
        self.assertIn('<html><div>View: test</div></html>', text_(res))
Esempio n. 8
0
    def test_layout_renderer_layout_info(self):
        from player.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)