Beispiel #1
0
 def test_inside_any_on_own(self):
     """
     Check inside an Any, on own.
     """
     assert util.validation_includes(validator.Any(validator.Required()),
                                     validator.Required)
     assert not util.validation_includes(
         validator.Any(validator.Required()), validator.Email)
Beispiel #2
0
 def test_inside_any_only_type(self):
     """
     Check inside an Any, amongst validators of same type.
     """
     assert util.validation_includes(
         validator.Any(validator.Required(), validator.Required()),
         validator.Required)
     assert not util.validation_includes(
         validator.Any(validator.Required(), validator.Required()),
         validator.Email)
Beispiel #3
0
 def test_inside_any_with_others(self):
     """
     Check when inside an Any with other types.
     """
     assert not util.validation_includes(
         validator.Any(validator.Required(), validator.Email()),
         validator.Required)
     assert not util.validation_includes(
         validator.Any(validator.Required(), validator.Email()),
         validator.Email)
Beispiel #4
0
class Test_RequiredAndIntegerOrString(unittest.TestCase):

    type = 'RequiredAndIntegerOrString'
    fn = validator.All(validator.Required(),
                       validator.Any(validator.String(), validator.Integer()))

    def test_validate_pass(self):
        self.section = 'pass'
        values = [
            '1',
            1,
            1L,
        ]
        check_pass('class', self, self.fn, values)

    def test_validate_fail(self):
        self.section = 'fail'
        values = [
            0.5,
            datetime.now(),
            None,
        ]
        check_fail('class', self, self.fn, values)

    def test_messages(self):
        try:
            self.fn(datetime.now())
        except error.Invalid, e:
            self.assertEquals(len(e.errors), 2)
            assert 'string' in ''.join(e.errors)
            assert 'integer' in ''.join(e.errors)
Beispiel #5
0
    def test_complex_error_all_required_2(self):

        schema = schemaish.Structure([
            ("one",
             schemaish.Integer(validator=v.All(
                 v.Required(),
                 v.Integer(),
                 v.Any(v.Range(min=18), v.Range(min=20)),
             ))),
        ])
        f = formish.Form(schema, name="form", add_default_action=False)

        f.add_action('submit', "Submit Me")
        r = webob.Request.blank('http://localhost/',
                                environ={'REQUEST_METHOD': 'POST'})
        r.POST['__formish_form__'] = 'form'
        r.POST['one'] = ''
        try:
            f.validate(r)
        except fv.FormError:
            assert str(
                f.errors['one']
            ) == 'is required; Please fix any of: must be greater than or equal to 18; must be greater than or equal to 20'
            assert str(f['one'].field.errors.exceptions[1].exceptions[1]
                       ) == 'must be greater than or equal to 20'
Beispiel #6
0
    def test_with_functions(self):
        """
        Check hunting doesn't explode with plain old functions.
        """
        def f(v):
            pass

        assert not util.validation_includes(f, validator.Required)
        assert not util.validation_includes(validator.All(f, f),
                                            validator.Required)
        assert util.validation_includes(validator.All(f, validator.Required()),
                                        validator.Required)
        assert not util.validation_includes(
            validator.Any(f, validator.Required()), validator.Required)
Beispiel #7
0
class TestAny_RangeInteger(unittest.TestCase):

    type = 'AnyRangeInteger'
    fn = validator.Any(validator.Range(min=8), validator.Integer())

    def test_validate_pass(self):
        self.section = 'pass'
        values = [
            4,
            12.3,
            15,
            None,
        ]
        check_pass('class', self, self.fn, values)

    def test_validate_fail(self):
        self.section = 'fail'
        values = [
            3.4,
        ]
        check_fail('class', self, self.fn, values)