Skip to content

Commit 1ad36da

Browse files
committed
Added test for backwards compatibilty support
1 parent d0589a2 commit 1ad36da

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

flask/module.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ def _register(state):
2323
state.app.modules[module.name] = module
2424
path = module.static_path
2525
# XXX: backwards compatibility. This will go away in 1.0
26-
if path is None and module._backwards_compat_static_path:
27-
path = module.static_path
28-
if path == app.static_path:
26+
if module._backwards_compat_static_path:
27+
if path == state.app.static_path:
2928
return
3029
from warnings import warn
3130
warn(DeprecationWarning('With Flask 0.7 the static folder '
@@ -35,7 +34,7 @@ def _register(state):
3534
'Pass ``static_path=\'static\'`` to the Module '
3635
'constructor if you want to use static folders.\n'
3736
'This backwards compatibility support will go away in '
38-
'Flask 1.0'), stacklevel=3)
37+
'Flask 1.0'), stacklevel=2)
3938
if path is None:
4039
return
4140
path = '/' + os.path.basename(path)

tests/flask_tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,15 @@ def test_safe_access(self):
828828
else:
829829
assert 0, 'expected exception'
830830

831+
def test_static_path_backwards_compat(self):
832+
with catch_warnings() as captured:
833+
from modulecompat import app
834+
rv = app.test_client().get('/test/static/hello.txt')
835+
assert rv.data.strip() == 'Hello World!'
836+
837+
# the warning for missing static_path
838+
assert len(captured) == 1
839+
831840

832841
class SendfileTestCase(unittest.TestCase):
833842

tests/modulecompat/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from flask import Flask
2+
3+
4+
app = Flask(__name__)
5+
from modulecompat.test import mod
6+
app.register_module(mod, url_prefix='/test')

tests/modulecompat/test/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from flask import Module
2+
3+
4+
mod = Module(__name__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World!

0 commit comments

Comments
 (0)