コード例 #1
0
    def test_widget_base_custom_css(self):
        from plone.app.z3cform.widget import BaseWidget
        from plone.app.widgets.base import InputWidget

        widget = BaseWidget(self.request)
        widget.field = self.field
        widget.pattern = 'example'
        widget.klass = 'very-custom-class'
        widget._base = InputWidget

        self.assertEqual(
            '<input class="pat-example very-custom-class" type="text"/>',
            widget.render())
コード例 #2
0
    def test_widget_pattern_notimplemented(self):
        from plone.app.widgets.utils import NotImplemented

        widget = BaseWidget(self.request)
        widget.field = self.field

        self.assertRaises(NotImplemented, widget._base_args)

        widget.pattern = 'example'

        self.assertEqual({
            'pattern': 'example',
            'pattern_options': {}
        }, widget._base_args())
コード例 #3
0
    def test_widget_base_notimplemented(self):
        from plone.app.z3cform.widget import BaseWidget
        from plone.app.widgets.base import InputWidget
        from plone.app.widgets.utils import NotImplemented

        widget = BaseWidget(self.request)
        widget.field = self.field
        widget.pattern = 'example'

        self.assertRaises(NotImplemented, widget.render)

        widget._base = InputWidget

        self.assertEqual('<input class="pat-example" type="text"/>',
                         widget.render())
コード例 #4
0
    def test_widget_base_notimplemented(self):
        from plone.app.z3cform.widget import BaseWidget
        from plone.app.widgets.base import InputWidget
        from plone.app.widgets.utils import NotImplemented

        widget = BaseWidget(self.request)
        widget.field = self.field
        widget.pattern = 'example'

        self.assertRaises(
            NotImplemented,
            widget.render)

        widget._base = InputWidget

        self.assertEqual(
            '<input class="pat-example" type="text"/>',
            widget.render())
コード例 #5
0
    def test_widget_pattern_notimplemented(self):
        from plone.app.widgets.utils import NotImplemented

        widget = BaseWidget(self.request)
        widget.field = self.field

        self.assertRaises(
            NotImplemented,
            widget._base_args)

        widget.pattern = 'example'

        self.assertEqual(
            {
                'pattern': 'example',
                'pattern_options': {}
            },
            widget._base_args())
コード例 #6
0
    def test_widget_base_pattern_options_with_functions(self):
        from plone.app.z3cform.widget import BaseWidget
        from plone.app.widgets.base import InputWidget

        widget = BaseWidget(self.request)
        widget.context = 'testcontext'
        widget.field = self.field
        widget.pattern = 'example'
        widget._base = InputWidget
        widget.pattern_options = {
            'subdict': {
                'subsubnormal': 789,
                'subsublist': [7, 8, 9, lambda x: x],
                'subsubtuple': (7, 8, 9, lambda x: x),
            }
        }

        self.assertEqual(
            '<input class="pat-example" type="text" '
            'data-pat-example="{&quot;subdict&quot;: '
            '{&quot;subsubtuple&quot;: [7, 8, 9, &quot;testcontext&quot;], '
            '&quot;subsublist&quot;: [7, 8, 9, &quot;testcontext&quot;], '
            '&quot;subsubnormal&quot;: 789}}"/>',
            widget.render())