Exemplo n.º 1
0
 def test_noattrs(self):
     try:
         validate.is_in_range(1)
         return
     except:
         pass
     self.fail('unexpected error using no attrs for validate.is_in_range')
Exemplo n.º 2
0
 def test_noattrs(self):
     try:
         validate.is_in_range(1)
         return
     except:
         pass
     self.fail('unexpected error using no attrs for validate.is_in_range')
Exemplo n.º 3
0
 def __call__(self, v):
     try:
         validate.is_in_range(v,
                              min=self.min,
                              max=self.max,
                              messages=self.messages)
     except Invalid, e:
         raise Invalid(e.message, validator=self)
Exemplo n.º 4
0
class TestRange(unittest.TestCase):

    type = 'Range'

    fn_min = staticmethod(lambda v: validate.is_in_range(v, min=3))
    class_fn_min = validator.Range(min=3)

    fn_max = staticmethod(lambda v: validate.is_in_range(v, max=3))
    class_fn_max = validator.Range(max=3)

    fn_between = staticmethod(lambda v: validate.is_in_range(v, min=1, max=3))
    class_fn_between = validator.Range(min=1, max=3)

    def test_validate_min_pass(self):
        self.section = 'pass'
        values = [
            4,
            5.5,
        ]
        check_pass('function', self, self.fn_min, values)
        check_pass('class', self, self.class_fn_min, values)

    def test_validate_min_fail(self):
        self.section = 'fail'
        values = [
            0,
            -1,
            -0.23,
        ]
        check_fail('function', self, self.fn_min, values)
        check_fail('class', self, self.class_fn_min, values)

    def test_validate_max_pass(self):
        self.section = 'pass'
        values = [
            0,
            -1,
            -0.23,
            2.99,
        ]
        check_pass('function', self, self.fn_max, values)
        check_pass('class', self, self.class_fn_max, values)

    def test_validate_max_fail(self):
        self.section = 'fail'
        values = [
            4,
            5,
            6.9845,
        ]
        check_fail('function', self, self.fn_max, values)
        check_fail('class', self, self.class_fn_max, values)

    def test_validate_between_pass(self):
        self.section = 'pass'
        values = [
            1.4,
            1,
            2.23,
            2.99,
            3,
        ]
        check_pass('function', self, self.fn_between, values)
        check_pass('class', self, self.class_fn_between, values)

    def test_validate_between_fail(self):
        self.section = 'fail'
        values = [
            4,
            5,
            6.9845,
            0,
            -2,
            -9,
        ]
        check_fail('function', self, self.fn_between, values)
        check_fail('class', self, self.class_fn_between, values)

    def test_messages(self):
        try:
            self.fn_min(-999999)
        except error.Invalid, e:
            assert 'greater' in e.message
        try:
            self.fn_max(999999)
        except error.Invalid, e:
            assert 'less' in e.message
Exemplo n.º 5
0
 def __call__(self, v):
     try:
         validate.is_in_range(v, min=self.min, max=self.max, messages=self.messages)
     except Invalid, e:
         raise Invalid(e.message, validator=self)