本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'],
)
示例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'],
)
示例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'],
)
示例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],
)
示例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'],
)
示例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],
)
示例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'],
)
示例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'],
)
示例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'],
)
示例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'],
)
示例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'],
)
示例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']
)
示例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'],
)
示例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']
)
示例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']
)