forked from orbit-oss/flask
Merge branch '1.0-maintenance'
This commit is contained in:
commit
161c43649d
9 changed files with 95 additions and 39 deletions
|
|
@ -356,6 +356,28 @@ def test_flaskgroup(runner):
|
|||
assert result.output == 'flaskgroup\n'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('set_debug_flag', (True, False))
|
||||
def test_flaskgroup_debug(runner, set_debug_flag):
|
||||
"""Test FlaskGroup debug flag behavior."""
|
||||
|
||||
def create_app(info):
|
||||
app = Flask("flaskgroup")
|
||||
app.debug = True
|
||||
return app
|
||||
|
||||
@click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)
|
||||
def cli(**params):
|
||||
pass
|
||||
|
||||
@cli.command()
|
||||
def test():
|
||||
click.echo(str(current_app.debug))
|
||||
|
||||
result = runner.invoke(cli, ['test'])
|
||||
assert result.exit_code == 0
|
||||
assert result.output == '%s\n' % str(not set_debug_flag)
|
||||
|
||||
|
||||
def test_print_exceptions(runner):
|
||||
"""Print the stacktrace if the CLI."""
|
||||
|
||||
|
|
@ -537,12 +559,12 @@ def test_run_cert_import(monkeypatch):
|
|||
run_command.make_context('run', ['--cert', 'not_here'])
|
||||
|
||||
# not an SSLContext
|
||||
if sys.version_info >= (2, 7):
|
||||
if sys.version_info >= (2, 7, 9):
|
||||
with pytest.raises(click.BadParameter):
|
||||
run_command.make_context('run', ['--cert', 'flask'])
|
||||
|
||||
# SSLContext
|
||||
if sys.version_info < (2, 7):
|
||||
if sys.version_info < (2, 7, 9):
|
||||
ssl_context = object()
|
||||
else:
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
||||
|
|
|
|||
|
|
@ -638,15 +638,22 @@ class TestSendfile(object):
|
|||
assert options['filename'] == 'index.txt'
|
||||
rv.close()
|
||||
|
||||
def test_attachment_with_utf8_filename(self, app, req_ctx):
|
||||
rv = flask.send_file('static/index.html', 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"
|
||||
))
|
||||
@pytest.mark.usefixtures('req_ctx')
|
||||
@pytest.mark.parametrize(('filename', 'ascii', 'utf8'), (
|
||||
('index.html', 'index.html', False),
|
||||
(u'Ñandú/pingüino.txt', '"Nandu/pinguino.txt"',
|
||||
'%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt'),
|
||||
(u'Vögel.txt', 'Vogel.txt', 'V%C3%B6gel.txt'),
|
||||
))
|
||||
def test_attachment_filename_encoding(self, filename, ascii, utf8):
|
||||
rv = flask.send_file('static/index.html', as_attachment=True, attachment_filename=filename)
|
||||
rv.close()
|
||||
content_disposition = rv.headers['Content-Disposition']
|
||||
assert 'filename=%s' % ascii in content_disposition
|
||||
if utf8:
|
||||
assert "filename*=UTF-8''" + utf8 in content_disposition
|
||||
else:
|
||||
assert "filename*=UTF-8''" not in content_disposition
|
||||
|
||||
def test_static_file(self, app, req_ctx):
|
||||
# default cache timeout is 12 hours
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue