def test_data_converter_tuple(self): from plone.app.widgets.dx import SelectWidget from plone.app.widgets.dx import SelectWidgetConverter field = Tuple(__name__='tuplefield', value_type=Choice(__name__='selectfield', values=['one', 'two', 'three'])) widget = SelectWidget(self.request) widget.field = field widget.multiple = True converter = SelectWidgetConverter(field, widget) self.assertEqual( converter.toFieldValue(''), field.missing_value, ) self.assertEqual( converter.toFieldValue('one;two;three'), ('one', 'two', 'three'), ) self.assertEqual( converter.toWidgetValue(tuple()), [], ) self.assertEqual( converter.toWidgetValue(('one', 'two', 'three')), ['one', 'two', 'three'], )
def test_data_converter_handles_empty_value(self): from plone.app.widgets.dx import SelectWidget from plone.app.widgets.dx import SelectWidgetConverter field = Tuple(__name__='tuplefield', value_type=Choice(__name__='selectfield', values=['one', 'two', 'three'])) widget = SelectWidget(self.request) widget.field = field widget.multiple = True converter = SelectWidgetConverter(field, widget) self.assertEqual( converter.toFieldValue((u'',)), field.missing_value, )
def test_data_converter_list(self): from plone.app.widgets.dx import SelectWidget from plone.app.widgets.dx import SelectWidgetConverter field = List(__name__='listfield', value_type=Choice(__name__='selectfield', values=['one', 'two', 'three'])) widget = SelectWidget(self.request) widget.field = field widget.multiple = True converter = SelectWidgetConverter(field, widget) self.assertEqual( converter.toFieldValue(''), field.missing_value, ) self.assertEqual( converter.toFieldValue('one;two;three'), ['one', 'two', 'three'], ) self.assertEqual( converter.toWidgetValue([]), [], ) widget.separator = ',' self.assertEqual( converter.toFieldValue('one,two,three'), ['one', 'two', 'three'], ) self.assertRaises( LookupError, converter.toFieldValue, 'one;two;three' ) self.assertEqual( converter.toWidgetValue(['one', 'two', 'three']), ['one', 'two', 'three'] )