示例#1
0
    def test_pagelet_register_without_class(self):
        view.pageletType('test', Context)
        view.registerPagelet('test', Context)
        self._init_memphis()

        pagelet = config.registry.getMultiAdapter(
            (Context(), self.request), IPagelet, 'test')

        self.assertTrue(isinstance(pagelet, Pagelet))
        self.assertEqual(str(pagelet.__class__),
                         "<class 'memphis.view.pagelet.Pagelet None'>")
示例#2
0
    def test_pagelet_register_errors(self):
        class TestPagelet(view.Pagelet):
            pass

        view.pageletType('test1', Context)
        view.pageletType('test2', Context)

        view.registerPagelet('test1', Context, TestPagelet)
        view.registerPagelet('test2', Context, TestPagelet)

        self.assertRaises(ValueError, self._init_memphis)
示例#3
0
    def test_pagelet_register(self):
        class TestPagelet(view.Pagelet):
            def render(self):
                return 'test pagelet'

        view.pageletType('test', Context)
        view.registerPagelet('test', Context, TestPagelet)
        self._init_memphis()

        self.assertEqual(
            renderPagelet('test', Context(), self.request), 'test pagelet')
示例#4
0
    def test_pagelet_View_pagelet_with_error(self):
        class TestPagelet(view.Pagelet):
            def render(self):
                raise ValueError('Error')

        view.pageletType('test', Context)
        view.registerPagelet('test', Context, TestPagelet)
        self._init_memphis()

        base = view.View(None, self.request)
        self.assertEqual(base.pagelet('test', Context()), '')
示例#5
0
    def test_pagelet_render_with_exception(self):
        class TestPagelet(view.Pagelet):
            def render(self):
                raise ValueError('Unknown')

        view.pageletType('test', Context)
        view.registerPagelet('test', Context, TestPagelet)
        self._init_memphis()

        self.assertRaises(
            ValueError,
            renderPagelet, 'test', Context(), self.request)
示例#6
0
    def test_pagelet_register_with_not_Pagelet_class(self):
        class TestPagelet(object):
            pass

        view.pageletType('test', Context)
        view.registerPagelet('test', Context, TestPagelet)
        self._init_memphis()

        pagelet = config.registry.getMultiAdapter(
            (Context(), self.request), IPagelet, 'test')

        self.assertTrue(isinstance(pagelet, Pagelet))
        self.assertTrue(isinstance(pagelet, TestPagelet))
示例#7
0
    def test_pagelet_register_declarative(self):
        global TestPagelet

        view.pageletType('pt', Context)

        class TestPagelet(view.Pagelet):
            view.pagelet('pt')

            def render(self):
                return 'test'

        self._init_memphis()

        self.assertEqual(renderPagelet('pt', Context(), self.request), 'test')
示例#8
0
    def test_pagelettype_register(self):
        class ITestPagelet(interface.Interface):
            pass

        view.pageletType('test', Context)
        self._init_memphis()

        from memphis.view.pagelet import ptypes

        self.assertTrue('test' in ptypes)

        pt = ptypes['test']
        self.assertTrue(isinstance(pt, PageletType))
        self.assertEqual(pt.name, 'test')
        self.assertEqual(pt.context, Context)
示例#9
0
    def test_pagelet_register_with_template(self):
        class TestPagelet(view.Pagelet):
            pass

        def template(*args, **kw):
            keys = kw.keys()
            keys.sort()
            return '|'.join(keys)

        view.pageletType('test', Context)
        view.registerPagelet('test', klass=TestPagelet, template = template)
        self._init_memphis()

        self.assertEqual(
            renderPagelet('test', Context(), self.request),
            'context|format|request|view')
示例#10
0
    def test_pagelet_render_additional_params_to_template(self):
        class TestPagelet(view.Pagelet):
            def update(self):
                return {'param1': 1, 'param2': 2}

        def template(*args, **kw):
            keys = kw.keys()
            keys.sort()
            return '|'.join(keys)

        view.pageletType('test', Context)
        view.registerPagelet('test', klass=TestPagelet, template = template)
        self._init_memphis()

        self.assertTrue(
            'param1|param2|' in renderPagelet('test', Context(), self.request))
示例#11
0
    def test_pagelet_View_pagelet(self):
        class TestPagelet(view.Pagelet):
            def render(self):
                return 'test pagelet'

        view.pageletType('test', Context)
        view.registerPagelet('test', Context, TestPagelet)
        self._init_memphis()

        base = view.View(None, self.request)

        # pageletType is string
        self.assertEqual(base.pagelet('unknown', Context()), '')
        self.assertEqual(base.pagelet('test', Context()), 'test pagelet')

        # by default use view context
        base.context = Context()
        self.assertEqual(base.pagelet('test'), 'test pagelet')
示例#12
0
文件: form.py 项目: mcdonc/memphis

class DisplayForm(Form):
    interface.implements(IDisplayForm)

    mode = FORM_DISPLAY

    def getParams(self):
        return self.params


FORM_VIEW = "form-view"
FORM_ACTIONS = "form-actions"
FORM_WIDGET = "form-widget"
FORM_DISPLAY_WIDGET = "form-display-widget"

view.pageletType(FORM_VIEW, IForm, "Form view")
view.pageletType(FORM_ACTIONS, IForm, "Form actions")
view.pageletType(FORM_WIDGET, Field, "Form widget")
view.pageletType(FORM_DISPLAY_WIDGET, Field, "Form display widget")

view.registerPagelet("form-view", IInputForm, template=view.template("memphis.form:templates/form.pt"))

view.registerPagelet("form-view", IDisplayForm, template=view.template("memphis.form:templates/form-display.pt"))

view.registerPagelet("form-actions", IInputForm, template=view.template("memphis.form:templates/form-actions.pt"))

view.registerPagelet("form-widget", Field, template=view.template("memphis.form:templates/widget.pt"))

view.registerPagelet("form-display-widget", Field, template=view.template("memphis.form:templates/widget-display.pt"))