def test_mixed_validators(self):
        """
        Tests that schema validators and single validators can be mixed
        safely.
        """
        values = dict(age="bad",
                      number="22",
                      sub=dict(age="bad",
                               number="bad",
                               sub2=dict(
                                   age="bad",
                                   number="bad",
                               )))

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert errors.pop('age', False)
        #assert values['number'] == 22

        # assert errors are not getting poluted errors from other levels of
        # the tree
        assert errors.keys() == ['sub']
        errors = errors['sub']
        assert errors.pop('age', False)
        assert errors.pop('number', False)

        assert errors.keys() == ['sub2']
        errors = errors['sub2']
        assert errors.pop('age', False)
        assert errors.pop('number', False)
        assert not errors
    def test_nested_schemas(self):
        """
        Tests that we can nest schema validators safely.
        """
        values = dict(age="bad",
                      number="22",
                      sub=dict(age="27",
                               number="bad",
                               sub2=dict(
                                   age="bad",
                                   number="bad",
                               )))

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert errors.pop('age', False)
        #assert values['number'] == 22

        # assert errors are not getting poluted errors from other levels of
        # the tree
        assert errors.keys() == ['sub']
        errors = errors['sub']
        values = values['sub']
        #XXX This assertion fails :(
        #XXX But it's normal as the Schema doesn't convert good values in
        #    invalid Schemas, ATM
        #assert values['age'] == 27
        assert errors.pop('number', False)

        assert errors.keys() == ['sub2']
        errors = errors['sub2']
        assert errors.pop('age', False)
        assert errors.pop('number', False)
        assert not errors
Exemple #3
0
 def test_widget_validator_and_schema_failure(self):
     values = dict(name=u'Jos\xc3\xa9', age="ninetynine", passwd="fado",
                   passwd2="fadO")
     values, errors = catch_validation_errors(self.form, values)
     print values, errors
     assert "age" in errors.keys()
     assert "passwd2" in errors.keys()
    def test_nested_schemas_good_values(self):
        values = dict(
            age="21",
            number="22",
            sub=dict(
                age="27",
                number="28",
                sub2=dict(
                    age="33",
                    number="34",
                )
            )
        )

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert not errors
        assert (values["age"], values['number']) == (21, 22)

        values = values['sub']
        assert (values["age"], values['number']) == (27, 28)

        values = values['sub2']
        assert (values["age"], values['number']) == (33, 34)
Exemple #5
0
def test_input_errors():
    """Data is stored in the request object if there are errors"""
    form = widgets.TableForm(fields=[widgets.TextField("name"),
                      widgets.TextField("age", validator=validators.Int())])
    values = dict(name="ed", age="ed")
    values, errors = catch_validation_errors(form, values)
    assert "enter an integer" in str(errors["age"])
Exemple #6
0
    def test_badvalues(self):
        values = dict(name=u'Jos\xc3\xa9', age="99", passwd="fado",
                      passwd2="fadO")

        values, errors = catch_validation_errors(self.form, values)
        print errors
        assert "passwd2" in errors.keys()
 def test_widget_validator_failure(self):
     values = dict(name=u'Jos\xc3\xa9',
                   age="ninetynine",
                   passwd="fado",
                   passwd2="fado")
     values, errors = catch_validation_errors(self.form, values)
     assert "age" in errors.keys()
Exemple #8
0
    def test_goodvalues(self):
        values = dict(name=u'Jos\xc3\xa9', age="99", passwd="fado",
                      passwd2="fado")

        values, errors = catch_validation_errors(self.form, values)
        assert values['age'] == 99
        assert not errors.keys()
    def test_badvalues(self):
        values = dict(name=u'Jos\xc3\xa9',
                      age="99",
                      passwd="fado",
                      passwd2="fadO")

        values, errors = catch_validation_errors(self.form, values)
        assert "passwd2" in errors.keys()
    def test_validate_outermost(self):
        values = dict(age="twenty")
        values, errors = catch_validation_errors(self.form, values)

        print values, errors

        assert errors.pop('age', False)
        assert not errors
Exemple #11
0
    def test_good_values_schema(self):
        values = dict(age=22, sub=dict(sub2=dict(age=20)))

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert errors == {}
        assert values['age'] == 22
    def test_good_values_schema(self):
        values = dict(age=22, sub=dict(sub2=dict(age=20)))

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert errors == {}
        assert values['age'] == 22
    def test_good_and_bad_values_schema(self):
        values = dict(age="ddd", sub=dict(age="20", sub2=dict()))

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert errors.pop('age', False)
        assert not errors
Exemple #14
0
    def test_validate_outermost(self):
        values = dict(age="twenty")
        values, errors = catch_validation_errors(self.form, values)

        print values, errors

        assert errors.pop('age', False)
        assert not errors
Exemple #15
0
    def test_good_and_bad_values_schema(self):
        values = dict(age="ddd", sub=dict(age="20", sub2=dict()))

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert errors.pop('age', False)
        assert not errors
    def test_goodvalues(self):
        values = dict(name=u'Jos\xc3\xa9',
                      age="99",
                      passwd="fado",
                      passwd2="fado")

        values, errors = catch_validation_errors(self.form, values)
        assert values['age'] == 99
        assert not errors.keys()
