Do not error for unknown files if send_file sends an actual file

This commit is contained in:
Armin Ronacher 2016-09-10 03:33:53 +03:00
parent c54c538c11
commit a30951ec28
2 changed files with 3 additions and 4 deletions

View file

@ -513,7 +513,8 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
if mimetype is None:
if attachment_filename is not None:
mimetype = mimetypes.guess_type(attachment_filename)[0]
mimetype = mimetypes.guess_type(attachment_filename)[0] \
or 'application/octet-stream'
if mimetype is None:
if attachment_filename is not None:

View file

@ -402,9 +402,7 @@ class TestSendfile(object):
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)
flask.send_file(StringIO("LOL"), attachment_filename='filename')
def test_send_file_object(self):
app = flask.Flask(__name__)