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

Python utils.assert_error_message_equal函数代码示例

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

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



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

示例1: test_response_parameter_validation

def test_response_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.
    """
    from django.core.exceptions import ValidationError

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

    response = ResponseFactory(url='http://www.example.com/get', status_code=301)

    with pytest.raises(ValidationError) as err:
        validate_response(
            response,
            paths=schema['paths'],
            base_path=schema.get('base_path', ''),
            context=schema,
            inner=True,
        )

    assert 'response' in err.value.messages[0]
    assert_error_message_equal(
        err.value.messages[0]['response'][0],
        MESSAGES['response']['invalid_status_code'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:34,代码来源:test_response_status_code_validation.py


示例2: test_path_serializer_path_parameter_validation_handles_references

def test_path_serializer_path_parameter_validation_handles_references():
    paths = {
        '/get/no-parameters/': {
            'parameters': [
                'Id',
            ],
        }
    }
    context = {
        'parameters': {
            'Id': {
                'name': 'id',
                'in': PATH,
                'description': 'id',
                'type': INTEGER,
                'required': True,
            },
        }
    }
    serializer = PathsSerializer(data=paths, context=context)

    assert not serializer.is_valid()
    assert 'non_field_errors' in serializer.errors
    assert '/get/no-parameters/' in serializer.errors['non_field_errors'][0]
    assert_error_message_equal(
        serializer.errors['non_field_errors'][0]['/get/no-parameters/'][0],
        MESSAGES['path']['missing_parameter'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:28,代码来源:test_paths_serializer.py


示例3: test_items_detects_invalid_schema_in_array

def test_items_detects_invalid_schema_in_array():
    schema = {
        'type': ARRAY,
        'items': [
            {
                'type': INTEGER,
                'minLength': 4,  # invalid with type 'integer'
            },
            {
                'type': STRING,
                'minimum': 4,  # invalid with type 'string'
            },
        ]
    }

    serializer = SchemaSerializer(
        data=schema,
    )

    assert not serializer.is_valid()
    assert 'items' in serializer.errors
    assert 'minLength' in serializer.errors['items'][0]
    assert_error_message_equal(
        serializer.errors['items'][0]['minLength'][0],
        serializer.error_messages['invalid_type_for_min_length'],
    )
    assert 'minimum' in serializer.errors['items'][1]
    assert_error_message_equal(
        serializer.errors['items'][1]['minimum'][0],
        serializer.error_messages['invalid_type_for_minimum'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:31,代码来源:test_schema_serializer.py


示例4: test_parameter_format_validation_on_invalid_values

def test_parameter_format_validation_on_invalid_values(format_, value, error_key):
    from django.core.exceptions import ValidationError
    serializer = ParameterSerializer(many=True, data=(
        {
            'name': 'id',
            'in': PATH,
            'description': 'id',
            'type': STRING,
            'required': True,
            'format': format_,
        },
    ))
    assert serializer.is_valid(), serializer.errors
    parameters = serializer.object
    parameter_values = {
        'id': value,
    }

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

    assert 'id' in err.value.messages[0]
    assert 'format' in err.value.messages[0]['id'][0]
    assert_error_message_equal(
        err.value.messages[0]['id'][0]['format'][0],
        MESSAGES['format'][error_key],
    )
开发者ID:dhilton,项目名称:flex,代码行数:27,代码来源:test_format_validation.py


示例5: test_response_validation_with_invalid_operation_on_path

def test_response_validation_with_invalid_operation_on_path():
    """
    Test that response validation detects request paths that are not declared
    in the schema.
    """
    from django.core.exceptions import ValidationError

    schema = SchemaFactory(
        paths={
            '/post': {
                'post': None,
            },
        },
    )

    response = ResponseFactory(url='http://www.example.com/post')

    with pytest.raises(ValidationError) as err:
        validate_response(
            response,
            paths=schema['paths'],
            base_path=schema.get('base_path', ''),
            context=schema,
            inner=True,
        )

    assert 'request' in err.value.messages[0]
    assert_error_message_equal(
        err.value.messages[0]['request'][0],
        MESSAGES['request']['invalid_method'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:31,代码来源:test_request_method_validation.py


示例6: test_parameter_schema_validation_for_invalid_value

def test_parameter_schema_validation_for_invalid_value(value, error_key, message_key):
    from django.core.exceptions import ValidationError
    serializer = ParameterSerializer(many=True, data=(
        {
            'name': 'id',
            'in': BODY,
            'description': 'id',
            'required': True,
            'schema': {'type': STRING, 'format': 'uuid'},
        },
    ))
    assert serializer.is_valid(), serializer.errors
    parameters = serializer.object
    parameter_values = {
        'id': value,
    }

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

    assert 'id' in err.value.messages[0]
    assert error_key in err.value.messages[0]['id'][0]
    assert_error_message_equal(
        err.value.messages[0]['id'][0][error_key][0],
        MESSAGES[error_key][message_key],
    )
开发者ID:dhilton,项目名称:flex,代码行数:26,代码来源:test_schema_validation.py


示例7: test_response_parameter_validation

def test_response_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': {
                'get': {
                    'responses': {200: {'description': 'Success'}},
                },
            },
        },
    )

    response = ResponseFactory(url='http://www.example.com/get', status_code=301)

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

    assert 'status_code' in err.value.messages[0]
    assert_error_message_equal(
        err.value.messages[0]['status_code'][0],
        MESSAGES['response']['invalid_status_code'],
    )
开发者ID:apploitech,项目名称:flex,代码行数:30,代码来源:test_response_status_code_validation.py


示例8: test_max_items_on_values_with_too_many_items

def test_max_items_on_values_with_too_many_items(max_items, value):
    from django.core.exceptions import ValidationError
    serializer = ParameterSerializer(many=True, data=(
        {
            'name': 'id',
            'in': PATH,
            'description':'id',
            'type': ARRAY,
            'required': True,
            'maxItems': max_items,
            'items': {'type': STRING},
        },
    ))
    assert serializer.is_valid(), serializer.errors
    parameters = serializer.object
    parameter_values = {
        'id': value,
    }

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

    assert 'id' in err.value.messages[0]
    assert 'maxItems' in err.value.messages[0]['id'][0]
    assert_error_message_equal(
        err.value.messages[0]['id'][0]['maxItems'][0],
        MESSAGES['max_items']['invalid'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:28,代码来源:test_min_max_items_validation.py


示例9: test_multiple_of_validation_for_invalid_values

def test_multiple_of_validation_for_invalid_values(divisor, value):
    from django.core.exceptions import ValidationError
    serializer = ParameterSerializer(many=True, data=(
        {
            'name': 'id',
            'in': PATH,
            'description':'id',
            'type': NUMBER,
            'required': True,
            'multipleOf': divisor,
        },
    ))
    assert serializer.is_valid(), serializer.errors
    parameters = serializer.object
    parameter_values = {
        'id': value,
    }

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

    assert 'id' in err.value.messages[0]
    assert 'multipleOf' in err.value.messages[0]['id'][0]
    assert_error_message_equal(
        err.value.messages[0]['id'][0]['multipleOf'][0],
        MESSAGES['multiple_of']['invalid'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:27,代码来源:test_multiple_of_validation.py


示例10: test_enum_validation_with_invalid_values

def test_enum_validation_with_invalid_values(enum, value):
    from django.core.exceptions import ValidationError
    serializer = ParameterSerializer(many=True, data=(
        {
            'name': 'id',
            'in': PATH,
            'description':'id',
            'type': [STRING, NUMBER, BOOLEAN],
            'required': True,
            'enum': enum,
        },
    ))
    assert serializer.is_valid(), serializer.errors
    parameters = serializer.object
    parameter_values = {
        'id': value,
    }

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

    assert 'id' in err.value.messages[0]
    assert 'enum' in err.value.messages[0]['id'][0]
    assert_error_message_equal(
        err.value.messages[0]['id'][0]['enum'][0],
        MESSAGES['enum']['invalid'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:27,代码来源:test_enum_validation.py


示例11: test_mistyped_header_default_boolean_to_string

def test_mistyped_header_default_boolean_to_string(type_, default):
    serializer = HeaderSerializer(
        data={'type': type_, 'default': default}
    )

    assert not serializer.is_valid()
    assert 'default' in serializer.errors
    assert_error_message_equal(
        serializer.errors['default'][0],
        serializer.error_messages['default_is_incorrect_type'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:11,代码来源:test_header_serializer.py


示例12: test_in_is_required_if_type_is_api_key

def test_in_is_required_if_type_is_api_key():
    serializer = SecuritySchemeSerializer(
        data={'type': API_KEY, 'name': 'TestName'},
    )

    assert not serializer.is_valid()
    assert 'in' in serializer.errors
    assert_error_message_equal(
        serializer.errors['in'][0],
        serializer.error_messages['in_required']
    )
开发者ID:dhilton,项目名称:flex,代码行数:11,代码来源:test_security_scheme_serializer.py


示例13: test_items_is_required_when_type_is_array

def test_items_is_required_when_type_is_array():
    serializer = HeaderSerializer(
        data={'type': ARRAY},
    )

    assert not serializer.is_valid()
    assert 'items' in serializer.errors
    assert_error_message_equal(
        serializer.errors['items'][0],
        serializer.error_messages['items_required'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:11,代码来源:test_header_serializer.py


示例14: test_token_url_required_if_type_is_oath2

def test_token_url_required_if_type_is_oath2(flow):
    serializer = SecuritySchemeSerializer(
        data={'type': OAUTH_2, 'flow': flow},
    )

    assert not serializer.is_valid()
    assert 'tokenUrl' in serializer.errors
    assert_error_message_equal(
        serializer.errors['tokenUrl'][0],
        serializer.error_messages['token_url_required']
    )
开发者ID:dhilton,项目名称:flex,代码行数:11,代码来源:test_security_scheme_serializer.py


示例15: test_flow_is_required_if_type_oath2

def test_flow_is_required_if_type_oath2():
    serializer = SecuritySchemeSerializer(
        data={'type': OAUTH_2},
    )

    assert not serializer.is_valid()
    assert 'flow' in serializer.errors
    assert_error_message_equal(
        serializer.errors['flow'][0],
        serializer.error_messages['flow_required']
    )
开发者ID:dhilton,项目名称:flex,代码行数:11,代码来源:test_security_scheme_serializer.py


示例16: test_unknown_parameter_reference

def test_unknown_parameter_reference():
    serializer = ParameterSerializer(
        data=['SomeReference'],
        context={},
    )

    assert not serializer.is_valid()
    assert 'non_field_errors' in serializer.errors[0]
    assert_error_message_equal(
        serializer.errors[0]['non_field_errors'][0],
        serializer.error_messages['unknown_reference']
    )
开发者ID:dhilton,项目名称:flex,代码行数:12,代码来源:test_parameter_serializer.py


示例17: test_max_properties_invalid_for_non_object_types

def test_max_properties_invalid_for_non_object_types(type_):
    serializer = BaseSchemaSerializer(
        data={
            'type': type_,
            'maxProperties': 3,
        },
    )
    assert not serializer.is_valid()
    assert 'maxProperties' in serializer.errors
    assert_error_message_equal(
        serializer.errors['maxProperties'][0],
        serializer.error_messages['invalid_type_for_max_properties']
    )
开发者ID:dhilton,项目名称:flex,代码行数:13,代码来源:test_schema_serializer.py


示例18: test_maximum_is_invalid_for_non_numeric_types

def test_maximum_is_invalid_for_non_numeric_types(type_):
    serializer = BaseSchemaSerializer(
        data={
            'type': type_,
            'maximum': 0,
        },
    )
    assert not serializer.is_valid()
    assert 'maximum' in serializer.errors
    assert_error_message_equal(
        serializer.errors['maximum'][0],
        serializer.error_messages['invalid_type_for_maximum'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:13,代码来源:test_schema_serializer.py


示例19: 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(ValidationError) as err:
        validator(letters)

    assert_error_message_equal(
        err.value.messages[0]['enum'][0],
        MESSAGES['enum']['invalid'],
    )
开发者ID:Arable,项目名称:flex,代码行数:13,代码来源:test_enum_validation.py


示例20: test_multiple_of_invalid_with_non_number_types

def test_multiple_of_invalid_with_non_number_types(type_):
    serializer = BaseSchemaSerializer(
        data={
            'type': type_,
            'multipleOf': 10,
        },
    )
    assert not serializer.is_valid()
    assert 'multipleOf' in serializer.errors
    assert_error_message_equal(
        serializer.errors['multipleOf'][0],
        serializer.error_messages['invalid_type_for_multiple_of'],
    )
开发者ID:dhilton,项目名称:flex,代码行数:13,代码来源:test_schema_serializer.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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