[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Forms/Views/Browser/tests - testBrowserWidget.py:1.7

Jim Fulton jim@zope.com
Thu, 19 Dec 2002 14:54:09 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Forms/Views/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv21950

Modified Files:
	testBrowserWidget.py 
Log Message:
  revision 1.6.8.2
  date: 2002/12/12 16:09:09;  author: jim;  state: Exp;  lines: +7 -0
  Fixed a bug in _showData (used to get data to be displayed in an edit
  widget). We failed to use field defaults when there was no initial
  data pr request data.

  revision 1.6.8.1
  date: 2002/12/12 15:16:50;  author: jim;  state: Exp;  lines: +14 -0
  Changed the widget haveData method to run the conversion api to make
  sure that there is non-missing data, not just form data.


=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testBrowserWidget.py 1.6 => 1.7 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testBrowserWidget.py:1.6	Wed Dec  4 04:58:46 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testBrowserWidget.py	Thu Dec 19 14:54:08 2002
@@ -73,8 +73,15 @@
         row = ''.join(self._widget.row().strip().split())
         self.assertEqual(row, '<td>%s</td><td>%s</td>' % (label, value))
 
+class TestWidget(BrowserWidget):
+
+    def _convert(self, v):
+        return v or None
+
 class Test(BrowserWidgetTest):
 
+    _WidgetFactory = TestWidget
+
     def test_showData(self):
 
         class W(BrowserWidget):
@@ -94,6 +101,20 @@
 
         w.setData('Xfoo')
         self.assertEqual(w._showData(), 'foo')        
+
+    def test_haveData(self):
+        self.failUnless(self._widget.haveData())
+        del self._widget.request.form['field.foo']
+        self.failIf(self._widget.haveData())
+        self._widget.request.form['field.foo'] = u''
+        self.failIf(self._widget.haveData())
+
+    def test_showData_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')
+        
 
 def test_suite():
     return unittest.makeSuite(Test)