[Zope3-checkins] SVN: Zope3/trunk/ Update CHANGES.txt, added note about error handling

Roger Ineichen roger at projekt01.ch
Sun Apr 30 20:06:05 EDT 2006


Log message for revision 67774:
  Update CHANGES.txt, added note about error handling
  Added tests for improved error handling

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/formlib/tests.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2006-04-30 22:47:53 UTC (rev 67773)
+++ Zope3/trunk/doc/CHANGES.txt	2006-05-01 00:06:04 UTC (rev 67774)
@@ -91,6 +91,11 @@
 
     Bug Fixes
 
+      - Fixed error handling in sequence item input widget. This widget
+        was raising a ValidationError instead a WidgetInputError. The formlib
+        didn't catch ValidationErrors. Added also ValidationError handling to
+        the formlib as a fallback for broken widget implementations.
+
       - Fixed issue 590: zope.app.mail could send multiple copies of emails on
         ConflictErrors, and it was also rate limited to 1 email per second when
         you used QueuedMailDelivery.

Modified: Zope3/trunk/src/zope/formlib/tests.py
===================================================================
--- Zope3/trunk/src/zope/formlib/tests.py	2006-04-30 22:47:53 UTC (rev 67773)
+++ Zope3/trunk/src/zope/formlib/tests.py	2006-05-01 00:06:04 UTC (rev 67774)
@@ -257,6 +257,58 @@
 """
 
 
+def test_error_handling():
+    """\
+
+Let's test the getWidgetsData method which is responsible for handling widget
+erros raised by the widgets getInputValue method.
+
+    >>> from zope.interface import implements
+    >>> from zope.app.form.interfaces import IInputWidget
+    >>> class Widget(object):
+    ...     implements(IInputWidget)
+    ...     def __init__(self):
+    ...         self.name = 'form.summary'
+    ...         self.label = 'Summary'
+    ...     def hasInput(self):
+    ...         return True
+    ...     def getInputValue(self):
+    ...         raise zope.app.form.interfaces.WidgetInputError(
+    ...         field_name='summary',
+    ...         widget_title=u'Summary')
+    >>> widget = Widget()
+    >>> inputs = [(True, widget)]
+    >>> widgets = form.Widgets(inputs, 5)
+    >>> errors = form.getWidgetsData(widgets, 'form', {'summary':'value'})
+    >>> errors #doctest: +ELLIPSIS
+    [<zope.app.form.interfaces.WidgetInputError instance at ...>]
+
+Let's see what happens if a widget doesn't convert a ValidationError 
+raised by a field to a WidgetInputError. This should not happen if a widget 
+converts ValidationErrors to WidgetInputErrors. But since I just fixed 
+yesterday the sequence input widget, I decided to catch ValidationError also
+in the formlib as a fallback if some widget doen't handle errors correct. (ri)
+
+    >>> from zope.schema.interfaces import ValidationError
+    >>> class Widget(object):
+    ...     implements(IInputWidget)
+    ...     def __init__(self):
+    ...         self.name = 'form.summary'
+    ...         self.label = 'summary'
+    ...     def hasInput(self):
+    ...         return True
+    ...     def getInputValue(self):
+    ...         raise ValidationError('A error message')
+    >>> widget = Widget()
+    >>> inputs = [(True, widget)]
+    >>> widgets = form.Widgets(inputs, 5)
+    >>> errors = form.getWidgetsData(widgets, 'form', {'summary':'value'})
+    >>> errors #doctest: +ELLIPSIS
+    [<zope.app.form.interfaces.WidgetInputError instance at ...>]
+    
+"""
+
+
 def test_form_template_i18n():
     """\
 Let's try to check that the formlib templates handle i18n correctly.



More information about the Zope3-Checkins mailing list