[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - test_browserwidget.py:1.3 test_checkboxwidget.py:1.3

Albertas Agejevas alga@codeworks.lt
Mon, 30 Dec 2002 14:39:49 -0500


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

Modified Files:
	test_browserwidget.py test_checkboxwidget.py 
Log Message:
Made CheckBoxWidget work.
Fixed an error in a raise, added more tests.


=== Zope3/src/zope/app/browser/form/tests/test_browserwidget.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/browser/form/tests/test_browserwidget.py:1.2	Wed Dec 25 09:12:32 2002
+++ Zope3/src/zope/app/browser/form/tests/test_browserwidget.py	Mon Dec 30 14:39:48 2002
@@ -19,6 +19,7 @@
 from zope.app.browser.form.widget import BrowserWidget
 from zope.publisher.browser import TestRequest
 from zope.schema import Text
+from zope.app.interfaces.forms import ConversionError, WidgetInputError, MissingInputError
 
 class BrowserWidgetTest(unittest.TestCase):
 
@@ -73,9 +74,12 @@
         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):
+        if v == u'barf!':
+            raise "SomethingTerribleHappenedError"
         return v or None
 
 class Test(BrowserWidgetTest):
@@ -101,6 +105,25 @@
 
         w.setData('Xfoo')
         self.assertEqual(w._showData(), 'foo')
+
+    def test_getData(self):
+        self.assertEqual(self._widget.getData(), u'Foo Value')
+
+        self._widget.request.form['field.foo'] = (1, 2)
+        self.assertRaises(WidgetInputError, self._widget.getData)
+
+        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)
+
 
     def test_haveData(self):
         self.failUnless(self._widget.haveData())


=== Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py:1.2	Wed Dec 25 09:12:32 2002
+++ Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py	Mon Dec 30 14:39:48 2002
@@ -45,6 +45,19 @@
         self._widget.extra = 'style="color: red"'
         self._verifyResult(self._widget.renderHidden(value), check_list)
 
+    def test_haveData(self):
+        # Checkbox always has data
+        self.failUnless(self._widget.haveData())
+        del self._widget.request.form['field.foo']
+        self.failUnless(self._widget.haveData())
+
+    def test_getData(self):
+        self._widget.request.form['field.foo'] = 'on'
+        self.assertEqual(self._widget.getData(), True)
+        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)
 
 
 def test_suite():