def test_string_validator(self): v = String() self.assertEqual("foo", v.validate("foo")) with self.assertRaises(ValidationError) as c: v.validate(1) self.assertEqual("Expected str got int instead.", str(c.exception))
def test_string_validator_min_len_kw(self): v = String(min_len=3) with self.assertRaises(ValidationError) as c: v.validate("fo") self.assertEqual("String must be at least length 3.", str(c.exception))
def test_string_validator_max_len_kw(self): v = String(max_len=3) self.assertEqual("foo", v.validate("foo")) with self.assertRaises(ValidationError) as c: v.validate("foobar") self.assertEqual("String exceeds max length of 3.", str(c.exception))