Browse Source

Merge branch '0.10-maintenance'

pull/977/head
Armin Ronacher 11 years ago
parent
commit
9298d89aed
  1. 2
      CHANGES
  2. 2
      flask/helpers.py
  3. 18
      flask/testsuite/helpers.py

2
CHANGES

@ -33,6 +33,8 @@ Version 0.10.2
the test client when absolute URLs were requested. the test client when absolute URLs were requested.
- Made `@before_first_request` into a decorator as intended. - Made `@before_first_request` into a decorator as intended.
- Fixed an etags bug when sending a file streams with a name. - Fixed an etags bug when sending a file streams with a name.
- Fixed `send_from_directory` not expanding to the application root path
correctly.
Version 0.10.1 Version 0.10.1
-------------- --------------

2
flask/helpers.py

@ -615,6 +615,8 @@ def send_from_directory(directory, filename, **options):
forwarded to :func:`send_file`. forwarded to :func:`send_file`.
""" """
filename = safe_join(directory, filename) filename = safe_join(directory, filename)
if not os.path.isabs(filename):
filename = os.path.join(current_app.root_path, filename)
if not os.path.isfile(filename): if not os.path.isfile(filename):
raise NotFound() raise NotFound()
options.setdefault('conditional', True) options.setdefault('conditional', True)

18
flask/testsuite/helpers.py

@ -304,8 +304,11 @@ class SendfileTestCase(FlaskTestCase):
# etags # etags
self.assert_equal(len(captured), 1) self.assert_equal(len(captured), 1)
with catch_warnings() as captured: with catch_warnings() as captured:
class PyStringIO(StringIO): class PyStringIO(object):
pass def __init__(self, *args, **kwargs):
self._io = StringIO(*args, **kwargs)
def __getattr__(self, name):
return getattr(self._io, name)
f = PyStringIO('Test') f = PyStringIO('Test')
f.name = 'test.txt' f.name = 'test.txt'
rv = flask.send_file(f) rv = flask.send_file(f)
@ -407,6 +410,17 @@ class SendfileTestCase(FlaskTestCase):
self.assert_equal(cc.max_age, 10) self.assert_equal(cc.max_age, 10)
rv.close() rv.close()
def test_send_from_directory(self):
app = flask.Flask(__name__)
app.testing = True
app.root_path = os.path.join(os.path.dirname(__file__),
'test_apps', 'subdomaintestmodule')
with app.test_request_context():
rv = flask.send_from_directory('static', 'hello.txt')
rv.direct_passthrough = False
self.assert_equal(rv.get_data().strip(), b'Hello Subdomain')
rv.close()
class LoggingTestCase(FlaskTestCase): class LoggingTestCase(FlaskTestCase):

Loading…
Cancel
Save