示例#1
0
    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))
示例#2
0
    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'))
示例#3
0
    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))
示例#4
0
    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))
示例#5
0
    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'))
示例#6
0
    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'))
示例#7
0
    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))
示例#8
0
    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'))