Ejemplo n.º 1
0
 def test_lengthMin(self):
     v = validation.LengthValidator(min=5)
     v.validate(types.String(), None)
     v.validate(types.String(), '12345')
     v.validate(types.String(), '1234567890')
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), '')
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), '1234')
Ejemplo n.º 2
0
 def test_rangeMax(self):
     v = validation.RangeValidator(max=5)
     v.validate(types.Integer(), None)
     v.validate(types.Integer(), -5)
     v.validate(types.Integer(), 0)
     v.validate(types.Integer(), 5)
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), 6)
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), 10)
Ejemplo n.º 3
0
 def test_range(self):
     self.assertRaises(AssertionError, validation.RangeValidator)
     v = validation.RangeValidator(min=5, max=10)
     v.validate(types.Integer(), None)
     v.validate(types.Integer(), 5)
     v.validate(types.Integer(), 7.5)
     v.validate(types.Integer(), 10)
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), 0)
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), 4)
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), -5)
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), 11)
Ejemplo n.º 4
0
 def test_length(self):
     self.assertRaises(AssertionError, validation.LengthValidator)
     v = validation.LengthValidator(min=5, max=10)
     v.validate(types.String(), None)
     v.validate(types.String(), '12345')
     v.validate(types.String(), '1234567')
     v.validate(types.String(), '1234567890')
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), '')
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), '1234')
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), '12345678901')
Ejemplo n.º 5
0
 def test_pattern(self):
     v = validation.PatternValidator('^[0-9]{3,5}$')
     v.validate(types.String(), None)
     v.validate(types.String(), '123')
     v.validate(types.String(), '12345')
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), ' 123')
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), '1')
     self.assertRaises(validation.FieldValidationError, v.validate,
                       types.String(), 'foo')
Ejemplo n.º 6
0
 def test_required(self):
     v = validation.RequiredValidator()
     v.validate(types.String(), 'bar')
     self.assertRaises(validation.FieldRequiredError, v.validate,
                       types.String(), None)