From 7454c350452de96628b0a99e7a0caf10f4eda0ad Mon Sep 17 00:00:00 2001 From: Fadi Moukayed Date: Tue, 23 Oct 2018 20:58:43 +0200 Subject: [PATCH] test_aiohttpparser: Add a test to ensure correct behaviour on empty JSON bodies --- tests/test_aiohttpparser.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_aiohttpparser.py b/tests/test_aiohttpparser.py index 6e65afa3..93bcc782 100644 --- a/tests/test_aiohttpparser.py +++ b/tests/test_aiohttpparser.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- import asyncio +import webtest import webtest_aiohttp import pytest +from io import BytesIO from webargs.core import MARSHMALLOW_VERSION_INFO from webargs.testing import CommonTestCase from tests.apps.aiohttp_app import create_app @@ -63,3 +65,10 @@ def test_schema_as_kwargs_view(self, testapp): assert testapp.get("/echo_use_schema_as_kwargs?name=Chandler").json == { "name": "Chandler" } + + # https://github.com/sloria/webargs/pull/297 + def test_empty_json_body(self, testapp): + environ = {"CONTENT_TYPE": "application/json", "wsgi.input": BytesIO(b"")} + req = webtest.TestRequest.blank("/echo", environ) + resp = testapp.do_request(req) + assert resp.json == {"name": "World"}