Skip to content
Myr

Merge pull request #1206 from methane/deprecate-request.json

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Deprecate request.json property

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents 7169f44, 4d4a639 · Browse files · 2 files+43 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+43 added−1 removed

  • tests:+40 added−0 removed
  • other:+3 added−1 removed

2 files+43 added−1 removed

modified:flask/wrappers.py+3 added-1 removed
101 unmodified lines
102 parsed JSON data. Otherwise this will be `None`.103104 The :meth:`get_json` method should be used instead.105 """106 # XXX: deprecate property106 from warnings import warn107 warn(DeprecationWarning('json is deprecated. '108 'Use get_json() instead.'), stacklevel=2)109 return self.get_json()110111 @property112 def is_json(self):
89 unmodified lines
modified:tests/test_deprecations.py+40 added
6 unmodified lines
78 :copyright: (c) 2014 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112import pytest1314import flask151617class TestRequestDeprecation(object):1819 def test_request_json(self, catch_deprecation_warnings):20 """Request.json is deprecated"""21 app = flask.Flask(__name__)22 app.testing = True2324 @app.route('/', methods=['POST'])25 def index():26 assert flask.request.json == {'spam': 42}27 print(flask.request.json)28 return 'OK'2930 with catch_deprecation_warnings() as captured:31 c = app.test_client()32 c.post('/', data='{"spam": 42}', content_type='application/json')3334 assert len(captured) == 13536 def test_request_module(self, catch_deprecation_warnings):37 """Request.module is deprecated"""38 app = flask.Flask(__name__)39 app.testing = True4041 @app.route('/')42 def index():43 assert flask.request.module is None44 return 'OK'4546 with catch_deprecation_warnings() as captured:47 c = app.test_client()48 c.get('/')4950 assert len(captured) == 1