当前位置: 首页>>代码示例>>Python>>正文


Python testutil.catch_validation_errors函数代码示例

本文整理汇总了Python中turbogears.testutil.catch_validation_errors函数的典型用法代码示例。如果您正苦于以下问题:Python catch_validation_errors函数的具体用法?Python catch_validation_errors怎么用?Python catch_validation_errors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了catch_validation_errors函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_nested_schemas_good_values

    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)
开发者ID:thraxil,项目名称:gtreed,代码行数:25,代码来源:test_nested_widgets.py

示例2: test_goodvalues

    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()
开发者ID:OnShift,项目名称:turbogears,代码行数:7,代码来源:test_widgets.py

示例3: test_input_errors

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"])
开发者ID:OnShift,项目名称:turbogears,代码行数:7,代码来源:test_forms.py

示例4: test_widget_validator_and_schema_failure

 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()
开发者ID:thraxil,项目名称:gtreed,代码行数:7,代码来源:test_widgets.py

示例5: test_badvalues

    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()
开发者ID:thraxil,项目名称:gtreed,代码行数:7,代码来源:test_widgets.py

示例6: test_validate_outermost

    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
开发者ID:thraxil,项目名称:gtreed,代码行数:8,代码来源:test_nested_widgets.py

示例7: test_good_values_schema

    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
开发者ID:thraxil,项目名称:gtreed,代码行数:8,代码来源:test_nested_widgets.py

示例8: test_good_and_bad_values_schema

    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
开发者ID:thraxil,项目名称:gtreed,代码行数:8,代码来源:test_nested_widgets.py

示例9: test_simple_form_bad

    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
开发者ID:thraxil,项目名称:gtreed,代码行数:10,代码来源:test_new_validation.py

示例10: test_simple_form_bad2

    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
开发者ID:marqui678,项目名称:finalchance.Panopta,代码行数:10,代码来源:test_new_validation.py

示例11: test_nested_form_bad

    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
开发者ID:thraxil,项目名称:gtreed,代码行数:11,代码来源:test_new_validation.py

示例12: test_validate_sub

    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
开发者ID:thraxil,项目名称:gtreed,代码行数:13,代码来源:test_nested_widgets.py

示例13: test_validate_sub2_schema

    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)
开发者ID:thraxil,项目名称:gtreed,代码行数:15,代码来源:test_nested_widgets.py

示例14: test_nested_schemas

    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
开发者ID:thraxil,项目名称:gtreed,代码行数:39,代码来源:test_nested_widgets.py

示例15: test_mixed_validators

    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
开发者ID:thraxil,项目名称:gtreed,代码行数:36,代码来源:test_nested_widgets.py


注:本文中的turbogears.testutil.catch_validation_errors函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。