def test_converter_List_of_Choice(self): from plone.app.widgets.dx import RelatedItemsDataConverter field = List() widget = Mock(separator=';') converter = RelatedItemsDataConverter(field, widget) self.assertEqual(converter.toWidgetValue(None), None) self.assertEqual(converter.toWidgetValue(['id1', 'id2']), 'id1;id2') self.assertEqual(converter.toFieldValue(None), None) self.assertEqual(converter.toFieldValue('id1;id2'), ['id1', 'id2'])
def test_converter_List_of_Choice(self): from plone.app.widgets.dx import RelatedItemsDataConverter field = List() widget = Mock(separator=';') converter = RelatedItemsDataConverter(field, widget) self.assertEqual(converter.toWidgetValue(None), None) self.assertEqual( converter.toWidgetValue(['id1', 'id2']), 'id1;id2') self.assertEqual(converter.toFieldValue(None), None) self.assertEqual( converter.toFieldValue('id1;id2'), ['id1', 'id2'])
def test_converter_RelationList(self): from plone.app.widgets.dx import RelatedItemsDataConverter from plone.app.widgets.dx import IRelationList field = List() alsoProvides(field, IRelationList) brain1 = Mock(getObject=Mock(return_value='obj1')) brain2 = Mock(getObject=Mock(return_value='obj2')) portal_catalog = Mock(return_value=[brain1, brain2]) widget = Mock(separator=';') converter = RelatedItemsDataConverter(field, widget) self.assertEqual(converter.toWidgetValue(None), None) with mock.patch('plone.app.widgets.dx.IUUID', side_effect=['id1', 'id2']): self.assertEqual(converter.toWidgetValue(['obj1', 'obj2']), 'id1;id2') self.assertEqual(converter.toFieldValue(None), None) with mock.patch('plone.app.widgets.dx.getToolByName', return_value=portal_catalog): self.assertEqual(converter.toFieldValue('id1;id2'), ['obj1', 'obj2'])
def test_converter_RelationList(self): from plone.app.widgets.dx import RelatedItemsDataConverter from plone.app.widgets.dx import IRelationList field = List() alsoProvides(field, IRelationList) brain1 = Mock(getObject=Mock(return_value='obj1')) brain2 = Mock(getObject=Mock(return_value='obj2')) portal_catalog = Mock(return_value=[brain1, brain2]) widget = Mock(separator=';') converter = RelatedItemsDataConverter(field, widget) self.assertEqual(converter.toWidgetValue(None), None) with mock.patch( 'plone.app.widgets.dx.IUUID', side_effect=['id1', 'id2']): self.assertEqual( converter.toWidgetValue(['obj1', 'obj2']), 'id1;id2') self.assertEqual(converter.toFieldValue(None), None) with mock.patch( 'plone.app.widgets.dx.getToolByName', return_value=portal_catalog): self.assertEqual( converter.toFieldValue('id1;id2'), ['obj1', 'obj2'])