[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests -
test_checkboxwidget.py:1.9.24.4
Garrett Smith
garrett at mojave-corp.com
Sun Feb 8 02:37:57 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv31887/src/zope/app/browser/form/tests
Modified Files:
Tag: ozzope-widgets-branch
test_checkboxwidget.py
Log Message:
Moved some doctests over to test module.
=== Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py 1.9.24.3 => 1.9.24.4 ===
--- Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py:1.9.24.3 Sun Feb 8 01:08:15 2004
+++ Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py Sun Feb 8 02:37:56 2004
@@ -19,6 +19,7 @@
from zope.app.interfaces.form import IEditWidget
from zope.app.interfaces.browser.widget import ICheckBoxWidget
from zope.app.browser.form.widget import CheckBoxWidget
+from zope.publisher.browser import TestRequest
from zope.schema import Bool
from zope.interface.verify import verifyClass, verifyObject
@@ -33,6 +34,79 @@
True
>>> ICheckBoxWidget.extends(IEditWidget)
True
+
+ The rest of the this doctest was moved from widget.py to this test module
+ to keep widget.py free of detailed tests. XXX the tests below should be
+ more narrative to highlight the 'story' being told.
+
+ >>> field = Bool(__name__='foo', title=u'on')
+ >>> request = TestRequest(form={'field.foo.used': u'on',
+ ... 'field.foo': u'on'})
+ >>> widget = CheckBoxWidget(field, request)
+ >>> widget.hasInput()
+ True
+ >>> widget.getInputValue()
+ True
+
+ >>> def normalize(s):
+ ... return '\\n '.join(s.split())
+
+ >>> print normalize( widget() )
+ <input
+ class="hiddenType"
+ id="field.foo.used"
+ name="field.foo.used"
+ type="hidden"
+ value=""
+ />
+ <input
+ class="checkboxType"
+ checked="checked"
+ id="field.foo"
+ name="field.foo"
+ type="checkbox"
+ />
+
+ >>> print normalize( widget.hidden() )
+ <input
+ class="hiddenType"
+ id="field.foo"
+ name="field.foo"
+ type="hidden"
+ value="on"
+ />
+
+ Calling setRenderedValue will change what gets output:
+
+ >>> widget.setRenderedValue(False)
+ >>> print normalize( widget() )
+ <input
+ class="hiddenType"
+ id="field.foo.used"
+ name="field.foo.used"
+ type="hidden"
+ value=""
+ />
+ <input
+ class="checkboxType"
+ id="field.foo"
+ name="field.foo"
+ type="checkbox"
+ />
+
+ When a checkbox is not 'checked', it's value is not
+ sent in the request, so we consider it 'False', which
+ means that 'required' for a boolean field doesn't make
+ much sense in the end.
+
+ >>> field = Bool(__name__='foo', title=u'on', required=True)
+ >>> request = TestRequest(form={'field.foo.used': u''})
+ >>> widget = CheckBoxWidget(field, request)
+ >>> widget.hasInput()
+ True
+ >>> widget.validate()
+ >>> widget.getInputValue()
+ False
"""
_FieldFactory = Bool
More information about the Zope3-Checkins
mailing list