From f3db68c8cee4f48fbc078e1f5a73bb025b425f91 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 5 Aug 2011 16:56:43 +0200 Subject: [PATCH] Added testcase for the debug behavior and explicit encoding --- flask/debughelpers.py | 2 +- tests/flask_tests.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/flask/debughelpers.py b/flask/debughelpers.py index 8f167e7e..e3bdf76f 100644 --- a/flask/debughelpers.py +++ b/flask/debughelpers.py @@ -27,7 +27,7 @@ class DebugFilesKeyError(KeyError, AssertionError): buf.append('\n\nThe browser instead transmitted some file names. ' 'This was submitted: %s' % ', '.join('"%s"' % x for x in form_matches)) - self.msg = ''.join(buf) + self.msg = ''.join(buf).encode('utf-8') def __str__(self): return self.msg diff --git a/tests/flask_tests.py b/tests/flask_tests.py index dbd38e12..3789cd97 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -626,6 +626,26 @@ class BasicFunctionalityTestCase(unittest.TestCase): else: self.fail('Expected exception') + def test_enctype_debug_helper(self): + from flask.debughelpers import DebugFilesKeyError + app = flask.Flask(__name__) + app.debug = True + @app.route('/fail', methods=['POST']) + def index(): + return flask.request.files['foo'].filename + + # with statement is important because we leave an exception on the + # stack otherwise and we want to ensure that this is not the case + # to not negatively affect other tests. + with app.test_client() as c: + try: + c.post('/fail', data={'foo': 'index.txt'}) + except DebugFilesKeyError, e: + assert 'no file contents were transmitted' in str(e) + assert 'This was submitted: "index.txt"' in str(e) + else: + self.fail('Expected exception') + def test_teardown_on_pop(self): buffer = [] app = flask.Flask(__name__)