[Zope3-checkins] CVS: Zope3/src/zope/app/form/tests - test_utility.py:1.8
Albertas Agejevas
alga@codeworks.lt
Fri, 21 Feb 2003 09:54:03 -0500
Update of /cvs-repository/Zope3/src/zope/app/form/tests
In directory cvs.zope.org:/tmp/cvs-serv25770/app/form/tests
Modified Files:
test_utility.py
Log Message:
Changed the browser:editform to clear the values which are missing or
empty in the form by default.
Added a keyword argument set_missing to getWidgetsData() and
getWidgetsDataForContent().
Renamed a keyword argument required there to strict, which is
clearer. Added it everywhere to be more explicit.
=== Zope3/src/zope/app/form/tests/test_utility.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/form/tests/test_utility.py:1.7 Mon Jan 27 23:48:09 2003
+++ Zope3/src/zope/app/form/tests/test_utility.py Fri Feb 21 09:53:33 2003
@@ -48,6 +48,10 @@
title = Text(title = u"Title", required = True)
description = Text(title = u"Description", required = True)
+class I3(Interface):
+ title = Text(title = u"Title", required = True)
+ description = Text(title=u"Description", required = False)
+
class C:
__implements__ = I
@@ -93,7 +97,9 @@
return v
def haveData(self):
- return self.name in self.request
+ if self.name in self.request and self.request[self.name]:
+ return True
+ return False
class Test(PlacelessSetup, TestCase):
@@ -360,6 +366,24 @@
{'title': u'ft',
'description': u'fd'})
+
+ setUpWidgets(view, I3, initial=kw(title=u"ttt", description=u"ddd"))
+ self.assertEqual(getWidgetsData(view, I3),
+ {'title': u'ft',
+ 'description': u'fd'})
+
+ request.form['field.description'] = ''
+ setUpWidgets(view, I3, initial=kw(title=u"ttt", description=u"ddd"))
+ self.assertEqual(getWidgetsData(view, I3),
+ {'title': u'ft',
+ 'description': None})
+
+ request.form['field.description'] = u''
+ setUpWidgets(view, I, initial=kw(title=u"ttt", description=u"ddd"))
+ self.assertEqual(getWidgetsData(view, I),
+ {'title': u'ft',
+ 'description': None})
+
def test_getWidgetsData_w_names(self):
c = C()
request = TestRequest()
@@ -402,17 +426,29 @@
request = TestRequest()
view = BrowserView(c, request)
setUpWidgets(view, I, initial=kw(title=u"ttt", description=u"ddd"))
- self.assertEqual(getWidgetsData(view, I, required=0), {})
+ self.assertEqual(getWidgetsData(view, I, strict=False, set_missing=False),
+ {})
- self.assertRaises(MissingInputError, getWidgetsData, view, I2)
- self.assertEqual(getWidgetsData(view, I), {})
+ self.assertEqual(getWidgetsData(view, I, strict=False, set_missing=True),
+ {'description': None, 'title': None})
+
+ self.assertRaises(MissingInputError, getWidgetsData, view, I2, strict=True)
+
+ self.assertEqual(getWidgetsData(view, I), {'description': None,
+ 'title': None})
request.form['field.description'] = u'fd'
- self.assertEqual(getWidgetsData(view, I2, required=0),
+ self.assertEqual(getWidgetsData(view, I2, strict=False,
+ set_missing=False),
{'description': u'fd'})
+ self.assertEqual(getWidgetsData(view, I2, strict=False,
+ set_missing=True),
+ {'description': u'fd', 'title': None})
+
self.assertRaises(MissingInputError, getWidgetsData, view, I2)
- self.assertEqual(getWidgetsData(view, I), {'description': u'fd'})
+ self.assertEqual(getWidgetsData(view, I), {'description': u'fd',
+ 'title': None})
def test_getWidgetsDataForContent(self):
c = C()
@@ -445,7 +481,7 @@
request.form['field.title'] = u'ft'
view = BrowserView(c, request)
setUpWidgets(view, I2, initial=kw(title=u"ttt", description=u"ddd"))
- getWidgetsDataForContent(view, I2)
+ getWidgetsDataForContent(view, I2, names=("title",))
self.assertEqual(c.title, u'ft')
self.assertEqual(c.description, u'old description')