[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - test_floatwidget.py:1.1 test_intwidget.py:1.1 test_browserwidget.py:1.7 test_checkboxwidget.py:1.5

Marius Gedminas mgedmin@codeworks.lt
Mon, 20 Jan 2003 11:23:41 -0500


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

Modified Files:
	test_browserwidget.py test_checkboxwidget.py 
Added Files:
	test_floatwidget.py test_intwidget.py 
Log Message:
IntWidget and FloatWidget should not try to access context.min_length which
is not valid for IInt/IFloat fields.  Added a fix and unit tests for the bug.
Introduced _FieldFactory in BrowserWidgetTest to facilitate widget testing
with different kinds of fields.




=== Added File Zope3/src/zope/app/browser/form/tests/test_floatwidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_floatwidget.py,v 1.1 2003/01/20 16:23:38 mgedmin Exp $
"""
from unittest import main, makeSuite
from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest
from zope.app.browser.form.widget import FloatWidget
from zope.app.interfaces.form import ConversionError
from zope.schema import Float


class FloatWidgetTest(BrowserWidgetTest):

    _FieldFactory = Float
    _WidgetFactory = FloatWidget

    def test_haveData(self):
        del self._widget.request.form['field.foo']
        self.failIf(self._widget.haveData())
        self._widget.request.form['field.foo'] = u''
        self.failIf(self._widget.haveData())
        self._widget.request.form['field.foo'] = u'123'
        self.failUnless(self._widget.haveData())

    def test_getData(self):
        self._widget.request.form['field.foo'] = u''
        self.assertEquals(self._widget.getData(optional=1), 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'
        self.assertRaises(ConversionError, self._widget.getData)


def test_suite():
    return makeSuite(FloatWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_intwidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_intwidget.py,v 1.1 2003/01/20 16:23:38 mgedmin Exp $
"""
from unittest import main, makeSuite
from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest
from zope.app.browser.form.widget import IntWidget
from zope.app.interfaces.form import ConversionError
from zope.schema import Int


class IntWidgetTest(BrowserWidgetTest):

    _FieldFactory = Int
    _WidgetFactory = IntWidget

    def test_haveData(self):
        del self._widget.request.form['field.foo']
        self.failIf(self._widget.haveData())
        self._widget.request.form['field.foo'] = u''
        self.failIf(self._widget.haveData())
        self._widget.request.form['field.foo'] = u'123'
        self.failUnless(self._widget.haveData())

    def test_getData(self):
        self._widget.request.form['field.foo'] = u''
        self.assertEquals(self._widget.getData(optional=1), None)
        self._widget.request.form['field.foo'] = u'123'
        self.assertEquals(self._widget.getData(), 123)
        self._widget.request.form['field.foo'] = u'abc'
        self.assertRaises(ConversionError, self._widget.getData)


def test_suite():
    return makeSuite(IntWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Zope3/src/zope/app/browser/form/tests/test_browserwidget.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/form/tests/test_browserwidget.py:1.6	Thu Jan 16 14:50:30 2003
+++ Zope3/src/zope/app/browser/form/tests/test_browserwidget.py	Mon Jan 20 11:23:38 2003
@@ -24,10 +24,11 @@
 
 class BrowserWidgetTest(unittest.TestCase):
 
+    _FieldFactory = Text
     _WidgetFactory = BrowserWidget
 
     def setUp(self):
-        field = Text(__name__ = 'foo', title = u"Foo Title")
+        field = self._FieldFactory(__name__ = 'foo', title = u"Foo Title")
         request = TestRequest()
         request.form['field.foo'] = u'Foo Value'
         self._widget = self._WidgetFactory(field, request)


=== Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py:1.4	Wed Jan 15 10:44:33 2003
+++ Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py	Mon Jan 20 11:23:38 2003
@@ -16,12 +16,14 @@
 """
 from unittest import TestCase, TestSuite, main, makeSuite
 from zope.app.browser.form.widget import CheckBoxWidget
+from zope.schema import Bool
 
 from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest
 
 
 class CheckBoxWidgetTest(BrowserWidgetTest):
 
+    _FieldFactory = Bool
     _WidgetFactory = CheckBoxWidget
 
     def testProperties(self):