• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.generate_validator_from_schema函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_field_declared_as_required_with_field_present_is_valid

def test_field_declared_as_required_with_field_present_is_valid():
    schema = {
        'required': True,
    }
    validator = generate_validator_from_schema(schema)

    validator('John Smith')
开发者ID:dhilton,项目名称:flex,代码行数:7,代码来源:test_required_validation.py


示例2: test_invalid_values_against_list_of_schemas

def test_invalid_values_against_list_of_schemas():
    from django.core.exceptions import ValidationError

    schema = {
        'type': ARRAY,
        'items': [
            {'type': INTEGER, 'minimum': 0, 'maximum': 10},
            {'type': STRING, 'minLength': 3, 'maxLength': 5},
            {'type': INTEGER, 'minimum': 0, 'maximum': 10},
            {'type': STRING, 'minLength': 3, 'maxLength': 5},
            {'type': INTEGER, 'minimum': 0, 'maximum': 10},
        ],
    }

    validator = generate_validator_from_schema(schema)

    with pytest.raises(ValidationError) as err:
        validator(
            [11, 'abc-abc', -5, 'ab', 'wrong-type'],
            inner=True,
        )

    assert 'items' in err.value.messages[0]
    assert len(err.value.messages[0]['items']) == 5
    _1, _2, _3, _4, _5 = err.value.messages[0]['items']

    assert 'maximum' in _1
    assert 'maxLength' in _2
    assert 'minimum' in _3
    assert 'minLength' in _4
    assert 'type' in _5
开发者ID:dhilton,项目名称:flex,代码行数:31,代码来源:test_items_validation.py


示例3: test_date_time_is_noop_when_not_present_or_required

def test_date_time_is_noop_when_not_present_or_required():
    schema = {
        'format': 'date-time',
    }
    validator = generate_validator_from_schema(schema)

    validator(EMPTY)
开发者ID:dhilton,项目名称:flex,代码行数:7,代码来源:test_format_validation.py


示例4: test_field_declared_as_required_with_field_present_is_valid

