Beispiel #1
0
 def test_validation(self):
     field = FloatField()
     field._set_attr_name('n')
     self.assertIsNone(field.validate(None))
     self.assertIsNone(field.validate(''))
     self.assertIsNone(field.validate('0'))
     self.assertIsNone(field.validate('1'))
     self.assertIsNone(field.validate(1))
     self.assertIsNone(field.validate(1.34))
     self.assertIsNone(field.validate('1,090,898.00'))
     self.assertEqual('Must be a number', field.validate('foo'))
     self.assertEqual('Must be a number', field.validate('123h'))
     self.assertEqual('Must be a number', field.validate('0x456'))
Beispiel #2
0
 def test_validation_upper(self):
     field = FloatField(upper=1.3)
     field._set_attr_name('n')
     self.assertIsNone(field.validate('1.29'))
     self.assertEqual('Must be less than 1.3', field.validate('2'))
Beispiel #3
0
 def test_validation_lower(self):
     field = FloatField(lower=1.2)
     field._set_attr_name('n')
     self.assertIsNone(field.validate('1.21'))
     self.assertEqual('Must be greater than 1.2', field.validate('0'))