From 61097c47a35ad8883c77fc49b93c1314f7819464 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Wed, 15 Oct 2014 02:21:52 +0900 Subject: [PATCH 1/2] Deprecate request.json property --- flask/wrappers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flask/wrappers.py b/flask/wrappers.py index da9d2c78..81c39f18 100644 --- a/flask/wrappers.py +++ b/flask/wrappers.py @@ -103,7 +103,9 @@ class Request(RequestBase): 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() @property From 4d4a639ba46cf72454497bc100b3e811e66af4b2 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Wed, 15 Oct 2014 03:32:04 +0900 Subject: [PATCH 2/2] Add test for deprecated flask.Request properties. --- tests/test_deprecations.py | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/test_deprecations.py b/tests/test_deprecations.py index bbbe10ad..e84080bb 100644 --- a/tests/test_deprecations.py +++ b/tests/test_deprecations.py @@ -8,3 +8,43 @@ :copyright: (c) 2014 by Armin Ronacher. :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