def test_field_declared_as_required_with_field_present_is_valid():
    schema = {
        'type': OBJECT,
        'required': [
            'field-A',
            # 'field-B',
        ],
    }
    validator = generate_validator_from_schema(schema)

    try:
        validator({'field-A': 'present'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'required.field-A',
        errors,
    )
    assert_path_not_in_errors(
        'required.field-B',
        errors,
    )
开发者ID:Arable,项目名称:flex,代码行数:25,代码来源:test_required_validation.py


示例5: test_integer_type_valid

def test_integer_type_valid():
    schema = {
        'type': INTEGER,
    }
    validator = generate_validator_from_schema(schema)

    validator(1)
开发者ID:Arable,项目名称:flex,代码行数:7,代码来源:test_type_validation.py


示例6: test_date_time_format_validation

def test_date_time_format_validation(when):
    schema = {
        'format': 'date-time',
    }
    validator = generate_validator_from_schema(schema)

    validator(when)
开发者ID:dhilton,项目名称:flex,代码行数:7,代码来源:test_format_validation.py


示例7: test_enum_noop_when_not_required_and_field_not_present

def test_enum_noop_when_not_required_and_field_not_present():
    schema = {
        'enum': [True, False, 1.0, 2.0, 'A'],
    }
    validator = generate_validator_from_schema(schema)

    validator(EMPTY)
开发者ID:dhilton,项目名称:flex,代码行数:7,代码来源:test_enum_validation.py


示例8: test_enum_with_valid_array

def test_enum_with_valid_array(letters):
    schema = {
        'enum': [2, 1, 'a', 'b', 'c', True, False],
    }
    validator = generate_validator_from_schema(schema)

    validator(letters)
开发者ID:dhilton,项目名称:flex,代码行数:7,代码来源:test_enum_validation.py


示例9: test_enum_disperate_text_types

def test_enum_disperate_text_types(enum_value, value):
    schema = {
        'enum': [enum_value],
    }
    validator = generate_validator_from_schema(schema)

    validator(value)
开发者ID:Arable,项目名称:flex,代码行数:7,代码来源:test_enum_validation.py


示例10: test_allof_complex

def test_allof_complex():
    schema_without_allof = {
        'type': 'object',
        'properties': {
            'name': {
                'type': STRING,
            },
            'age': {
                'type': INTEGER,
            }
        }
    }

    schema_with_allof = {
        'type': 'object',
        'allOf': [
            {
                'properties': {
                    'name': {
                        'type': STRING,
                    }
                }
            },
            {
                'properties': {
                    'age': {
                        'type': INTEGER,
                    }
                }
            },
        ]
    }

    good_data = dict(name="foo", age=42)
    bad_data = dict(name="foo", age="bar")

    validator_without_allof = generate_validator_from_schema(schema_without_allof)
    validator_with_allof = generate_validator_from_schema(schema_with_allof)

    validator_without_allof(good_data)
    validator_with_allof(good_data)

    with pytest.raises(ValidationError):
        validator_without_allof(bad_data)

    with pytest.raises(ValidationError):
        validator_with_allof(bad_data)
开发者ID:pipermerriam,项目名称:flex,代码行数:47,代码来源:test_allof_validation.py


示例11: test_multiple_of_is_noop_if_not_required_and_not_present

def test_multiple_of_is_noop_if_not_required_and_not_present():
    schema = {
        'type': INTEGER,
        'multipleOf': 0.3,
    }
    validator = generate_validator_from_schema(schema)

    validator(EMPTY)
开发者ID:Arable,项目名称:flex,代码行数:8,代码来源:test_multiple_of_validation.py


示例12: test_float_multiple_of

def test_float_multiple_of(count):
    schema = {
        'type': NUMBER,
        'multipleOf': 0.1,
    }
    validator = generate_validator_from_schema(schema)

    validator(count)
开发者ID:Arable,项目名称:flex,代码行数:8,代码来源:test_multiple_of_validation.py


示例13: test_unique_items_is_noop_when_not_required_and_not_present

def test_unique_items_is_noop_when_not_required_and_not_present():
    schema = {
        'type': ARRAY,
        'uniqueItems': True,
    }
    validator = generate_validator_from_schema(schema)

    validator(EMPTY)
开发者ID:Arable,项目名称:flex,代码行数:8,代码来源:test_unique_items_validation.py


示例14: test_max_properties_is_noop_when_not_required_or_present

def test_max_properties_is_noop_when_not_required_or_present():
    schema = {
        'type': OBJECT,
        'maxProperties': 2,
    }
    validator = generate_validator_from_schema(schema)

    validator(EMPTY)
开发者ID:dhilton,项目名称:flex,代码行数:8,代码来源:test_min_max_properties_validation.py


示例15: test_inclusive_minimum_validation_with_valid_numbers

def test_inclusive_minimum_validation_with_valid_numbers(width):
    schema = {
        'type': NUMBER,
        'minimum': 5,
    }
    validator = generate_validator_from_schema(schema)

    validator(width)
开发者ID:Arable,项目名称:flex,代码行数:8,代码来源:test_minimum_and_maximum_validation.py


示例16: test_enum_with_invalid_items

def test_enum_with_invalid_items(letters):
    schema = {
        'enum': [True, False, 1.0, 2.0, 'A'],
    }
    validator = generate_validator_from_schema(schema)

    with pytest.raises(ValueError):
        validator(letters)
开发者ID:dhilton,项目名称:flex,代码行数:8,代码来源:test_enum_validation.py


示例17: test_maximum_length_is_noop_when_not_required_and_not_present

def test_maximum_length_is_noop_when_not_required_and_not_present():
    schema = {
        'type': STRING,
        'maxLength': 5,
    }
    validator = generate_validator_from_schema(schema)

    validator(EMPTY)
开发者ID:dhilton,项目名称:flex,代码行数:8,代码来源:test_min_and_max_length_validation.py


示例18: test_maximum_length_with_valid_string

def test_maximum_length_with_valid_string(zipcode):
    schema = {
        'type': STRING,
        'maxLength': 10,
    }
    validator = generate_validator_from_schema(schema)

    validator(zipcode)
开发者ID:dhilton,项目名称:flex,代码行数:8,代码来源:test_min_and_max_length_validation.py


示例19: test_pattern_on_good_strings

def test_pattern_on_good_strings(zipcode):
    schema = {
        'type': STRING,
        'pattern': ZIPCODE_REGEX,
    }
    validator = generate_validator_from_schema(schema)

    validator(zipcode)
开发者ID:dhilton,项目名称:flex,代码行数:8,代码来源:test_pattern_validation.py


示例20: test_valid_array_with_max_items

def test_valid_array_with_max_items(letters):
    schema = {
        'type': ARRAY,
        'maxItems': 3,
    }
    validator = generate_validator_from_schema(schema)

    validator(letters)
开发者ID:dhilton,项目名称:flex,代码行数:8,代码来源:test_min_max_items_validation.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_basic_fullyvirt_guest函数代码示例发布时间:2022-05-27
下一篇:
Python utils.generate_response函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap