Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdlib wsgiref requires argument for read() #477

Merged
merged 4 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ Contributors (chronological)
* `@dodumosu <https://github.com/dodumosu>`_
* Nate Dellinger `@Nateyo <https://github.com/Nateyo>`_
* Karthikeyan Singaravelan `@tirkarthi <https://github.com/tirkarthi>`_
* Sami Salonen `@suola <https://github.com/suola>`_
2 changes: 1 addition & 1 deletion src/webargs/falconparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _raw_load_json(self, req):
non-json, even if the request body is parseable as json."""
if not is_json_request(req) or req.content_length in (None, 0):
return core.missing
body = req.stream.read()
body = req.stream.read(req.content_length)
if body:
return core.parse_json(body)
else:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_falconparser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import falcon.testing

from webargs.testing import CommonTestCase
from tests.apps.falcon_app import create_app
Expand Down Expand Up @@ -42,3 +43,10 @@ def test_invalid_json(self, testapp):
def test_parsing_headers(self, testapp):
res = testapp.get("/echo_headers", headers={"name": "Fred"})
assert res.json == {"NAME": "Fred"}

# `falcon.testing.TestClient.simulate_request` parses request with `wsgiref`
def test_body_parsing_works_with_simulate(self):
app = self.create_app()
client = falcon.testing.TestClient(app)
res = client.simulate_post("/echo_json", json={"name": "Fred"},)
assert res.json == {"name": "Fred"}