[Zope-Checkins] CVS: Zope3/lib/python/Schema/tests - testSchema.py:1.2
Joachim Schmitz
js@aixtraware.de
Tue, 25 Jun 2002 06:21:02 -0400
Update of /cvs-repository/Zope3/lib/python/Schema/tests
In directory cvs.zope.org:/tmp/cvs-serv16614/tests
Modified Files:
testSchema.py
Log Message:
added new Schema validation and tests.
=== Zope3/lib/python/Schema/tests/testSchema.py 1.1 => 1.2 ===
from unittest import TestCase, TestSuite, main, makeSuite
-from Schema.Exceptions import StopValidation, ValidationError
-from Schema._Schema import validate
-from Schema.IField import IStr
-
+from Schema.Exceptions import StopValidation, ValidationError, ValidationErrorsAll
+from Schema._Schema import validateMapping,validateMappingAll
+from Interface import Interface
+import Schema
+
+class ISchemaTest(Interface):
+ title = Schema.Str(
+ title="Title"
+ ,description="Title"
+ ,default=""
+ ,required=1
+ )
+ description = Schema.Str(
+ title="Description"
+ ,description="Description"
+ ,default=""
+ ,required=1
+ )
+ spam = Schema.Str(
+ title="Spam"
+ ,description="Spam"
+ ,default=""
+ ,required=1
+ )
+
class SchemaTestCase(TestCase):
- def test_validate(self):
- dict = {'title': 'A title',
- 'description': 'A particular description.',
- 'readonly': 0}
-
- result = validate(IStr, dict)
- for key, value in dict.items():
- self.assertEquals(value, result[key])
-
+ def test_validateMapping(self):
+ dict = {
+ 'title': 'A title',
+ 'description': 'A particular description.',
+ 'spam': 'Spam',
+ }
+ try:
+ validateMapping(ISchemaTest, dict)
+ except ValidationError:
+ self.fail()
+
+
+ def test_validateBadMapping(self):
+ dict = {'title': 'A title'
+ }
+
+ self.assertRaises(ValidationError, validateMapping, ISchemaTest, dict)
+
+ def test_validateMappingAll(self):
+ dict = {
+ 'title': 'A title',
+ 'description': 'A particular description.',
+ 'spam': 'Spam',
+ }
+ try:
+ validateMappingAll(ISchemaTest, dict)
+ except ValidationErrorsAll:
+ self.fail()
+
+
+ def test_validateBadMappingAll(self):
+ dict = {'title': 'A title'
+ }
+
+ try:
+ validateMappingAll(ISchemaTest, dict)
+ except ValidationErrorsAll, e:
+ error=ValidationError("Must be required")
+ self.assertEqual(e.errors , [('description',error),
+ ('spam',error)]
+ )
+ self.assertRaises(ValidationError, validateMapping, ISchemaTest, dict)
+
def test_suite():
return TestSuite((
makeSuite(SchemaTestCase),