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

Python utils.assert_message_in_errors函数代码示例

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

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



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

示例1: test_request_validation_with_invalid_operation_on_path

def test_request_validation_with_invalid_operation_on_path():
    """
    Test that request validation detects request paths that are not declared
    in the schema.
    """
    schema = SchemaFactory(
        paths={
            '/post': {
                'post': {},
            },
        },
    )

    request = RequestFactory(url='http://www.example.com/post')

    with pytest.raises(ValidationError) as err:
        validate_request(
            request=request,
            schema=schema,
        )

    assert_message_in_errors(
        MESSAGES['request']['invalid_method'],
        err.value.detail,
        'method',
    )
开发者ID:Arable,项目名称:flex,代码行数:26,代码来源:test_request_method_validation.py


示例2: test_basic_response_body_schema_validation_with_invalid_value

def test_basic_response_body_schema_validation_with_invalid_value():
    schema = SchemaFactory(
        paths={
            '/get': {
                'get': {
                    'responses': {
                        200: {
                            'description': 'Success',
                            'schema': {'type': INTEGER},
                        }
                    },
                },
            },
        },
    )

    response = ResponseFactory(
        url='http://www.example.com/get',
        status_code=200,
        content_type='application/json',
        content=json.dumps('not-an-integer'),
    )

    with pytest.raises(ValidationError) as err:
        validate_response(
            response=response,
            request_method='get',
            schema=schema,
        )

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'body.schema.type',
    )
开发者ID:Arable,项目名称:flex,代码行数:35,代码来源:test_schema_validation.py


示例3: test_produces_validation_for_invalid_mimetype_from_operation_definition

def test_produces_validation_for_invalid_mimetype_from_operation_definition():
    """
    Test the situation when the operation definition has overridden the global
    allowed mimetypes, that that the local value is used for validation.
    """
    response = ResponseFactory(
        content_type='application/xml',
        url='http://www.example.com/get',
    )

    schema = SchemaFactory(
        produces=['application/xml'],
        paths={
            '/get': {'get': {
                'responses': {200: {'description': 'Success'}},
                'produces': ['application/json'],
            }},
        },
    )

    with pytest.raises(ValidationError) as err:
        validate_response(
            response=response,
            request_method='get',
            schema=schema,
        )

    assert_message_in_errors(
        MESSAGES['content_type']['invalid'],
        err.value.detail,
        'body.produces',
    )
开发者ID:Arable,项目名称:flex,代码行数:32,代码来源:test_produces_validation.py


示例4: test_request_validation_with_parametrized_path_with_invalid_value

def test_request_validation_with_parametrized_path_with_invalid_value():
    """
    Test that request validation finds and validates parametrized paths.
    Ensure that it does validation on the values.
    """
    schema = SchemaFactory(
        paths={
            '/get/{id}': {
                'get': {'responses': {'200': {'description': 'Success'}}},
                'parameters': [
                    {
                        'name': 'id',
                        'in': PATH,
                        'description': 'The Primary Key',
                        'type': INTEGER,
                        'required': True,
                    }
                ]
            },
        }
    )

    request = RequestFactory(url='http://www.example.com/get/abcd')

    with pytest.raises(ValidationError) as err:
        validate_request(
            request=request,
            schema=schema,
        )

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'path.id.type',
    )
开发者ID:ivan-c,项目名称:flex,代码行数:35,代码来源:test_request_path_validation.py


示例5: test_parameter_items_validation_on_invalid_array

def test_parameter_items_validation_on_invalid_array():
    parameters = parameters_validator([
        {
            'name': 'id',
            'in': QUERY,
            'description': 'id',
            'items': {
                'type': INTEGER,
                'minimum': 0,
            },
            'type': ARRAY,
        },
    ])
    value = [1, 2, '3', -1, 4]
    parameter_values = {
        'id': value,
    }

    with pytest.raises(ValidationError) as err:
        validate_parameters(parameter_values, parameters, context={})

    assert_message_in_errors(
        MESSAGES['minimum']['invalid'],
        err.value.detail,
        'id.items.type',
    )
    assert_message_in_errors(
        MESSAGES['minimum']['invalid'],
        err.value.detail,
        'id.items.minimum',
    )