Exemple #17
0
def test_input_errors():
    """Data is stored in the request object if there are errors"""
    form = widgets.TableForm(fields=[
        widgets.TextField("name"),
        widgets.TextField("age", validator=validators.Int())
    ])
    values = dict(name="ed", age="ed")
    values, errors = catch_validation_errors(form, values)
    assert "enter an integer" in str(errors["age"])
    def test_simple_form_bad2(self):
        """We can validate a simple form with errors, error from the schema """

        form = SimpleForm()
        value = dict(age="22", phone="bad")

        value, errors = catch_validation_errors(form, value)
        print value, errors
        assert errors.pop('phone')
        assert not errors
    def test_simple_form_bad(self):
        """ We can validate a simple form with errors """

        form = SimpleForm()
        value = dict(age="bad", phone="5555555")

        value, errors = catch_validation_errors(form, value)
        print value, errors
        assert errors.pop('age')
        assert not errors
Exemple #20
0
    def test_simple_form_bad(self):
        """ We can validate a simple form with errors """

        form = SimpleForm()
        value = dict(age="bad", phone="5555555")
        
        value, errors = catch_validation_errors(form, value)
        print value, errors
        assert errors.pop('age')
        assert not errors
    def test_simple_form_bad2(self):
        """ We can validate a simple form with errors, error from
        the schema """

        form = SimpleForm()
        value = dict(age="22", phone="bad")

        value, errors = catch_validation_errors(form, value)
        print value, errors
        assert errors.pop('phone')
        assert not errors
    def test_nested_form_bad(self):
        """ We can validate a form with a nested fieldset with errors"""
        form = SimpleForm(fields=SimpleForm.fields + [SimpleFieldSet()])
        value = dict(age="22", phone="5555555",
                     fs=dict(age="bad", phone="5555555"))

        value, errors = catch_validation_errors(form, value)
        print value, errors
        assert errors['fs'].pop('age')
        assert not errors.pop('fs')
        assert not errors
Exemple #23
0
    def test_nested_form_bad(self):
        """ We can validate a form with a nested fieldset with errors"""
        form = SimpleForm(fields=SimpleForm.fields + [SimpleFieldSet()])
        value = dict(age="22", phone="5555555", 
                     fs=dict(age="bad", phone="5555555"))

        value, errors = catch_validation_errors(form, value)
        print value, errors
        assert errors['fs'].pop('age')
        assert not errors.pop('fs')
        assert not errors
    def test_validate_sub(self):
        values = dict(sub=dict(age="twenty"))

        values, errors = catch_validation_errors(self.form, values)

        print values, errors
        # check the outermost dict is not poluted with errors from the inner
        # dicts
        assert not errors.has_key('age')

        errors = errors['sub']
        assert errors.pop('age', False)
        assert not errors
Exemple #25
0
    def test_validate_sub(self):
        values = dict(sub=dict(age="twenty"))

        values, errors = catch_validation_errors(self.form, values)

        print values, errors
        # check the outermost dict is not poluted with errors from the inner
        # dicts
        assert not errors.has_key('age')

        errors = errors['sub']
        assert errors.pop('age', False)
        assert not errors
    def test_validate_sub2_schema(self):
        values = dict(sub=dict(sub2=dict(age="twenty")))

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert not errors.has_key('age')

        errors = errors['sub']
        print values, errors
        assert not errors.has_key('age')

        errors = errors['sub2']
        print values, errors
        assert errors.pop('age', False)
Exemple #27
0
    def test_validate_sub2_schema(self):
        values = dict(sub=dict(sub2=dict(age="twenty")))

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert not errors.has_key('age')

        errors = errors['sub']
        print values, errors
        assert not errors.has_key('age')

        errors = errors['sub2']
        print values, errors
        assert errors.pop('age', False)
    def test_nested_schemas_good_values(self):
        values = dict(age="21",
                      number="22",
                      sub=dict(age="27",
                               number="28",
                               sub2=dict(
                                   age="33",
                                   number="34",
                               )))

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert not errors
        assert (values["age"], values['number']) == (21, 22)

        values = values['sub']
        assert (values["age"], values['number']) == (27, 28)

        values = values['sub2']
        assert (values["age"], values['number']) == (33, 34)
Exemple #29
0
    def test_nested_schemas(self):
        """
        Tests that we can nest schema validators safely.
        """
        values = dict(
            age="bad",
            number="22",
            sub=dict(
                age="27",
                number="bad",
                sub2=dict(
                    age="bad",
                    number="bad",
                )
            )
        )

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert errors.pop('age', False)
        #assert values['number'] == 22

        # assert errors are not getting poluted errors from other levels of
        # the tree
        assert errors.keys() == ['sub']
        errors = errors['sub']
        values = values['sub']
        #XXX This assertion fails :(
        #XXX But it's normal as the Schema doesn't convert good values in
        #    invalid Schemas, ATM
        #assert values['age'] == 27
        assert errors.pop('number', False)

        assert errors.keys() == ['sub2']
        errors = errors['sub2']
        assert errors.pop('age', False)
        assert errors.pop('number', False)
        assert not errors
Exemple #30
0
    def test_mixed_validators(self):
        """
        Tests that schema validators and single validators can be mixed
        safely.
        """
        values = dict(
            age="bad",
            number="22",
            sub=dict(
                age="bad",
                number="bad",
                sub2=dict(
                    age="bad",
                    number="bad",
                )
            )
        )

        values, errors = catch_validation_errors(self.form, values)
        print values, errors

        assert errors.pop('age', False)
        #assert values['number'] == 22

        # assert errors are not getting poluted errors from other levels of
        # the tree
        assert errors.keys() == ['sub']
        errors = errors['sub']
        assert errors.pop('age', False)
        assert errors.pop('number', False)

        assert errors.keys() == ['sub2']
        errors = errors['sub2']
        assert errors.pop('age', False)
        assert errors.pop('number', False)
        assert not errors