[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/ftests -
test_checkboxwidget.py:1.3.10.1
Jeremy Hylton
jeremy at zope.com
Thu Feb 12 15:33:12 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/browser/form/ftests
In directory cvs.zope.org:/tmp/cvs-serv18730
Modified Files:
Tag: zope3-zodb3-devel-branch
test_checkboxwidget.py
Log Message:
Fix line-endings.
=== Zope3/src/zope/app/browser/form/ftests/test_checkboxwidget.py 1.3 => 1.3.10.1 ===
--- Zope3/src/zope/app/browser/form/ftests/test_checkboxwidget.py:1.3 Sun Sep 21 13:30:39 2003
+++ Zope3/src/zope/app/browser/form/ftests/test_checkboxwidget.py Thu Feb 12 15:33:11 2004
@@ -1,157 +1,157 @@
-##############################################################################
-#
-# 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$
-"""
-
-import unittest
-from persistence import Persistent
-from transaction import get_transaction
-
-from zope.interface import Interface
-from zope.interface import implements
-
-from zope.schema import Bool
-from zope.app.browser.form.widget import CheckBoxWidget
-
-from support import *
-from zope.app.traversing import traverse
-
-from zope.testing.functional import BrowserTestCase
-
-
-class IBoolTest(Interface):
-
- b1 = Bool(
- required=True)
-
- b2 = Bool(
- required=False)
-
-
-registerEditForm(IBoolTest)
-
-
-class BoolTest(Persistent):
-
- implements(IBoolTest)
-
- def __init__(self):
- self.b1 = True
- self.b2 = False
-
-defineSecurity(BoolTest, IBoolTest)
-
-
-class Test(BrowserTestCase):
-
-
- def test_display_editform(self):
- self.getRootFolder()['test'] = BoolTest()
- get_transaction().commit()
-
- # display edit view
- response = self.publish('/test/edit.html')
- self.assertEqual(response.getStatus(), 200)
-
- # b1 and b2 should be displayed in checkbox input fields
- self.assert_(patternExists(
- '<input .* checked="checked".* name="field.b1".* ' \
- 'type="checkbox".* />',
- response.getBody()))
- self.assert_(patternExists(
- '<input .* name="field.b2".* type="checkbox".* />',
- response.getBody()))
- # confirm that b2 is *not* checked
- self.assert_(not patternExists(
- '<input .* checked="checked".* name="field.b2".* ' \
- 'type="checkbox".* />',
- response.getBody()))
-
-
- def test_submit_editform(self):
- self.getRootFolder()['test'] = BoolTest()
- get_transaction().commit()
-
- # submit edit view
- response = self.publish('/test/edit.html', form={
- 'UPDATE_SUBMIT' : '',
- 'field.b1' : '',
- 'field.b2' : 'on' })
- self.assertEqual(response.getStatus(), 200)
- self.assert_(updatedMsgExists(response.getBody()))
-
- # check new values in object
- object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
- self.assertEqual(object.b1, False)
- self.assertEqual(object.b2, True)
-
-
- def test_unexpected_value(self):
- object = BoolTest()
- object.b1 = True
- object.b2 = True
- self.getRootFolder()['test'] = object
- get_transaction().commit()
-
- # submit invalud type for text line
- response = self.publish('/test/edit.html', form={
- 'UPDATE_SUBMIT' : '',
- 'field.b1' : 'true',
- 'field.b2' : 'foo' })
- self.assertEqual(response.getStatus(), 200)
- self.assert_(updatedMsgExists(response.getBody()))
-
- # values other than 'on' should be treated as False
- object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
- self.assertEqual(object.b1, False)
- self.assertEqual(object.b2, False)
-
-
- def test_missing_value(self):
- # Note: checkbox widget doesn't support a missing value. This
- # test confirms that one cannot set a Bool field to None.
-
- self.getRootFolder()['test'] = BoolTest()
- get_transaction().commit()
-
- # confirm default value of b1 is True
- object = traverse(self.getRootFolder(), 'test')
- self.assertEqual(object.b1, True)
-
- # submit missing for b1
- response = self.publish('/test/edit.html', form={
- 'UPDATE_SUBMIT' : '',
- 'field.b1' : CheckBoxWidget._missing })
- self.assertEqual(response.getStatus(), 200)
- self.assert_(updatedMsgExists(response.getBody()))
-
- # confirm b1 is not missing
- object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
- self.assert_(object.b1 != Bool.missing_value)
-
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(Test))
- return suite
-
-if __name__=='__main__':
- unittest.main(defaultTest='test_suite')
-
-
+##############################################################################
+#
+# 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$
+"""
+
+import unittest
+from persistence import Persistent
+from transaction import get_transaction
+
+from zope.interface import Interface
+from zope.interface import implements
+
+from zope.schema import Bool
+from zope.app.browser.form.widget import CheckBoxWidget
+
+from support import *
+from zope.app.traversing import traverse
+
+from zope.testing.functional import BrowserTestCase
+
+
+class IBoolTest(Interface):
+
+ b1 = Bool(
+ required=True)
+
+ b2 = Bool(
+ required=False)
+
+
+registerEditForm(IBoolTest)
+
+
+class BoolTest(Persistent):
+
+ implements(IBoolTest)
+
+ def __init__(self):
+ self.b1 = True
+ self.b2 = False
+
+defineSecurity(BoolTest, IBoolTest)
+
+
+class Test(BrowserTestCase):
+
+
+ def test_display_editform(self):
+ self.getRootFolder()['test'] = BoolTest()
+ get_transaction().commit()
+
+ # display edit view
+ response = self.publish('/test/edit.html')
+ self.assertEqual(response.getStatus(), 200)
+
+ # b1 and b2 should be displayed in checkbox input fields
+ self.assert_(patternExists(
+ '<input .* checked="checked".* name="field.b1".* ' \
+ 'type="checkbox".* />',
+ response.getBody()))
+ self.assert_(patternExists(
+ '<input .* name="field.b2".* type="checkbox".* />',
+ response.getBody()))
+ # confirm that b2 is *not* checked
+ self.assert_(not patternExists(
+ '<input .* checked="checked".* name="field.b2".* ' \
+ 'type="checkbox".* />',
+ response.getBody()))
+
+
+ def test_submit_editform(self):
+ self.getRootFolder()['test'] = BoolTest()
+ get_transaction().commit()
+
+ # submit edit view
+ response = self.publish('/test/edit.html', form={
+ 'UPDATE_SUBMIT' : '',
+ 'field.b1' : '',
+ 'field.b2' : 'on' })
+ self.assertEqual(response.getStatus(), 200)
+ self.assert_(updatedMsgExists(response.getBody()))
+
+ # check new values in object
+ object = traverse(self.getRootFolder(), 'test')
+ object._p_jar.sync()
+ self.assertEqual(object.b1, False)
+ self.assertEqual(object.b2, True)
+
+
+ def test_unexpected_value(self):
+ object = BoolTest()
+ object.b1 = True
+ object.b2 = True
+ self.getRootFolder()['test'] = object
+ get_transaction().commit()
+
+ # submit invalud type for text line
+ response = self.publish('/test/edit.html', form={
+ 'UPDATE_SUBMIT' : '',
+ 'field.b1' : 'true',
+ 'field.b2' : 'foo' })
+ self.assertEqual(response.getStatus(), 200)
+ self.assert_(updatedMsgExists(response.getBody()))
+
+ # values other than 'on' should be treated as False
+ object = traverse(self.getRootFolder(), 'test')
+ object._p_jar.sync()
+ self.assertEqual(object.b1, False)
+ self.assertEqual(object.b2, False)
+
+
+ def test_missing_value(self):
+ # Note: checkbox widget doesn't support a missing value. This
+ # test confirms that one cannot set a Bool field to None.
+
+ self.getRootFolder()['test'] = BoolTest()
+ get_transaction().commit()
+
+ # confirm default value of b1 is True
+ object = traverse(self.getRootFolder(), 'test')
+ self.assertEqual(object.b1, True)
+
+ # submit missing for b1
+ response = self.publish('/test/edit.html', form={
+ 'UPDATE_SUBMIT' : '',
+ 'field.b1' : CheckBoxWidget._missing })
+ self.assertEqual(response.getStatus(), 200)
+ self.assert_(updatedMsgExists(response.getBody()))
+
+ # confirm b1 is not missing
+ object = traverse(self.getRootFolder(), 'test')
+ object._p_jar.sync()
+ self.assert_(object.b1 != Bool.missing_value)
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(Test))
+ return suite
+
+if __name__=='__main__':
+ unittest.main(defaultTest='test_suite')
+
+
More information about the Zope3-Checkins
mailing list