[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - test_browserwidget.py:1.13.2.1 test_checkboxwidget.py:1.8.14.1 test_datetimewidget.py:1.1.32.1 test_editview.py:1.12.2.1 test_floatwidget.py:1.1.42.1 test_intwidget.py:1.1.42.1 test_objectwidget.py:1.1.2.1 test_sequencewidget.py:1.3.2.1 test_vocabularywidget.py:1.23.14.1

Garrett Smith garrett@mojave-corp.com
Tue, 22 Jul 2003 09:01:16 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv26193/src/zope/app/browser/form/tests

Modified Files:
      Tag: garrett-widgets-branch
	test_browserwidget.py test_checkboxwidget.py 
	test_datetimewidget.py test_editview.py test_floatwidget.py 
	test_intwidget.py test_objectwidget.py test_sequencewidget.py 
	test_vocabularywidget.py 
Log Message:
CVS: ----------------------------------------------------------------------
CVS: Enter Log.  Lines beginning with `CVS:' are removed automatically
CVS: 
CVS: Committing in .
CVS: 
CVS: Modified Files:
CVS:  Tag: garrett-widgets-branch
CVS: 	src/zope/app/browser/cache/cacheable.py 
CVS: 	src/zope/app/browser/component/interfacewidget.py 
CVS: 	src/zope/app/browser/component/tests/test_interfacewidget.py 
CVS: 	src/zope/app/browser/form/editview.py 
CVS: 	src/zope/app/browser/form/vocabularywidget.py 
CVS: 	src/zope/app/browser/form/widget.py 
CVS: 	src/zope/app/browser/form/tests/test_browserwidget.py 
CVS: 	src/zope/app/browser/form/tests/test_checkboxwidget.py 
CVS: 	src/zope/app/browser/form/tests/test_datetimewidget.py 
CVS: 	src/zope/app/browser/form/tests/test_editview.py 
CVS: 	src/zope/app/browser/form/tests/test_floatwidget.py 
CVS: 	src/zope/app/browser/form/tests/test_intwidget.py 
CVS: 	src/zope/app/browser/form/tests/test_objectwidget.py 
CVS: 	src/zope/app/browser/form/tests/test_sequencewidget.py 
CVS: 	src/zope/app/browser/form/tests/test_vocabularywidget.py 
CVS: 	src/zope/app/browser/security/permissionwidget.py 
CVS: 	src/zope/app/browser/services/field.py 
CVS: 	src/zope/app/browser/services/registration/__init__.py 
CVS: 	src/zope/app/browser/services/tests/test_field_widget.py 
CVS: 	src/zope/app/browser/skins/rotterdam/editingwidgets.py 
CVS: 	src/zope/app/dav/configure.zcml src/zope/app/dav/widget.py 
CVS: 	src/zope/app/form/utility.py src/zope/app/form/widget.py 
CVS: 	src/zope/app/form/tests/test_utility.py 
CVS: 	src/zope/app/form/tests/test_widget_geddon_deprecations.py 
CVS: 	src/zope/app/interfaces/form.py 
CVS: 	src/zope/schema/_bootstrapfields.py 
CVS: ----------------------------------------------------------------------
Several changes related to widgets:

- Changed haveData to hasData.

- Propogated the use of Field.missing_value as an alternative to
  explicit checks for None and '' (empty string).

- Changed the default implementation of hasData (was haveData) to return
  True only if the one of the following was true:

  - setData had been called for the widget. Per IWidget, values passed to
    setData override all other data sources for a widget.

  - There is a value in the request form that corresponds to the widget
    field.

  Prior to this change, hasData would return False if the widget's data
  equaled the field's missing value. E.g., a text widget with an empty
  string would return False, indicating that it has no data, even though
  the empty string, a legitmate value, was submitted in the request.

  This change required a handful of other changes to reflect the new
  logic.

  The bulk of this change effected widget.py. To see how the new logic
  implementation of hasData effected widgets, see test_browserwidget.py
  and test_utility.py.

- Modified the update logic for objects to skip fields that are not
  present in the request form. Prior to this change, unspecified values
  (i.e. values not in the request form) would cause default values to be
  set for corresponding object fields.

- Exposed missing_value in initializer for Field - developers can now
  specify a missing value for a schema field.

- Changed the default implementation of field validation. Prior to this
  change, validation failed if a required value was missing. Now validation 
  is limited to validating non-missing values and the check for required
  values is performed elsewhere.

- Text fields have a missing_value of '' (empty string) instead of None.

- Widget related error classes have been revamped:

  - WidgetInputError, the base class for all widget related errors, now
    provides two attributes: widget, the widget associated with the
    error, and error_msg, a string describing the error,

  - WidgetInputError implements 'args' so it can be rendered like other
    errors.

  - MissingInputError uses a standard error message.

  - All uses of WidgetInputError and its subclasses have been updated
    to use the new class.

- Deleted class zope.app.browser.form.widget.PossiblyEmptyMeansMissing.
  This capability is now handled by setting a field's missing_value to '' 
  (empty string).

- Changed widget's _showData:

  - Renamed to getUnconvertedData to clarify the method meaning and signal
    its use as a public method.

  - Positioned the method as a complement to getData, which returns data
    in its converted form. getUnconvertedData returns data in its
    unconvereted form using _unconvert.

- Renamed the 'force' argument used in various setUpWidget methods in 
  utility.py to 'ignore_unspecified'. This argument is set to True to
  ensure that fields that are not in a form are not used to update their
  corresponding widget. This argument should be true during object
  updates (see editview.py) to ensure that unspecified fields are not
  updated.

- Removed the 'strict' argument from applyWidgetChanges since no one was
  using it and there's no clear application for it.
  



=== Zope3/src/zope/app/browser/form/tests/test_browserwidget.py 1.13 => 1.13.2.1 ===
--- Zope3/src/zope/app/browser/form/tests/test_browserwidget.py:1.13	Sun Jul 13 02:47:18 2003
+++ Zope3/src/zope/app/browser/form/tests/test_browserwidget.py	Tue Jul 22 09:00:37 2003
@@ -59,10 +59,10 @@
         self._widget.context.required = True
         self.failUnless(self._widget.required)
 
-    def test_haveData(self):
-        self.failUnless(self._widget.haveData())
+    def test_hasData(self):
+        self.failUnless(self._widget.hasData())
         del self._widget.request.form['field.foo']
-        self.failIf(self._widget.haveData())
+        self.failIf(self._widget.hasData())
 
     def testProperties(self):
         self.assertEqual(self._widget.getValue('tag'), 'input')
@@ -109,14 +109,14 @@
 
     def _convert(self, v):
         if v == u'barf!':
-            raise ConversionError('ralph')
-        return v or None
+            raise ConversionError(self, 'ralph')
+        return v or self.context.missing_value
 
 class Test(BrowserWidgetTest):
 
     _WidgetFactory = TestWidget
 
-    def test_showData(self):
+    def test_getUnconvertedData(self):
 
         class W(BrowserWidget):
             def _convert(self, v):
@@ -129,46 +129,54 @@
         request = TestRequest()
 
         w = W(field, request)
-        self.assertEqual(w._showData(), '')
+
+        # nothing to unconvert at this point, return field.default
+        self.assertEqual(w.getUnconvertedData(), field.default)
+
+        # provide data in form -- should return as-is
         request.form['field.foo'] = 'val'
-        self.assertEqual(w._showData(), 'val')
+        self.assertEqual(w.getUnconvertedData(), 'val')
 
+        # override data using setData -- should employ _convert
         w.setData('Xfoo')
-        self.assertEqual(w._showData(), 'foo')
+        self.assertEqual(w.getUnconvertedData(), 'foo')
 
     def test_getData(self):
         self.assertEqual(self._widget.getData(), u'Foo Value')
 
+        # test WidgetInputError
         self._widget.request.form['field.foo'] = (1, 2)
         self.assertRaises(WidgetInputError, self._widget.getData)
 
+        # test ConversionError
         self._widget.request.form['field.foo'] = u'barf!'
         self.assertRaises(ConversionError, self._widget.getData)
 
-        del self._widget.request.form['field.foo']        
-        self._widget.context.required = True
-        self.assertEqual(self._widget.getData(optional=1), None)
-        self.assertRaises(MissingInputError, self._widget.getData)
-
-        self._widget.context.required = False
-        self.assertEqual(self._widget.getData(optional=1), None)
-        self.assertEqual(self._widget.getData(), None)
+        # test 'unspecified'
+        del self._widget.request.form['field.foo']
+        self.assertEqual(self._widget.getData(), self._widget.unspecified)
+
+        # test 'missing'
+        self._widget.request.form['field.foo'] = self._widget._missing
+        self.assertEqual(
+            self._widget.getData(), 
+            self._widget.context.missing_value)
 
     def test_applyChanges(self):
         self.assertEqual(self._widget.applyChanges(self.content), True)
 
-    def test_haveData(self):
-        self.failUnless(self._widget.haveData())
+    def test_hasData(self):
+        self.failUnless(self._widget.hasData())
         del self._widget.request.form['field.foo']
-        self.failIf(self._widget.haveData())
+        self.failIf(self._widget.hasData())
         self._widget.request.form['field.foo'] = u''
-        self.failIf(self._widget.haveData())
+        self.failUnless(self._widget.hasData())
 
-    def test_showData_w_default(self):
+    def test_getUnconvertedData_w_default(self):
         field = Text(__name__ = 'foo', title = u"Foo Title", default=u"def")
         request = TestRequest()
         widget = self._WidgetFactory(field, request)
-        self.assertEqual(widget._showData(), u'def')
+        self.assertEqual(widget.getUnconvertedData(), u'def')
 
 
 def test_suite():


=== Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py 1.8 => 1.8.14.1 ===
--- Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py:1.8	Thu Jun  5 10:23:05 2003
+++ Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py	Tue Jul 22 09:00:37 2003
@@ -56,7 +56,7 @@
         self._widget.request.form['field.foo'] = 'positive'
         self.assertEqual(self._widget.getData(), False)
         del self._widget.request.form['field.foo']
-        self.assertEqual(self._widget.getData(), False)
+        self.assertEqual(self._widget.getData(), self._widget.unspecified)
 
 
 def test_suite():


=== Zope3/src/zope/app/browser/form/tests/test_datetimewidget.py 1.1 => 1.1.32.1 ===
--- Zope3/src/zope/app/browser/form/tests/test_datetimewidget.py:1.1	Wed Mar 26 06:28:53 2003
+++ Zope3/src/zope/app/browser/form/tests/test_datetimewidget.py	Tue Jul 22 09:00:37 2003
@@ -27,18 +27,18 @@
     _FieldFactory = Datetime
     _WidgetFactory = DatetimeWidget
 
-    def test_haveData(self):
+    def test_hasData(self):
         del self._widget.request.form['field.foo']
-        self.failIf(self._widget.haveData())
+        self.failIf(self._widget.hasData())
         self._widget.request.form['field.foo'] = u''
-        self.failIf(self._widget.haveData())
+        self.failUnless(self._widget.hasData())
         self._widget.request.form['field.foo'] = u'2003/03/26 12:00:00'
-        self.failUnless(self._widget.haveData())
+        self.failUnless(self._widget.hasData())
 
     def test_getData(self):
         TEST_DATE= u'2003/03/26 12:00:00'
         self._widget.request.form['field.foo'] = u''
-        self.assertEquals(self._widget.getData(optional=1), None)
+        self.assertEquals(self._widget.getData(), None)
         self._widget.request.form['field.foo'] = TEST_DATE
         self.assertEquals(self._widget.getData(), parseDatetimetz(TEST_DATE))
         self._widget.request.form['field.foo'] = u'abc'


=== Zope3/src/zope/app/browser/form/tests/test_editview.py 1.12 => 1.12.2.1 ===
--- Zope3/src/zope/app/browser/form/tests/test_editview.py:1.12	Sun Jul 13 02:47:18 2003
+++ Zope3/src/zope/app/browser/form/tests/test_editview.py	Tue Jul 22 09:00:37 2003
@@ -124,19 +124,20 @@
     def test_update(self):
         c = C()
         request = TestRequest()
-        v = EV(c, request)
         request.form[Update] = ''
         request.form['field.foo'] = u'r foo'
         request.form['field.bar'] = u'r bar'
         request.form['field.getbaz'] = u'r baz'
         request.form['field.a'] = u'c a'
 
+        v = EV(c, request)
         message = v.update()
+
         self.failUnless(message.startswith('Updated '), message)
         self.assertEqual(c.foo, u'r foo')
         self.assertEqual(c.bar, u'r bar')
         self.assertEqual(c.a  , u'c a')
-        self.assertEqual(c.b  , None)
+        self.assertEqual(c.b  , u'c b') # wasn't in form, value not changed
         self.assertEqual(c.getbaz(), u'r baz')
 
         # Verify that calling update multiple times has no effect


=== Zope3/src/zope/app/browser/form/tests/test_floatwidget.py 1.1 => 1.1.42.1 ===
--- Zope3/src/zope/app/browser/form/tests/test_floatwidget.py:1.1	Mon Jan 20 11:23:38 2003
+++ Zope3/src/zope/app/browser/form/tests/test_floatwidget.py	Tue Jul 22 09:00:37 2003
@@ -26,17 +26,17 @@
     _FieldFactory = Float
     _WidgetFactory = FloatWidget
 
-    def test_haveData(self):
+    def test_hasData(self):
         del self._widget.request.form['field.foo']
-        self.failIf(self._widget.haveData())
+        self.failIf(self._widget.hasData())
         self._widget.request.form['field.foo'] = u''
-        self.failIf(self._widget.haveData())
+        self.failUnless(self._widget.hasData())
         self._widget.request.form['field.foo'] = u'123'
-        self.failUnless(self._widget.haveData())
+        self.failUnless(self._widget.hasData())
 
     def test_getData(self):
         self._widget.request.form['field.foo'] = u''
-        self.assertEquals(self._widget.getData(optional=1), None)
+        self.assertEquals(self._widget.getData(), None)
         self._widget.request.form['field.foo'] = u'123.45'
         self.assertEquals(self._widget.getData(), 123.45)
         self._widget.request.form['field.foo'] = u'abc'


=== Zope3/src/zope/app/browser/form/tests/test_intwidget.py 1.1 => 1.1.42.1 ===
--- Zope3/src/zope/app/browser/form/tests/test_intwidget.py:1.1	Mon Jan 20 11:23:38 2003
+++ Zope3/src/zope/app/browser/form/tests/test_intwidget.py	Tue Jul 22 09:00:37 2003
@@ -26,17 +26,17 @@
     _FieldFactory = Int
     _WidgetFactory = IntWidget
 
-    def test_haveData(self):
+    def test_hasData(self):
         del self._widget.request.form['field.foo']
-        self.failIf(self._widget.haveData())
+        self.failIf(self._widget.hasData())
         self._widget.request.form['field.foo'] = u''
-        self.failIf(self._widget.haveData())
+        self.failUnless(self._widget.hasData())
         self._widget.request.form['field.foo'] = u'123'
-        self.failUnless(self._widget.haveData())
+        self.failUnless(self._widget.hasData())
 
     def test_getData(self):
         self._widget.request.form['field.foo'] = u''
-        self.assertEquals(self._widget.getData(optional=1), None)
+        self.assertEquals(self._widget.getData(), None)
         self._widget.request.form['field.foo'] = u'123'
         self.assertEquals(self._widget.getData(), 123)
         self._widget.request.form['field.foo'] = u'abc'


=== Zope3/src/zope/app/browser/form/tests/test_objectwidget.py 1.1 => 1.1.2.1 ===
--- Zope3/src/zope/app/browser/form/tests/test_objectwidget.py:1.1	Sun Jul 13 02:47:18 2003
+++ Zope3/src/zope/app/browser/form/tests/test_objectwidget.py	Tue Jul 22 09:00:37 2003
@@ -54,7 +54,7 @@
         self.request.form['field.foo'] = u'Foo Value'
         self._widget = self._WidgetFactory(self.field, self.request)
 
-    def test_haveData(self):
+    def test_hasData(self):
         # doesn't work with subfields
         pass
 
@@ -97,7 +97,7 @@
     def test_new(self):
         request = TestRequest()
         widget = ObjectWidget(self.field, request, TestContact)
-        self.assertEquals(int(widget.haveData()), 0)
+        self.assert_(not widget.hasData())
         check_list = (
             'input', 'name="field.foo.name"',
             'input', 'name="field.foo.email"'
@@ -110,7 +110,7 @@
             'field.foo.email': u'fred@fred.com'
             })
         widget = ObjectWidget(self.field, request, TestContact)
-        self.assertEquals(int(widget.haveData()), 1)
+        self.assertEquals(int(widget.hasData()), 1)
         o = widget.getData()
         self.assertEquals(hasattr(o, 'name'), 1)
         self.assertEquals(o.name, u'fred')


=== Zope3/src/zope/app/browser/form/tests/test_sequencewidget.py 1.3 => 1.3.2.1 ===
--- Zope3/src/zope/app/browser/form/tests/test_sequencewidget.py:1.3	Sun Jul 13 02:47:18 2003
+++ Zope3/src/zope/app/browser/form/tests/test_sequencewidget.py	Tue Jul 22 09:00:37 2003
@@ -44,34 +44,34 @@
             value_type=TextLine(__name__=u'bar'))
         provideView(ITextLine, 'edit', IBrowserPresentation, [TextWidget])
 
-    def test_haveNoData(self):
-        self.failIf(self._widget.haveData())
+    def test_hasNoData(self):
+        self.failIf(self._widget.hasData())
 
-    def test_haveData(self):
+    def test_hasData(self):
         self._widget.request.form['field.foo.0.bar'] = u'hi, mum'
-        self.failUnless(self._widget.haveData())
+        self.failUnless(self._widget.hasData())
 
     def test_list(self):
         self.field = List(__name__=u'foo', value_type=TextLine(__name__=u'bar'))
         request = TestRequest()
         widget = ListSequenceWidget(self.field, request)
-        self.assertEquals(int(widget.haveData()), 0)
+        self.assertEquals(int(widget.hasData()), 0)
         self.assertEquals(widget.getData(), [])
 
         request = TestRequest(form={'field.foo.add': u'Add bar'})
         widget = ListSequenceWidget(self.field, request)
-        self.assertEquals(int(widget.haveData()), 1)
+        self.assertEquals(int(widget.hasData()), 1)
         self.assertRaises(ValidationError, widget.getData)
 
         request = TestRequest(form={'field.foo.0.bar': u'Hello world!'})
         widget = ListSequenceWidget(self.field, request)
-        self.assertEquals(int(widget.haveData()), 1)
+        self.assertEquals(int(widget.hasData()), 1)
         self.assertEquals(widget.getData(), [u'Hello world!'])
 
     def test_new(self):
         request = TestRequest()
         widget = TupleSequenceWidget(self.field, request)
-        self.assertEquals(int(widget.haveData()), 0)
+        self.assertEquals(int(widget.hasData()), 0)
         self.assertEquals(widget.getData(), ())
         check_list = ('input', 'name="field.foo.add"')
         self.verifyResult(widget(), check_list)
@@ -79,7 +79,7 @@
     def test_add(self):
         request = TestRequest(form={'field.foo.add': u'Add bar'})
         widget = TupleSequenceWidget(self.field, request)
-        self.assertEquals(int(widget.haveData()), 1)
+        self.assertEquals(int(widget.hasData()), 1)
         self.assertRaises(ValidationError, widget.getData)
         check_list = (
             'checkbox', 'field.foo.remove_0', 'input', 'field.foo.0.bar',
@@ -90,14 +90,14 @@
     def test_request(self):
         request = TestRequest(form={'field.foo.0.bar': u'Hello world!'})
         widget = TupleSequenceWidget(self.field, request)
-        self.assertEquals(int(widget.haveData()), 1)
+        self.assertEquals(int(widget.hasData()), 1)
         self.assertEquals(widget.getData(), (u'Hello world!',))
 
     def test_existing(self):
         request = TestRequest()
         widget = TupleSequenceWidget(self.field, request)
         widget.setData((u'existing',))
-        self.assertEquals(int(widget.haveData()), 1)
+        self.assertEquals(int(widget.hasData()), 1)
         self.assertEquals(widget.getData(), (u'existing',))
         check_list = (
             'checkbox', 'field.foo.remove_0', 'input', 'field.foo.0.bar',
@@ -106,7 +106,7 @@
         )
         self.verifyResult(widget(), check_list, inorder=True)
         widget.setData((u'existing', u'second'))
-        self.assertEquals(int(widget.haveData()), 1)
+        self.assertEquals(int(widget.hasData()), 1)
         self.assertEquals(widget.getData(), (u'existing', u'second'))
         check_list = (
             'checkbox', 'field.foo.remove_0', 'input', 'field.foo.0.bar',


=== Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py 1.23 => 1.23.14.1 ===
--- Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py:1.23	Wed Jun 18 11:09:16 2003
+++ Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py	Tue Jul 22 09:00:37 2003
@@ -247,13 +247,13 @@
         bound = self.makeField()
         request = self.makeRequest('field.f=foobar')
         w = getView(bound, "display", request)
-        self.assert_(w.haveData())
+        self.assert_(w.hasData())
         self.assertEqual(w(), "foobar")
 
     def setup_edit(self, bound):
         w = getView(bound, "edit", self.makeRequest())
         w.setData(bound.context.f)
-        self.assert_(not w.haveData())
+        self.assert_(not w.hasData())
         return w
 
     def test_edit(self, extraChecks=[]):
@@ -311,19 +311,19 @@
         bound = self.makeField()
         request = self.makeRequest('field.f=foobar')
         w = getView(bound, "edit", request)
-        self.assert_(w.haveData())
+        self.assert_(w.hasData())
         self.assertEqual(w.getData(), "foobar")
         self.assert_(isinstance(w, vocabularywidget.VocabularyEditWidget))
 
     def test_edit_with_modified_empty_value(self):
         # This tests that emptying a value via the form when there's a
         # non-empty value for the field on the content object will
-        # report haveData() properly.
+        # report hasData() properly.
         bound = self.makeField()
         bound.context.f = "splat"
         w = getView(bound, "edit", self.makeRequest(
             'field.f-empty-marker='))
-        self.assert_(w.haveData())
+        self.assert_(w.hasData())
         self.assertEqual(w.getData(), None) # XXX might be []...
 
 class SingleSelectionTests(SingleSelectionTestsBase):
@@ -357,7 +357,7 @@
         bound = self.makeField()
         del bound.context.f
         w = getView(bound, "display", self.makeRequest())
-        self.assert_(not w.haveData())
+        self.assert_(not w.hasData())
         self.verifyResult(w(), [
             '<span',
             'id="field.f"',
@@ -369,7 +369,7 @@
         bound = self.makeField(value=["foobar", "frob"])
         w = getView(bound, "display", self.makeRequest())
         w.setData(bound.context.f)
-        self.assert_(not w.haveData())
+        self.assert_(not w.hasData())
         self.verifyResult(w(), [
             '<ol',
             'id="field.f"',
@@ -390,7 +390,7 @@
         bound = self.makeField(value=["foobar", "frob"])
         request = self.makeRequest('field.f:list=splat')
         w = getView(bound, "display", request)
-        self.assert_(w.haveData())
+        self.assert_(w.hasData())
         s = w()
         self.verifyResult(s, [
             '<ol',
@@ -407,7 +407,7 @@
     def test_edit(self):
         bound = self.makeField()
         w = getView(bound, "edit", self.makeRequest())
-        self.assert_(not w.haveData())
+        self.assert_(not w.hasData())
         self.verifyResult(w(), [
             'id="field.f"',
             'name="field.f:list"',
@@ -439,7 +439,7 @@
         bound = self.makeField()
         request = self.makeRequest('field.f:list=foobar&field.f:list=splat')
         w = getView(bound, "edit", request)
-        self.assert_(w.haveData())
+        self.assert_(w.hasData())
         L = w.getData()
         L.sort()
         self.assertEqual(L, ["foobar", "splat"])