开发者ID:Arable,项目名称:flex,代码行数:31,代码来源:test_items_validation.py


示例6: test_nullable_enum_with_null_values_strict

def test_nullable_enum_with_null_values_strict(enum, value, monkeypatch):

    parameters = parameters_validator([
        {
            'name': 'id',
            'in': PATH,
            'description': 'id',
            'type': [STRING, NUMBER, BOOLEAN],
            'required': True,
            'enum': enum,
            'x-nullable': True
        },
    ])
    parameter_values = {
        'id': value,
    }

    monkeypatch.setattr(os, 'environ', {FLEX_DISABLE_X_NULLABLE: '1'})
    with pytest.raises(ValidationError) as err:
        validate_parameters(parameter_values, parameters, {})

    assert_message_in_errors(
        MESSAGES['enum']['invalid'],
        err.value.detail,
        'id.enum',
    )
开发者ID:pipermerriam,项目名称:flex,代码行数:26,代码来源:test_enum_validation.py


示例7: test_request_parameter_validation

def test_request_parameter_validation():
    """
    Test that request validation does parameter validation.  This is largely a
    smoke test to ensure that parameter validation is wired into request
    validation correctly.
    """
    schema = SchemaFactory(
        paths={
            "/get/{id}/": {
                "parameters": [
                    {"name": "id", "in": PATH, "description": "id", "required": True, "type": STRING, "format": "uuid"},
                    {"name": "page", "in": QUERY, "type": INTEGER},
                ],
                "get": {"responses": {200: {"description": "Success"}}},
            }
        }
    )

    request = RequestFactory(url="http://www.example.com/get/32/?page=abcd")

    with pytest.raises(ValidationError) as err:
        validate_request(request=request, schema=schema)

    assert_message_in_errors(MESSAGES["format"]["invalid_uuid"], err.value.detail, "method.parameters.path.id.format")

    assert_message_in_errors(MESSAGES["type"]["invalid"], err.value.detail, "query.page.type")
开发者ID:Arable,项目名称:flex,代码行数:26,代码来源:test_request_parameter_validation.py


示例8: test_request_header_validation

def test_request_header_validation():
    schema = SchemaFactory(
        paths={
            '/get/': {
                'get': {
                    'responses': {200: {'description': "Success"}},
                    'parameters': [
                        {
                            'name': 'Authorization',
                            'in': HEADER,
                            'type': INTEGER,
                        }
                    ]
                },
            },
        },
    )

    request = RequestFactory(
        url='http://www.example.com/get/',
        headers={'Authorization': 'abc'},
    )

    with pytest.raises(ValidationError) as err:
        validate_request(
            request=request,
            schema=schema,
        )

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'method.parameters.headers.Authorization.type',
    )
开发者ID:Arable,项目名称:flex,代码行数:34,代码来源:test_request_header_validation.py


示例9: test_nullable_enum_with_invalid_values

def test_nullable_enum_with_invalid_values(enum, value):

    parameters = parameters_validator([
        {
            'name': 'id',
            'in': PATH,
            'description': 'id',
            'type': [STRING, NUMBER, BOOLEAN],
            'required': True,
            'enum': enum,
            'x-nullable': True
        },
    ])
    parameter_values = {
        'id': value,
    }

    with pytest.raises(ValidationError) as err:
        validate_parameters(parameter_values, parameters, {})

    assert_message_in_errors(
        MESSAGES['enum']['invalid'],
        err.value.detail,
        'id.enum',
    )
开发者ID:pipermerriam,项目名称:flex,代码行数:25,代码来源:test_enum_validation.py


示例10: test_mimetype_with_invalid_value_in_multiple_values

def test_mimetype_with_invalid_value_in_multiple_values():
    with pytest.raises(ValidationError) as err:
        mimetype_validator(['application/json', 'not-a-valid-mimetype'])

    assert_message_in_errors(
        MESSAGES['mimetype']['invalid'],
        err.value.detail,
    )
