def test_multiple_selection(self): """The pattern_options key maximumSelectionSize shouldn't be set when the field allows multiple selections""" from plone.app.z3cform.widget import RelatedItemsFieldWidget from zope.schema.interfaces import ISource from zope.schema.vocabulary import VocabularyRegistry context = Mock(absolute_url=lambda: 'fake_url', getPhysicalPath=lambda: ['', 'site']) field = List( __name__='selectfield', value_type=Choice(vocabulary='foobar') ) widget = RelatedItemsFieldWidget(field, self.request) widget.context = context vocab = Mock() alsoProvides(vocab, ISource) with mock.patch.object(VocabularyRegistry, 'get', return_value=vocab): widget.update() base_args = widget._base_args() patterns_options = base_args['pattern_options'] self.assertFalse('maximumSelectionSize' in patterns_options) self.assertEqual( patterns_options['vocabularyUrl'], '/@@getVocabulary?name=foobar&field=selectfield', )
def test_single_selection(self): """The pattern_options value for maximumSelectionSize should be 1 when the field only allows a single selection.""" from plone.app.z3cform.widget import RelatedItemsFieldWidget context = Mock(absolute_url=lambda: 'fake_url', getPhysicalPath=lambda: ['', 'site']) field = Choice( __name__='selectfield', values=['one', 'two', 'three'], ) widget = RelatedItemsFieldWidget(field, self.request) widget.context = context widget.update() base_args = widget._base_args() pattern_options = base_args['pattern_options'] self.assertEqual(pattern_options.get('maximumSelectionSize', 0), 1)
def test_single_selection(self): """The pattern_options value for maximumSelectionSize should be 1 when the field only allows a single selection.""" from plone.app.z3cform.widget import RelatedItemsFieldWidget with patch('plone.app.widgets.utils.getToolByName') as mock_method: context = Mock(absolute_url=lambda: 'fake_url') props = Mock() props.site_properties.getProperty.return_value = ['SomeType'] mock_method.return_value = props field = Choice( __name__='selectfield', values=['one', 'two', 'three'], ) widget = RelatedItemsFieldWidget(field, self.request) widget.context = context widget.update() base_args = widget._base_args() pattern_options = base_args['pattern_options'] self.assertEquals(pattern_options.get('maximumSelectionSize', 0), 1)
def test_fieldwidget(self): from plone.app.z3cform.widget import RelatedItemsWidget from plone.app.z3cform.widget import RelatedItemsFieldWidget field = Mock(__name__='field', title=u'', required=True) vocabulary = Mock() request = Mock() widget = RelatedItemsFieldWidget(field, vocabulary, request) self.assertTrue(isinstance(widget, RelatedItemsWidget)) self.assertIs(widget.field, field) self.assertIs(widget.request, request)
def test_multiple_selection(self): """The pattern_options key maximumSelectionSize shouldn't be set when the field allows multiple selections""" from plone.app.z3cform.widget import RelatedItemsFieldWidget from zope.schema.interfaces import ISource from zope.schema.vocabulary import VocabularyRegistry context = Mock(absolute_url=lambda: 'fake_url') context.portal_properties.site_properties\ .getProperty.return_value = ['SomeType'] field = List(__name__='selectfield', value_type=Choice(vocabulary='foobar')) widget = RelatedItemsFieldWidget(field, self.request) widget.context = context vocab = Mock() alsoProvides(vocab, ISource) with mock.patch.object(VocabularyRegistry, 'get', return_value=vocab): widget.update() base_args = widget._base_args() patterns_options = base_args['pattern_options'] self.assertFalse('maximumSelectionSize' in patterns_options) self.assertEqual( patterns_options['vocabularyUrl'], '/@@getVocabulary?name=foobar&field=selectfield', )
def test_single_selection(self): """The pattern_options value for maximumSelectionSize should be 1 when the field only allows a single selection.""" from plone.app.z3cform.widget import RelatedItemsFieldWidget context = Mock(absolute_url=lambda: 'fake_url', getPhysicalPath=lambda: ['', 'site']) field = Choice( __name__='selectfield', values=['one', 'two', 'three'], ) widget = RelatedItemsFieldWidget(field, self.request) widget.context = context widget.update() base_args = widget._base_args() pattern_options = base_args['pattern_options'] self.assertEquals(pattern_options.get('maximumSelectionSize', 0), 1)
def test_single_selection(self): """The pattern_options value for maximumSelectionSize should be 1 when the field only allows a single selection.""" from plone.app.z3cform.widget import RelatedItemsFieldWidget with patch('plone.app.widgets.utils.getUtility') as mock_method: context = Mock(absolute_url=lambda: 'fake_url') registry = Mock() registry.get.return_value = [] mock_method.return_value = registry field = Choice( __name__='selectfield', values=['one', 'two', 'three'], ) widget = RelatedItemsFieldWidget(field, self.request) widget.context = context widget.update() base_args = widget._base_args() pattern_options = base_args['pattern_options'] self.assertEquals(pattern_options.get('maximumSelectionSize', 0), 1)