def test_data_converter_tuple(self): from plone.app.z3cform.widget import AjaxSelectWidget from plone.app.z3cform.converters import AjaxSelectWidgetConverter field = Tuple(__name__='tuplefield', value_type=TextLine()) widget = AjaxSelectWidget(self.request) widget.field = field converter = AjaxSelectWidgetConverter(field, widget) self.assertEqual( converter.toFieldValue(''), field.missing_value, ) self.assertEqual( converter.toFieldValue('123;456;789'), ('123', '456', '789'), ) self.assertEqual( converter.toWidgetValue(tuple()), None, ) self.assertEqual( converter.toWidgetValue(('123', '456', '789')), '123;456;789', )
def test_widget_tuple_orderable(self): from plone.app.z3cform.widget import AjaxSelectWidget widget = AjaxSelectWidget(self.request) widget.field = Tuple(__name__='selectfield') self.assertEqual( { 'name': None, 'value': u'', 'pattern': 'select2', 'pattern_options': {'orderable': True, 'separator': ';'}, }, widget._base_args(), )
def test_widget_choice(self): from plone.app.z3cform.widget import AjaxSelectWidget from zope.schema.interfaces import ISource widget = AjaxSelectWidget(self.request) source = Mock() alsoProvides(source, ISource) widget.field = Choice(__name__='choicefield', source=source) widget.name = 'choicefield' self.assertEqual( { 'name': 'choicefield', 'value': u'', 'pattern': 'select2', 'pattern_options': { 'separator': ';', 'maximumSelectionSize': 1, 'vocabularyUrl': 'http://127.0.0.1/++widget++choicefield/@@getSource', }, }, widget._base_args(), )
def test_widget_choice(self): from plone.app.z3cform.widget import AjaxSelectWidget from zope.schema.interfaces import ISource widget = AjaxSelectWidget(self.request) source = Mock() alsoProvides(source, ISource) widget.field = Choice(__name__='choicefield', source=source) widget.name = 'choicefield' self.assertEqual( { 'name': 'choicefield', 'value': u'', 'pattern': 'select2', 'pattern_options': { 'separator': ';', 'maximumSelectionSize': 1, 'allowNewItems': 'false', 'vocabularyUrl': 'http://127.0.0.1/++widget++choicefield/@@getSource', }, }, widget._base_args(), )