def test_type_checking(self): Text().validate('string') Text().validate(u'unicode') Text().validate(bytearray('bytearray', encoding='ascii')) with self.assertRaises(ValidationError): Text(required=True).validate(None) with self.assertRaises(ValidationError): Text().validate(5) with self.assertRaises(ValidationError): Text().validate(True)
def test_min_length(self): #min len defaults to 1 col = Text() col.validate('') col.validate('b') #test not required defaults to 0 Text(required=False).validate('') #test arbitrary lengths Text(min_length=0).validate('') Text(min_length=5).validate('blake') Text(min_length=5).validate('blaketastic') with self.assertRaises(ValidationError): Text(min_length=6).validate('blake')
def test_non_required_validation(self): """ Tests that validation is ok on none and blank values if required is False """ Text().validate('') Text().validate(None)
def test_max_length(self): Text(max_length=5).validate('blake') with self.assertRaises(ValidationError): Text(max_length=5).validate('blaketastic')