forked from orbit-oss/flask
Merge pull request #1206 from methane/deprecate-request.json
Deprecate request.json property
This commit is contained in:
commit
46918d3ceb
2 changed files with 43 additions and 1 deletions
|
|
@ -103,7 +103,9 @@ class Request(RequestBase):
|
||||||
|
|
||||||
The :meth:`get_json` method should be used instead.
|
The :meth:`get_json` method should be used instead.
|
||||||
"""
|
"""
|
||||||
# XXX: deprecate property
|
from warnings import warn
|
||||||
|
warn(DeprecationWarning('json is deprecated. '
|
||||||
|
'Use get_json() instead.'), stacklevel=2)
|
||||||
return self.get_json()
|
return self.get_json()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,43 @@
|
||||||
:copyright: (c) 2014 by Armin Ronacher.
|
:copyright: (c) 2014 by Armin Ronacher.
|
||||||
:license: BSD, see LICENSE for more details.
|
:license: BSD, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
import flask
|
||||||
|
|
||||||
|
|
||||||
|
class TestRequestDeprecation(object):
|
||||||
|
|
||||||
|
def test_request_json(self, catch_deprecation_warnings):
|
||||||
|
"""Request.json is deprecated"""
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
app.testing = True
|
||||||
|
|
||||||
|
@app.route('/', methods=['POST'])
|
||||||
|
def index():
|
||||||
|
assert flask.request.json == {'spam': 42}
|
||||||
|
print(flask.request.json)
|
||||||
|
return 'OK'
|
||||||
|
|
||||||
|
with catch_deprecation_warnings() as captured:
|
||||||
|
c = app.test_client()
|
||||||
|
c.post('/', data='{"spam": 42}', content_type='application/json')
|
||||||
|
|
||||||
|
assert len(captured) == 1
|
||||||
|
|
||||||
|
def test_request_module(self, catch_deprecation_warnings):
|
||||||
|
"""Request.module is deprecated"""
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
app.testing = True
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
assert flask.request.module is None
|
||||||
|
return 'OK'
|
||||||
|
|
||||||
|
with catch_deprecation_warnings() as captured:
|
||||||
|
c = app.test_client()
|
||||||
|
c.get('/')
|
||||||
|
|
||||||
|
assert len(captured) == 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue