style cleanup

break out header parts in test
test for no filename* parameter for ascii header
This commit is contained in:
David Lord 2017-04-07 18:02:31 -07:00
parent d50a5db5ed
commit c1973016ea
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 28 additions and 16 deletions

View file

@ -540,10 +540,11 @@ class TestSendfile(object):
value, options = \
parse_options_header(rv.headers['Content-Disposition'])
assert value == 'attachment'
assert options['filename'] == 'index.html'
assert 'filename*' not in options
rv.close()
with app.test_request_context():
assert options['filename'] == 'index.html'
rv = flask.send_file('static/index.html', as_attachment=True)
value, options = parse_options_header(rv.headers['Content-Disposition'])
assert value == 'attachment'
@ -562,15 +563,21 @@ class TestSendfile(object):
def test_attachment_with_utf8_filename(self):
app = flask.Flask(__name__)
with app.test_request_context():
with open(os.path.join(app.root_path, 'static/index.html')) as f:
rv = flask.send_file(f, as_attachment=True,
attachment_filename=u'Ñandúpingüino.txt')
content_disposition = set(rv.headers['Content-Disposition'].split(';'))
assert content_disposition == set(['attachment',
' filename="Nandu/pinguino.txt"',
" filename*=UTF-8''%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt"])
rv.close()
rv = flask.send_file(
'static/index.html', as_attachment=True,
attachment_filename=u'Ñandúpingüino.txt'
)
value, options = parse_options_header(
rv.headers['Content-Disposition']
)
rv.close()
assert value == 'attachment'
assert sorted(options.keys()) == ('filename', 'filename*')
assert options['filename'] == 'Nandu/pinguino.txt'
assert options['filename*'] == 'UTF-8''%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt'
def test_static_file(self):
app = flask.Flask(__name__)