[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Forms/Views/Browser/tests - testBrowserWidget.py:1.5 testCheckBoxWidget.py:1.4 testFileWidget.py:1.4 testListWidget.py:1.6 testMultiCheckboxWidget.py:1.6 testMultiListWidget.py:1.6 testPasswordWidget.py:1.4 testRadioWidget.py:1.6 testTextAreaWidget.py:1.4 testTextWidget.py:1.4 test_setPrefix.py:1.2 SchemaTestObject.py:NONE testFormView.py:NONE
Jim Fulton
jim@zope.com
Mon, 11 Nov 2002 15:43:34 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Forms/Views/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv17285/Browser/tests
Modified Files:
testBrowserWidget.py testCheckBoxWidget.py testFileWidget.py
testListWidget.py testMultiCheckboxWidget.py
testMultiListWidget.py testPasswordWidget.py
testRadioWidget.py testTextAreaWidget.py testTextWidget.py
test_setPrefix.py
Removed Files:
SchemaTestObject.py testFormView.py
Log Message:
Added widgets for the new TextLine and Line field types.
Added new label and row methods for generating forms.
Ripped converter framework.
Removed set-data and prefix machinery, which are now handled by the
generic widget code.
Added haveData method that tests whether user inpput data are
available.
Added _unconvert and _showData method to help with rendering data
provided by setData.
Added machinery to treat stringish fields as missing when the input
data is an empty string and the minimum length is greater than 0.
Changed text (text, textarea, bytes, bytesarea) widgets to use a
style="width:100%".
Changed (single-line) text and bytes widget to use a select list when
allowed_values are defined on the underlying field. (Hint: A nice
improvement would be to add rdio button support).
Changed the tests to use real fields. This required some refactoring.
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testBrowserWidget.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testBrowserWidget.py:1.4 Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testBrowserWidget.py Mon Nov 11 15:43:33 2002
@@ -17,27 +17,35 @@
"""
import unittest
from Zope.App.Forms.Views.Browser.Widget import BrowserWidget
-
-class Field:
- """Field Stub """
- __name__ = 'foo'
-
- def getName(self):
- return 'foo'
-
+from Zope.Publisher.Browser.BrowserRequest import TestRequest
+from Zope.Schema import Text
class BrowserWidgetTest(unittest.TestCase):
+ _WidgetFactory = BrowserWidget
+
def setUp(self):
- field = Field()
- request = {'field.foo': 'Foo Value'}
- self._widget = BrowserWidget(field, request)
+ field = Text(__name__ = 'foo', title = u"Foo Title")
+ request = TestRequest()
+ request.form['field.foo'] = u'Foo Value'
+ self._widget = self._WidgetFactory(field, request)
def _verifyResult(self, result, check_list):
for check in check_list:
self.assertNotEqual(-1, result.find(check),
'"'+check+'" not found in "'+result+'"')
+ def test_required(self):
+ self._widget.context.required = False
+ self.failIf(self._widget.required)
+ self._widget.context.required = True
+ self.failUnless(self._widget.required)
+
+ def test_haveData(self):
+ self.failUnless(self._widget.haveData())
+ del self._widget.request.form['field.foo']
+ self.failIf(self._widget.haveData())
+
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
self.assertEqual(self._widget.getValue('type'), 'text')
@@ -54,6 +62,17 @@
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.renderHidden(value), check_list)
+ def testLabel(self):
+ label = ' '.join(self._widget.label().strip().split())
+ self.assertEqual(label, '<label for="field.foo">Foo Title</label>')
+
+ def testRow(self):
+ self._widget.request.form.clear()
+ label = ''.join(self._widget.label().strip().split())
+ value = ''.join(self._widget().strip().split())
+ row = ''.join(self._widget.row().strip().split())
+ self.assertEqual(row, '<td>%s</td><td>%s</td>' % (label, value))
+
def test_suite():
return unittest.makeSuite(BrowserWidgetTest)
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testCheckBoxWidget.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testCheckBoxWidget.py:1.3 Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testCheckBoxWidget.py Mon Nov 11 15:43:33 2002
@@ -17,15 +17,12 @@
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import CheckBoxWidget
-from testBrowserWidget import BrowserWidgetTest, Field
+from testBrowserWidget import BrowserWidgetTest
class CheckBoxWidgetTest(BrowserWidgetTest):
-
- def setUp(self):
- field = Field()
- request = {'field.foo': 'Foo Value'}
- self._widget = CheckBoxWidget(field, request)
+
+ _WidgetFactory = CheckBoxWidget
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testFileWidget.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testFileWidget.py:1.3 Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testFileWidget.py Mon Nov 11 15:43:33 2002
@@ -16,16 +16,20 @@
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import FileWidget
+from StringIO import StringIO
-from testBrowserWidget import BrowserWidgetTest, Field
-
+from testBrowserWidget import BrowserWidgetTest
class FileWidgetTest(BrowserWidgetTest):
-
- def setUp(self):
- field = Field()
- request = {'field.foo': 'Foo Value'}
- self._widget = FileWidget(field, request)
+
+ _WidgetFactory = FileWidget
+
+ def setUp(self):
+ BrowserWidgetTest.setUp(self)
+
+ file = StringIO('Foo Value')
+ file.filename = 'test.txt'
+ self._widget.request.form['field.foo'] = file
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testListWidget.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testListWidget.py:1.5 Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testListWidget.py Mon Nov 11 15:43:33 2002
@@ -19,29 +19,17 @@
from testBrowserWidget import BrowserWidgetTest
-class Field:
- """Field Stub """
- items = [('foo', 'Foo'), ('bar', 'Bar')]
-
- __name__ = 'foo'
-
- def getName(self):
- return 'foo'
-
- def get(self, name):
- return getattr(self, name)
-
class ListWidgetTest(BrowserWidgetTest):
-
+
def setUp(self):
- field = Field()
- request = {'field.foo': 'Foo Value'}
- self._widget = ListWidget(field, request)
+ BrowserWidgetTest.setUp(self)
+ self._widget.context.allowed_values = (u'foo', u'bar')
+
+ _WidgetFactory = ListWidget
def testProperties(self):
self.assertEqual(self._widget.getValue('cssClass'), "")
self.assertEqual(self._widget.getValue('extra'), '')
- self.assertEqual(self._widget.getValue('items'), [])
self.assertEqual(self._widget.getValue('firstItem'), 0)
self.assertEqual(self._widget.getValue('size'), 5)
@@ -58,8 +46,8 @@
def testRenderItems(self):
- check_list = ('option', 'value="foo"', 'Bar',
- 'value="foo"', 'Foo', 'selected="selected"')
+ check_list = ('option', 'value="foo"', 'bar',
+ 'value="foo"', 'foo', 'selected="selected"')
self._verifyResult('\n'.join(self._widget.renderItems('foo')),
check_list)
@@ -67,8 +55,8 @@
def testRender(self):
value = 'foo'
check_list = ('select', 'name="field.foo"', 'size="5"',
- 'option', 'value="foo"', '>Foo<',
- 'value="foo"', '>Bar<', 'selected="selected"')
+ 'option', 'value="foo"', '>foo<',
+ 'value="foo"', '>bar<', 'selected="selected"')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"', 'name="field.foo"', 'value="foo"')
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testMultiCheckboxWidget.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testMultiCheckboxWidget.py:1.5 Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testMultiCheckboxWidget.py Mon Nov 11 15:43:33 2002
@@ -19,30 +19,17 @@
from testBrowserWidget import BrowserWidgetTest
-class Field:
- """Field Stub """
- items = [('foo1', 'Foo'), ('bar1', 'Bar')]
-
- __name__ = 'foo'
-
- def getName(self):
- return 'foo'
-
- def get(self, name):
- return getattr(self, name)
+class MultiCheckBoxWidgetTest(BrowserWidgetTest):
+ _WidgetFactory = MultiCheckBoxWidget
-class MultiCheckBoxWidgetTest(BrowserWidgetTest):
-
def setUp(self):
- field = Field()
- request = {'field.foo': 'Foo Value'}
- self._widget = MultiCheckBoxWidget(field, request)
+ BrowserWidgetTest.setUp(self)
+ self._widget.context.allowed_values = (u'foo', u'bar')
def testProperties(self):
self.assertEqual(self._widget.getValue('cssClass'), "")
self.assertEqual(self._widget.getValue('extra'), '')
- self.assertEqual(self._widget.getValue('items'), [])
self.assertEqual(self._widget.getValue('orientation'), 'vertical')
@@ -59,19 +46,19 @@
def testRenderItems(self):
- check_list = ('type="checkbox"', 'name="field.foo"', 'value="bar1"',
- 'Bar', 'value="foo1"', 'Foo', 'checked="checked"')
- self._verifyResult('\n'.join(self._widget.renderItems('bar1')),
+ check_list = ('type="checkbox"', 'name="field.foo"', 'value="bar"',
+ 'bar', 'value="foo"', 'foo', 'checked="checked"')
+ self._verifyResult('\n'.join(self._widget.renderItems('bar')),
check_list)
def testRender(self):
- value = 'bar1'
- check_list = ('type="checkbox"', 'name="field.foo"', 'value="bar1"',
- 'Bar', 'value="foo1"', 'Foo', 'checked="checked"')
+ value = 'bar'
+ check_list = ('type="checkbox"', 'name="field.foo"', 'value="bar"',
+ 'bar', 'value="foo"', 'foo', 'checked="checked"')
self._verifyResult(self._widget.render(value), check_list)
- check_list = ('type="hidden"', 'name="field.foo"', 'value="bar1"')
+ check_list = ('type="hidden"', 'name="field.foo"', 'value="bar"')
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testMultiListWidget.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testMultiListWidget.py:1.5 Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testMultiListWidget.py Mon Nov 11 15:43:33 2002
@@ -19,31 +19,17 @@
from testBrowserWidget import BrowserWidgetTest
-class Field:
- """Field Stub """
- items = [('foo', 'Foo'), ('bar', 'Bar')]
-
- __name__ = 'foo'
-
- def getName(self):
- return 'foo'
-
- def get(self, name):
- return getattr(self, name)
+class MultiListWidgetTest(BrowserWidgetTest):
+ _WidgetFactory = MultiListWidget
-class MultiListWidgetTest(BrowserWidgetTest):
-
def setUp(self):
- field = Field()
- request = {'field.foo': 'Foo Value'}
- self._widget = MultiListWidget(field, request)
-
+ BrowserWidgetTest.setUp(self)
+ self._widget.context.allowed_values = (u'foo', u'bar')
def testProperties(self):
self.assertEqual(self._widget.getValue('cssClass'), "")
self.assertEqual(self._widget.getValue('extra'), '')
- self.assertEqual(self._widget.getValue('items'), [])
self.assertEqual(self._widget.getValue('size'), 5)
@@ -59,8 +45,8 @@
def testRenderItems(self):
- check_list = ('option', 'value="foo"', 'Bar',
- 'value="foo"', 'Foo', 'selected="selected"')
+ check_list = ('option', 'value="foo"', 'bar',
+ 'value="foo"', 'foo', 'selected="selected"')
self._verifyResult('\n'.join(self._widget.renderItems('foo')),
check_list)
@@ -68,8 +54,8 @@
def testRender(self):
value = 'foo'
check_list = ('select', 'name="field.foo"', 'size="5"',
- 'option', 'value="foo"', '>Foo<',
- 'value="foo"', '>Bar<', 'selected="selected"',
+ 'option', 'value="foo"', '>foo<',
+ 'value="foo"', '>bar<', 'selected="selected"',
'multiple="multiple"')
self._verifyResult(self._widget.render(value), check_list)
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testPasswordWidget.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testPasswordWidget.py:1.3 Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testPasswordWidget.py Mon Nov 11 15:43:33 2002
@@ -17,15 +17,12 @@
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import PasswordWidget
-from testBrowserWidget import BrowserWidgetTest, Field
+from testBrowserWidget import BrowserWidgetTest
class PasswordWidgetTest(BrowserWidgetTest):
-
- def setUp(self):
- field = Field()
- request = {'field.foo': 'Foo Value'}
- self._widget = PasswordWidget(field, request)
+
+ _WidgetFactory = PasswordWidget
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testRadioWidget.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testRadioWidget.py:1.5 Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testRadioWidget.py Mon Nov 11 15:43:33 2002
@@ -19,30 +19,17 @@
from testBrowserWidget import BrowserWidgetTest
-class Field:
- """Field Stub """
- items = [('foo1', 'Foo'), ('bar1', 'Bar')]
-
- __name__ = 'foo'
-
- def getName(self):
- return 'foo'
-
- def get(self, name):
- return getattr(self, name)
+class RadioWidgetTest(BrowserWidgetTest):
+ _WidgetFactory = RadioWidget
-class RadioWidgetTest(BrowserWidgetTest):
-
def setUp(self):
- field = Field()
- request = {'field.foo': 'Foo Value'}
- self._widget = RadioWidget(field, request)
+ BrowserWidgetTest.setUp(self)
+ self._widget.context.allowed_values = (u'foo', u'bar')
def testProperties(self):
self.assertEqual(self._widget.getValue('cssClass'), "")
self.assertEqual(self._widget.getValue('extra'), '')
- self.assertEqual(self._widget.getValue('items'), [])
self.assertEqual(self._widget.getValue('firstItem'), 0)
self.assertEqual(self._widget.getValue('orientation'), 'vertical')
@@ -60,19 +47,19 @@
def testRenderItems(self):
- check_list = ('type="radio"', 'name="field.foo"', 'value="bar1"',
- 'Bar', 'value="foo1"', 'Foo', 'checked="checked"')
- self._verifyResult('\n'.join(self._widget.renderItems('bar1')),
+ check_list = ('type="radio"', 'name="field.foo"', 'value="bar"',
+ 'bar', 'value="foo"', 'foo', 'checked="checked"')
+ self._verifyResult('\n'.join(self._widget.renderItems('bar')),
check_list)
def testRender(self):
- value = 'bar1'
- check_list = ('type="radio"', 'name="field.foo"', 'value="bar1"',
- 'Bar', 'value="foo1"', 'Foo', 'checked="checked"')
+ value = 'bar'
+ check_list = ('type="radio"', 'name="field.foo"', 'value="bar"',
+ 'bar', 'value="foo"', 'foo', 'checked="checked"')
self._verifyResult(self._widget.render(value), check_list)
- check_list = ('type="hidden"', 'name="field.foo"', 'value="bar1"')
+ check_list = ('type="hidden"', 'name="field.foo"', 'value="bar"')
self._verifyResult(self._widget.renderHidden(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testTextAreaWidget.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testTextAreaWidget.py:1.3 Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testTextAreaWidget.py Mon Nov 11 15:43:33 2002
@@ -17,33 +17,38 @@
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import TextAreaWidget
-from testBrowserWidget import BrowserWidgetTest, Field
+from testBrowserWidget import BrowserWidgetTest
class TextAreaWidgetTest(BrowserWidgetTest):
-
- def setUp(self):
- field = Field()
- request = {'field.foo': 'Foo Value'}
- self._widget = TextAreaWidget(field, request)
+
+ _WidgetFactory = TextAreaWidget
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
self.assertEqual(self._widget.getValue('type'), 'text')
self.assertEqual(self._widget.getValue('cssClass'), '')
self.assertEqual(self._widget.getValue('extra'), '')
- self.assertEqual(self._widget.getValue('width'), 80)
+ self.assertEqual(self._widget.getValue('width'), 60)
self.assertEqual(self._widget.getValue('height'), 15)
def testRender(self):
value = "Foo Value"
- check_list = ('rows="15"', 'cols="80"', 'name="field.foo"', 'textarea')
+ check_list = ('rows="15"', 'cols="60"', 'name="field.foo"', 'textarea')
self._verifyResult(self._widget.render(value), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.render(value), check_list)
check_list = ('type="hidden"', 'name="field.foo"', 'value="Foo Value"')
self._verifyResult(self._widget.renderHidden(value), check_list)
+
+ def testRow(self):
+ self._widget.request.form.clear()
+ label = ''.join(self._widget.label().strip().split())
+ value = ''.join(self._widget().strip().split())
+ row = ''.join(self._widget.row().strip().split())
+ self.assertEqual(row,
+ '<tdcolspan="2">%s<br/>%s</td>' % (label, value))
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testTextWidget.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testTextWidget.py:1.3 Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testTextWidget.py Mon Nov 11 15:43:33 2002
@@ -17,16 +17,13 @@
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Forms.Views.Browser.Widget import TextWidget
-from testBrowserWidget import BrowserWidgetTest, Field
+from testBrowserWidget import BrowserWidgetTest
class TextWidgetTest(BrowserWidgetTest):
-
- def setUp(self):
- field = Field()
- request = {'field.foo': 'Foo Value'}
- self._widget = TextWidget(field, request)
+ _WidgetFactory = TextWidget
+
def testProperties(self):
self.assertEqual(self._widget.getValue('tag'), 'input')
self.assertEqual(self._widget.getValue('type'), 'text')
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/test_setPrefix.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/test_setPrefix.py:1.1 Tue Oct 29 12:19:48 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/test_setPrefix.py Mon Nov 11 15:43:33 2002
@@ -21,7 +21,7 @@
from Zope.Schema import Text
-class TextWidgetTest(BrowserWidgetTest):
+class Test(TestCase):
def setUp(self):
field = Text(__name__ = 'foo')
@@ -45,10 +45,15 @@
self._widget.extra = 'style="color: red"'
self._verifyResult(self._widget.hidden(), check_list)
+ def _verifyResult(self, result, check_list):
+ for check in check_list:
+ self.assertNotEqual(-1, result.find(check),
+ '"'+check+'" not found in "'+result+'"')
+
def test_suite():
- return makeSuite(TextWidgetTest)
+ return makeSuite(Test)
if __name__=='__main__':
main(defaultTest='test_suite')
=== Removed File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/SchemaTestObject.py ===
=== Removed File Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testFormView.py ===