def test_validate_without_includes(self): validator = Range(12, 17, False, False) self.assertRaises( ValidationError, validator.validate, 11 ) self.assertRaises( ValidationError, validator.validate, 18 ) self.assertRaises( ValidationError, validator.validate, 12 ) self.assertRaises( ValidationError, validator.validate, 17 ) self.assertEqual(15, validator.validate(15))
def test_validate_with_string(self): validator = Range('c', 'h', validator=None) self.assertRaises(ValidationError, validator.validate, 'a') self.assertRaises(ValidationError, validator.validate, 'i') self.assertEqual('d', validator.validate('d')) self.assertEqual('h', validator.validate('h')) self.assertEqual('c', validator.validate('c'))
def test_validate_with_includes(self): validator = Range(12, 17) self.assertRaises(ValidationError, validator.validate, 11) self.assertRaises(ValidationError, validator.validate, 18) self.assertEqual(15, validator.validate(15)) self.assertEqual(12, validator.validate(12)) self.assertEqual(17, validator.validate(17))
def test_validate_with_invalid_type(self): validator = Range(12, 17, validator=Integer()) self.assertRaises( ValidationError, validator.validate, '12.57' ) self.assertEqual(15, validator.validate(15))
def test_validate_with_string(self): validator = Range('c', 'h', validator=None) self.assertRaises( ValidationError, validator.validate, 'a' ) self.assertRaises( ValidationError, validator.validate, 'i' ) self.assertEqual('d', validator.validate('d')) self.assertEqual('h', validator.validate('h')) self.assertEqual('c', validator.validate('c'))
def test_validate_with_type(self): validator = Range(12, 17, validator=Float()) self.assertEqual(15, validator.validate(15)) self.assertEqual(12.57, validator.validate(12.57)) self.assertEqual(12.57, validator.validate('12.57'))
def test_validate_with_invalid_type(self): validator = Range(12, 17, validator=Integer()) self.assertRaises(ValidationError, validator.validate, '12.57') self.assertEqual(15, validator.validate(15))