Beispiel #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))
Beispiel #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'))
Beispiel #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))
Beispiel #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))
Beispiel #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'))
Beispiel #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'))
Beispiel #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))
Beispiel #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'))