Merge pull request #430 from jamesls/issue140
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix issue 140
authored by Ron DuPlain · committed by Ron DuPlain · parents c1a2e3c, 075b6b1 · Browse files · 3 files·+47 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
3 files+47 added−1 removed
- other:+47 added−1 removed
Provenance
- Commit
f7bb2b5- Tree
2d2859b- Author
Ron DuPlain <ron.duplain@gmail.com>- Committer
Ron DuPlain <ron.duplain@gmail.com>- Parent 1
c1a2e3c- Parent 2
075b6b1
3 files changed+47 added−1 removed
modified:flask/testsuite/basic.py+29 added
657 unmodified lines658 self.assert_equal(rv.status_code, 404)659 self.assert_equal(rv.data, 'W00t')660 self.assert_equal(rv.mimetype, 'text/html')661 662+ def test_make_response_with_response_instance(self):663+ app = flask.Flask(__name__)664+ with app.test_request_context():665+ rv = flask.make_response(666+ flask.jsonify({'msg': 'W00t'}), 400)667+ self.assertEqual(rv.status_code, 400)668+ self.assertEqual(rv.data,669+ '{\n "msg": "W00t"\n}')670+ self.assertEqual(rv.mimetype, 'application/json')671+672+ rv = flask.make_response(673+ flask.Response(''), 400)674+ self.assertEqual(rv.status_code, 400)675+ self.assertEqual(rv.data, '')676+ self.assertEqual(rv.mimetype, 'text/html')677+678+ rv = flask.make_response(679+ flask.Response('', headers={'Content-Type': 'text/html'}),680+ 400, None, 'application/json')681+ self.assertEqual(rv.status_code, 400)682+ self.assertEqual(rv.headers['Content-Type'], 'application/json')683+684+ rv = flask.make_response(685+ flask.Response('', mimetype='application/json'),686+ 400, {'Content-Type': 'text/html'})687+ self.assertEqual(rv.status_code, 400)688+ self.assertEqual(rv.headers['Content-Type'], 'text/html')689+690+691 def test_url_generation(self):692 app = flask.Flask(__name__)693 @app.route('/hello/<name>', methods=['POST'])694 def hello():455 unmodified linesmodified:flask/app.py+15 added-1 removed
1359 unmodified lines1360 return rv1361 if isinstance(rv, basestring):1362 return self.response_class(rv)1363 if isinstance(rv, tuple):1364+ if len(rv) > 0 and isinstance(rv[0], self.response_class):1365+ original = rv[0]1366+ new_response = self.response_class('', *rv[1:])1367+ if len(rv) < 3:1368+ # The args for the response class are1369+ # response=None, status=None, headers=None,1370+ # mimetype=None, content_type=None, ...1371+ # so if there's at least 3 elements the rv1372+ # tuple contains header information so the1373+ # headers from rv[0] "win."1374+ new_response.headers = original.headers1375+ new_response.response = original.response1376+ return new_response1377+ else:1364- return self.response_class(*rv)1378+ return self.response_class(*rv)1379 return self.response_class.force_type(rv, request.environ)1380 1381 def create_url_adapter(self, request):1382 """Creates a URL adapter for the given request. The URL adapter176 unmodified linesmodified:CHANGES+3 added
43 unmodified lines44 file is provided.45 - The :meth:`flask.render_template` method now accepts a either an iterable of46 template names or a single template name. Previously, it only accepted a47 single template name. On an iterable, the first template found is rendered.48+- View functions can now return a tuple with the first instance being an49+ instance of :class:`flask.Response`. This allows for returning50+ ``jsonify(error="error msg"), 400`` from a view function.51 52 53 Version 0.8.154 -------------295 unmodified lines