Browse Source

Fix error in send_file helper (#2003)

* Fix error in send_file (mimetype_filename is not defined)

* fix formatting error message in send_file
reviewable/pr2004/r1
Roman 8 years ago committed by David Lord
parent
commit
92ce20eeac
  1. 4
      flask/helpers.py
  2. 6
      tests/test_helpers.py

4
flask/helpers.py

@ -518,8 +518,8 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
if mimetype is None: if mimetype is None:
if attachment_filename is not None: if attachment_filename is not None:
raise ValueError( raise ValueError(
'Unable to infer MIME-type from filename {!r}, please ' 'Unable to infer MIME-type from filename {0!r}, please '
'pass one explicitly.'.format(mimetype_filename) 'pass one explicitly.'.format(attachment_filename)
) )
raise ValueError( raise ValueError(
'Unable to infer MIME-type because no filename is available. ' 'Unable to infer MIME-type because no filename is available. '

6
tests/test_helpers.py

@ -398,10 +398,14 @@ class TestSendfile(object):
with app.test_request_context(): with app.test_request_context():
with pytest.raises(ValueError) as excinfo: with pytest.raises(ValueError) as excinfo:
flask.send_file(StringIO("LOL")) flask.send_file(StringIO("LOL"))
assert 'Unable to infer MIME-type' in str(excinfo) assert 'Unable to infer MIME-type' in str(excinfo)
assert 'no filename is available' in str(excinfo) assert 'no filename is available' in str(excinfo)
with app.test_request_context():
with pytest.raises(ValueError) as excinfo:
flask.send_file(StringIO("LOL"), attachment_filename='filename')
assert "Unable to infer MIME-type from filename 'filename'" in str(excinfo)
def test_send_file_object(self): def test_send_file_object(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)

Loading…
Cancel
Save