Esempio n. 1
0
    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')
Esempio n. 2
0
    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)
Esempio n. 3
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')
Esempio n. 4
0
    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)
Esempio n. 5
0
    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')
Esempio n. 6
0
    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>')
Esempio n. 7
0
    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