[Zope3-checkins] CVS: Zope3/lib/python/Zope/Schema/tests - testField.py:1.5

Holger Krekel hpk@devel.trillke.net
Thu, 5 Dec 2002 08:27:09 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Schema/tests
In directory cvs.zope.org:/tmp/cvs-serv27419/lib/python/Zope/Schema/tests

Modified Files:
	testField.py 
Log Message:
- refactored/renamed the fields in IField.py interfaces 
  together with Martijn Faassen to have expressive and
  consistent names.

- please note that now the 'required' field defaults
  to true. you have to explicitly state that you 
  want a Field to be optional (i.e. non-required).

- improved the docstrings

- modified the unittests to reflect the new situation



=== Zope3/lib/python/Zope/Schema/tests/testField.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/Schema/tests/testField.py:1.4	Mon Nov 11 15:24:35 2002
+++ Zope3/lib/python/Zope/Schema/tests/testField.py	Thu Dec  5 08:27:07 2002
@@ -15,7 +15,7 @@
 $Id$
 """
 from unittest import TestCase, TestSuite, main, makeSuite
-from Zope.Schema import Field, Text, IField, ErrorNames
+from Zope.Schema import Field, Text, IField, ErrorNames, Int
 from Zope.Schema.Exceptions import StopValidation, ValidationError
 
 class FieldTestBase(TestCase):
@@ -107,11 +107,31 @@
             a = Text()
 
         self.failUnless(S2['a'].order > S2['b'].order)
-                           
+
+    def testConstraint(self):
+        def isodd(x):
+            return x % 2 == 1
+
+        i = Int(title=u'my constrained integer',
+                constraint=isodd)
+
+        i.validate(11)
+        self.assertRaisesErrorNames(ErrorNames.ConstraintNotSatisfied,
+                                    i.validate, 10)
         
+                           
+class FieldDefaultBehaviour(TestCase):
+    def test_required_defaults_to_true(self):
+        class MyField(Field):
+            pass
+        field = MyField(title=u'my')
+        self.assert_(field.required)
 
 def test_suite():
-    return makeSuite(FieldTest)
+    return TestSuite(   (
+            makeSuite(FieldTest),
+            makeSuite(FieldDefaultBehaviour)
+    ))
 
 if __name__ == '__main__':
     main(defaultTest='test_suite')