[Zope3-checkins] SVN: zope.formlib/trunk/ Improve truth testing for ItemDisplayWidget [LP:159232]
Christian Theune
ct at gocept.com
Sat Apr 24 06:18:55 EDT 2010
Log message for revision 111335:
Improve truth testing for ItemDisplayWidget [LP:159232]
Changed:
U zope.formlib/trunk/CHANGES.txt
U zope.formlib/trunk/src/zope/formlib/itemswidgets.py
U zope.formlib/trunk/src/zope/formlib/tests/test_itemswidget.py
-=-
Modified: zope.formlib/trunk/CHANGES.txt
===================================================================
--- zope.formlib/trunk/CHANGES.txt 2010-04-24 10:13:52 UTC (rev 111334)
+++ zope.formlib/trunk/CHANGES.txt 2010-04-24 10:18:55 UTC (rev 111335)
@@ -5,6 +5,8 @@
4.0.3 (unreleased)
==================
+- Improve truth testing for ItemDisplayWidget [LP:159232]
+
- LP #98491: don't blow up if TypeError raised during token conversion.
4.0.2 (2010-03-07)
Modified: zope.formlib/trunk/src/zope/formlib/itemswidgets.py
===================================================================
--- zope.formlib/trunk/src/zope/formlib/itemswidgets.py 2010-04-24 10:13:52 UTC (rev 111334)
+++ zope.formlib/trunk/src/zope/formlib/itemswidgets.py 2010-04-24 10:18:55 UTC (rev 111335)
@@ -232,7 +232,7 @@
def __call__(self):
"""See IBrowserWidget."""
value = self._getFormValue()
- if not value:
+ if value is None or value == u'':
return self.translate(self._messageNoValue)
else:
term = self.vocabulary.getTerm(value)
Modified: zope.formlib/trunk/src/zope/formlib/tests/test_itemswidget.py
===================================================================
--- zope.formlib/trunk/src/zope/formlib/tests/test_itemswidget.py 2010-04-24 10:13:52 UTC (rev 111334)
+++ zope.formlib/trunk/src/zope/formlib/tests/test_itemswidget.py 2010-04-24 10:18:55 UTC (rev 111335)
@@ -148,6 +148,39 @@
ConversionError, widget._toFieldValue, ['token1', 'token2'])
+containerVocab = SimpleVocabulary(
+ [SimpleTerm(value, token, title) for value, token, title in (
+ ((), 'container1', 'Container One'),
+ ((1,), 'container2', 'Container Two'),
+ ((2,), 'container3', 'Container Three'))])
+
+class ITestContainer(Interface):
+ container = Choice(
+ title=u"Container",
+ description=u"The container",
+ vocabulary=containerVocab,
+ required=True)
+
+class TestContainer(object):
+ implements(ITestContainer)
+
+ def __init__(self, container=None):
+ self.container = container
+
+class ContainerItemDisplayWidgetTest(VerifyResults,
+ PlacelessSetup,
+ unittest.TestCase):
+ def test_handle_empty_containers(self):
+ # Regression test for bug 159232"""
+ field = ITestContainer.get('container')
+
+ request = TestRequest(form={'field.container': 'container1'})
+ container = TestContainer()
+ bound = field.bind(container)
+ widget = ItemDisplayWidget(bound, field.vocabulary, request)
+
+ self.assertEqual(widget(), 'Container One')
+
class ItemsMultiDisplayWidgetTest(ItemsWidgetBaseTest):
_widget = ItemsMultiDisplayWidget
@@ -590,6 +623,7 @@
def test_suite():
suite = unittest.makeSuite(ItemDisplayWidgetTest)
+ suite.addTest(unittest.makeSuite(ContainerItemDisplayWidgetTest))
suite.addTest(unittest.makeSuite(ItemsMultiDisplayWidgetTest))
suite.addTest(unittest.makeSuite(ListDisplayWidgetTest))
suite.addTest(unittest.makeSuite(SetDisplayWidgetTest))
More information about the Zope3-Checkins
mailing list