[Zope-Checkins] CVS: Zope3/lib/python/Schema/tests - testField.py:1.3
Klaus Wölfel
woelfel@aurora-systems.de
Tue, 25 Jun 2002 11:14:18 -0400
Update of /cvs-repository/Zope3/lib/python/Schema/tests
In directory cvs.zope.org:/tmp/cvs-serv31183/tests
Modified Files:
testField.py
Log Message:
Added tests for min_lenght and max_legth in StringFields and fixed a bug in lengthchecking.
=== Zope3/lib/python/Schema/tests/testField.py 1.2 => 1.3 ===
self.assertRaises(ValidationError, field.validate, '')
+ def test_validate_min(self):
+ field = Str(
+ title='Str field',
+ description='',
+ readonly=0,
+ required=0,
+ min_length=3)
+ try:
+ field.validate(None)
+ field.validate('333')
+ field.validate('55555')
+ except ValidationError, e:
+ self.fail('Expected no ValidationError, but we got %s.' % e.error_name)
+
+ self.assertRaisesErrorNames(ErrorNames.TooShort, field.validate, '')
+ self.assertRaisesErrorNames(ErrorNames.TooShort, field.validate, '22')
+ self.assertRaisesErrorNames(ErrorNames.TooShort, field.validate, '1')
+
+ def test_validate_max(self):
+ field = Str(
+ title='Str field',
+ description='',
+ readonly=0,
+ required=0,
+ max_length=5)
+ try:
+ field.validate(None)
+ field.validate('')
+ field.validate('333')
+ field.validate('55555')
+ except ValidationError, e:
+ self.fail('Expected no ValidationError, but we got %s.' % e.error_name)
+
+ self.assertRaisesErrorNames(ErrorNames.TooLong, field.validate, '666666')
+ self.assertRaisesErrorNames(ErrorNames.TooLong, field.validate, '999999999')
+
+ def test_validate_min_max(self):
+ field = Str(
+ title='Str field',
+ description='',
+ readonly=0,
+ required=0,
+ min_length=3,
+ max_length=5)
+ try:
+ field.validate(None)
+ field.validate('333')
+ field.validate('4444')
+ field.validate('55555')
+ except ValidationError, e:
+ self.fail('Expected no ValidationError, but we got %s.' % e.error_name)
+
+ self.assertRaisesErrorNames(ErrorNames.TooShort, field.validate, '22')
+ self.assertRaisesErrorNames(ErrorNames.TooShort, field.validate, '22')
+ self.assertRaisesErrorNames(ErrorNames.TooLong, field.validate, '666666')
+ self.assertRaisesErrorNames(ErrorNames.TooLong, field.validate, '999999999')
+
+
class BoolTestCase(FieldTestCase):
def test_validate(self):
field = Bool(
@@ -194,6 +252,7 @@
except ValidationError, e:
self.fail('Expected no ValidationError, but we got %s.' % e.error_name)
+ self.assertRaisesErrorNames(ErrorNames.TooSmall, field.validate, -10)
self.assertRaisesErrorNames(ErrorNames.TooSmall, field.validate, -1)
self.assertRaisesErrorNames(ErrorNames.TooBig, field.validate, 11)
self.assertRaisesErrorNames(ErrorNames.TooBig, field.validate, 20)