From c13657dd31c8e0c3217e29b35556f9aa2be37268 Mon Sep 17 00:00:00 2001 From: Daniel Opitz Date: Tue, 21 Nov 2017 20:53:00 +0100 Subject: [PATCH] add failing test for #138 --- .../test_request_body_parameter_validation.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/validation/request/test_request_body_parameter_validation.py b/tests/validation/request/test_request_body_parameter_validation.py index a6fe7c0..03b3502 100644 --- a/tests/validation/request/test_request_body_parameter_validation.py +++ b/tests/validation/request/test_request_body_parameter_validation.py @@ -112,3 +112,53 @@ def test_request_body_parameter_validation_with_invalid_value(user_post_schema): MESSAGES['format']['invalid_email'], err.value.detail, ) + + +def test_request_body_parameter_validation_invalid_without_ref(): + """ + Test validating the request body with a invalid post. + """ + schema = SchemaFactory( + paths={ + '/post/': { + 'post': { + 'consumes': ['application/json'], + 'parameters': [ + { + 'in': 'body', + 'name': 'body', + 'required': True, + 'schema': { + 'type': 'object', + 'required': ['name'], + 'properties': { + 'name': { + 'type': 'string' + } + } + } + } + ], + 'responses': {200: {'description': "Success"}}, + } + } + } + ) + + request = RequestFactory( + url='http://www.example.com/post/', + content_type='application/json', + body=json.dumps({}), + method=POST, + ) + + with pytest.raises(ValidationError) as err: + validate_request( + request=request, + schema=schema, + ) + + assert_message_in_errors( + MESSAGES['required']['required'], + err.value.detail, + )