开发者ID:pipermerriam,项目名称:flex,代码行数:8,代码来源:test_mimetype_validation.py


示例11: test_multi_format_invalid_in_values

def test_multi_format_invalid_in_values(in_):
    parameter = ParameterFactory(**{"collectionFormat": MULTI, "in": in_})
    with pytest.raises(ValidationError) as err:
        single_parameter_validator(parameter)

    assert_message_in_errors(
        MESSAGES["collection_format"]["invalid_based_on_in_value"], err.value.detail, "collectionFormat"
    )
开发者ID:Arable,项目名称:flex,代码行数:8,代码来源:test_collection_format.py


示例12: test_mimetype_with_invalid_values

def test_mimetype_with_invalid_values(value):
    with pytest.raises(ValidationError) as err:
        mimetype_validator(value)

    assert_message_in_errors(
        MESSAGES['mimetype']['invalid'],
        err.value.detail,
    )
开发者ID:pipermerriam,项目名称:flex,代码行数:8,代码来源:test_mimetype_validation.py


示例13: test_schema_for_invalid_types

def test_schema_for_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator(value)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'type',
    )
开发者ID:Arable,项目名称:flex,代码行数:9,代码来源:test_schema_validator.py


示例14: test_required_with_invalid_sub_types

def test_required_with_invalid_sub_types():
    with pytest.raises(ValidationError) as err:
        schema_validator({'required': ['field-A', True, 'Field-B']})

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'required.type',
    )
开发者ID:Arable,项目名称:flex,代码行数:9,代码来源:test_required.py


示例15: test_required_with_invalid_types

def test_required_with_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator({'required': value})

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'required.type',
    )
开发者ID:Arable,项目名称:flex,代码行数:9,代码来源:test_required.py


示例16: test_mimetype_invalid_for_non_array_value

def test_mimetype_invalid_for_non_array_value(value):
    with pytest.raises(ValidationError) as err:
        mimetype_validator(value)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'type',
    )
开发者ID:pipermerriam,项目名称:flex,代码行数:9,代码来源:test_mimetype_validation.py


示例17: test_in_must_be_one_of_valid_values

def test_in_must_be_one_of_valid_values():
    with pytest.raises(ValidationError) as err:
        single_parameter_validator({'in': 'not-a-valid-in-value'})

    assert_message_in_errors(
        MESSAGES['enum']['invalid'],
        err.value.detail,
        'in.enum',
    )
开发者ID:Arable,项目名称:flex,代码行数:9,代码来源:test_in_validation.py


示例18: test_enum_with_empty_array_is_invalid

def test_enum_with_empty_array_is_invalid():
    with pytest.raises(ValidationError) as err:
        schema_validator({'enum': []})

    assert_message_in_errors(
        MESSAGES['min_items']['invalid'],
        err.value.detail,
        'enum.minItems',
    )
开发者ID:Arable,项目名称:flex,代码行数:9,代码来源:test_enum.py


示例19: test_pattern_with_invalid_regex

def test_pattern_with_invalid_regex():
    with pytest.raises(ValidationError) as err:
        schema_validator({'pattern': '(arrst'})

    assert_message_in_errors(
        MESSAGES['pattern']['invalid_regex'],
        err.value.detail,
        'pattern',
    )
开发者ID:Arable,项目名称:flex,代码行数:9,代码来源:test_pattern.py


示例20: test_type_with_invalid_single_type

def test_type_with_invalid_single_type():
    with pytest.raises(ValidationError) as err:
        single_parameter_validator({'type': 'not-a-valid-type'})

    assert_message_in_errors(
        MESSAGES['enum']['invalid'],
        err.value.detail,
        'type.enum',
    )
开发者ID:Arable,项目名称:flex,代码行数:9,代码来源:test_type_validation.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.assert_nodes_equal函数代码示例发布时间:2022-05-27
下一篇:
Python utils.assert_latest_log函数代码示例发布时间: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