[Zope3-checkins] CVS: Zope3/src/zope/app/form/tests - test_utility.py:1.16 test_widget_geddon_deprecations.py:1.2

Garrett Smith garrett at mojave-corp.com
Wed Aug 13 18:29:14 EDT 2003


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

Modified Files:
	test_utility.py test_widget_geddon_deprecations.py 
Log Message:
Made the following changes to the widget machinery:

- Renamed IWidget getData to getInputValue

getInputValue no longer accepts an 'optional' flag. If value is missing or is invalid, getInputValue will raise an error. Calls made to this method should be in a try...except block to handle such conditions.

- Renamed IWidget haveData to hasInput

- Added method hasValidInput to IWidget and widget implementations

- Renamed IWidget setData to setRenderedValue

- Added functional tests for some of the core widgets - additional ftests are needed

- Deleted the class PossibleEmptyMeansMissing - it's no longer needed

- Added deprecation tests for changes to widgets

- Some widgets were refactored to use the new framework correctly

These changes were based on the proposal:

 http://dev.zope.org/Zope3/ComponentArchitecture/WidgetsFormsSchemas

Not all the changes in the proposal are included in this commit. Specifically, getRawData/setRawData and the refactoring of the widget error classes are the two major changes not included in this commit.

=== Zope3/src/zope/app/form/tests/test_utility.py 1.15 => 1.16 ===
--- Zope3/src/zope/app/form/tests/test_utility.py:1.15	Thu Jun  5 16:13:09 2003
+++ Zope3/src/zope/app/form/tests/test_utility.py	Wed Aug 13 17:28:38 2003
@@ -31,7 +31,7 @@
 from zope.app.interfaces.form import WidgetsError
 from zope.app.form.utility import setUpWidget, setUpWidgets, setUpEditWidgets
 from zope.app.form.utility import getWidgetsData, getWidgetsDataForContent
-from zope.app.form.utility import haveWidgetsData
+from zope.app.form.utility import viewHasInput
 from zope.schema.interfaces import ValidationError
 from zope.component.interfaces import IViewFactory
 
@@ -87,7 +87,7 @@
 
 class W(TextWidget):
 
-    def setData(self, v):
+    def setRenderedValue(self, v):
         self.context.validate(v)
         self._data = v
 
@@ -96,14 +96,10 @@
 
     def __call__(self):
         name = self.name
-        v = getattr(self, '_data', None)
-        if (v is None) and (name in self.request):
-            v = self.request[name]
-
-
+        v = self._showData()
         return unicode(self.context.__name__) + u': ' + (v or '')
 
-    def getData(self):
+    def getInputValue(self):
         v = self.request.get(self.name, self)
         if v is self:
             if self.context.required:
@@ -111,7 +107,7 @@
             v = self.context.default
         return v
 
-    def haveData(self):
+    def hasInput(self):
         if self.name in self.request and self.request[self.name]:
             return True
         return False
@@ -130,7 +126,7 @@
         view = BrowserView(c, request)
         setUpWidget(view, 'title', I['title'])
         self.assertEqual(view.title_widget(), u'title: ')
-        self.assertEqual(view.title_widget.getData(), None)
+        self.assertEqual(view.title_widget.getInputValue(), None)
 
 
     def test_setUpWidget_w_request_data(self):
@@ -140,7 +136,7 @@
         view = BrowserView(c, request)
         setUpWidget(view, 'title', I['title'])
         self.assertEqual(view.title_widget(), u'title: xxx')
-        self.assertEqual(view.title_widget.getData(), u'xxx')
+        self.assertEqual(view.title_widget.getInputValue(), u'xxx')
 
     def test_setUpWidget_w_request_data_and_initial_data(self):
         c = C()
@@ -149,7 +145,7 @@
         view = BrowserView(c, request)
         setUpWidget(view, 'title', I['title'], u'yyy')
         self.assertEqual(view.title_widget(), u'title: xxx')
-        self.assertEqual(view.title_widget.getData(), u'xxx')
+        self.assertEqual(view.title_widget.getInputValue(), u'xxx')
 
     def test_setUpWidget_w_request_data_and_initial_data_force(self):
         c = C()
@@ -158,7 +154,7 @@
         view = BrowserView(c, request)
         setUpWidget(view, 'title', I['title'], u'yyy', force=1)
         self.assertEqual(view.title_widget(), u'title: yyy')
-        self.assertEqual(view.title_widget.getData(), u'xxx')
+        self.assertEqual(view.title_widget.getInputValue(), u'xxx')
 
     def test_setUpWidget_w_initial_data(self):
         c = C()
@@ -166,7 +162,7 @@
         view = BrowserView(c, request)
         setUpWidget(view, 'title', I['title'], u'yyy')
         self.assertEqual(view.title_widget(), u'title: yyy')
-        self.assertEqual(view.title_widget.getData(), None)
+        self.assertEqual(view.title_widget.getInputValue(), None)
 
     def test_setUpWidget_w_bad_initial_data(self):
         c = C()
@@ -182,7 +178,7 @@
         view.title_widget = w = W(I['title'], request)
         setUpWidget(view, 'title', I['title'], u'yyy')
         self.assertEqual(view.title_widget(), u'title: yyy')
-        self.assertEqual(view.title_widget.getData(), None)
+        self.assertEqual(view.title_widget.getInputValue(), None)
         self.assertEqual(view.title_widget, w)
 
     def test_setUpWidget_w_Custom_widget(self):
@@ -191,7 +187,7 @@
         view = ViewWithCustomTitleWidgetFactory(c, request)
         setUpWidget(view, 'title', I['title'], u'yyy')
         self.assertEqual(view.title_widget(), u'title: yyy')
-        self.assertEqual(view.title_widget.getData(), None)
+        self.assertEqual(view.title_widget.getInputValue(), None)
         self.assertEqual(view.title_widget.custom, 1)
 
     def test_setupWidgets(self):
@@ -452,28 +448,28 @@
                            exclude_readonly=True),
             {'title': u'ft'})
 
-    def test_haveWidgetsData(self):
+    def test_viewHasInput(self):
         c = C()
         request = TestRequest()
         view = BrowserView(c, request)
         setUpWidgets(view, I, initial=kw(title=u"ttt", description=u"ddd"))
-        self.failIf(haveWidgetsData(view, I))
+        self.failIf(viewHasInput(view, I))
 
         request.form['field.description'] = u'fd'
-        self.failUnless(haveWidgetsData(view, I))
+        self.failUnless(viewHasInput(view, I))
 
-    def test_haveWidgetsData_w_names(self):
+    def test_viewHasInput_w_names(self):
         c = C()
         request = TestRequest()
         view = BrowserView(c, request)
         setUpWidgets(view, I, initial=kw(title=u"ttt", description=u"ddd"))
-        self.failIf(haveWidgetsData(view, I))
+        self.failIf(viewHasInput(view, I))
 
         request.form['field.description'] = u'fd'
-        self.failUnless(haveWidgetsData(view, I))
-        self.failIf(haveWidgetsData(view, I, names=['title']))
-        self.assertRaises(KeyError, haveWidgetsData, view, I, names=['bar'])
-        self.assertRaises(AttributeError, haveWidgetsData, view, I,
+        self.failUnless(viewHasInput(view, I))
+        self.failIf(viewHasInput(view, I, names=['title']))
+        self.assertRaises(KeyError, viewHasInput, view, I, names=['bar'])
+        self.assertRaises(AttributeError, viewHasInput, view, I,
                           names=['foo'])
 
     def test_getWidgetsData_w_default(self):


=== Zope3/src/zope/app/form/tests/test_widget_geddon_deprecations.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/form/tests/test_widget_geddon_deprecations.py:1.1	Thu Jun  5 16:13:09 2003
+++ Zope3/src/zope/app/form/tests/test_widget_geddon_deprecations.py	Wed Aug 13 17:28:38 2003
@@ -27,20 +27,25 @@
 from zope.publisher.interfaces.browser import IBrowserPresentation
 import warnings
 
-class TestView:
-
-    bar = CustomWidget(Widget, uncle='bob')
+class TestWidget(Widget):
     
     def __init__(self, context, request):
         self.context, self.request = context, request
 
-class TestWidget:
+    def __call__(self):
+        return '42'
+
+    def hasInput(self):
+        return True
+
+
+class TestView:
+
+    bar = CustomWidget(TestWidget, uncle='bob')
     
     def __init__(self, context, request):
         self.context, self.request = context, request
 
-    def __call__(self):
-        return '42'
 
 theField = Text(__name__="foo")
 
@@ -56,7 +61,7 @@
     
     >>> request = TestRequest()
     >>> view = TestView(None, request)
-    >>> view.foo = Widget(theField, request)
+    >>> view.foo = TestWidget(theField, request)
     >>> int(hasattr(view, 'foo_widget'))
     0
 




More information about the Zope3-Checkins mailing list