[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - test_add.py:1.16
Marius Gedminas
mgedmin@codeworks.lt
Mon, 23 Jun 2003 12:42:21 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv8639/src/zope/app/browser/form/tests
Modified Files:
test_add.py
Log Message:
Do not accept optional fields as positional arguments in add forms (otherwise
you'll get an exception when the user submits the form without filling them
in).
=== Zope3/src/zope/app/browser/form/tests/test_add.py 1.15 => 1.16 ===
--- Zope3/src/zope/app/browser/form/tests/test_add.py:1.15 Fri Jun 6 17:35:17 2003
+++ Zope3/src/zope/app/browser/form/tests/test_add.py Mon Jun 23 12:41:50 2003
@@ -55,7 +55,7 @@
address = TextLine()
getfoo, setfoo = accessors(TextLine())
extra1 = TextLine()
- extra2 = TextLine()
+ extra2 = TextLine(required=False)
class C:
@@ -127,6 +127,20 @@
)
self.assertEqual(result1, result2)
+
+ def test_add_error_handling(self):
+
+ result1 = self._invoke_add(fields="first last email getfoo extra1")
+ # cannot use a field in arguments if it is not mentioned in fields
+ self.assertRaises(ValueError, self._invoke_add, fields="first email getfoo extra1")
+ # cannot use a field in keyword_arguments if it is not mentioned in fields
+ self.assertRaises(ValueError, self._invoke_add, fields="first last getfoo extra1")
+ # cannot use a field in set_before_add if it is not mentioned in fields
+ self.assertRaises(ValueError, self._invoke_add, fields="first last email extra1")
+ # cannot use a field in set_after_add if it is not mentioned in fields
+ self.assertRaises(ValueError, self._invoke_add, fields="first last email getfoo")
+ # cannot use an optional field in arguments
+ self.assertRaises(ValueError, self._invoke_add, arguments="extra2")
def test_add(self, args=None):