diff --git a/flask/module.py b/flask/module.py index ee1a342e..d106e69b 100644 --- a/flask/module.py +++ b/flask/module.py @@ -12,7 +12,7 @@ from flask.helpers import _PackageBoundObject -def _register_module(module): +def _register_module(module, static_path): """Internal helper function that returns a function for recording that registers the `send_static_file` function for the module on the application of necessary. It also registers the module on @@ -99,7 +99,7 @@ class Module(_PackageBoundObject): _PackageBoundObject.__init__(self, import_name) self.name = name self.url_prefix = url_prefix - self._register_events = [_register_module(self)] + self._register_events = [_register_module(self, static_path)] def route(self, rule, **options): """Like :meth:`Flask.route` but for a module. The endpoint for the diff --git a/tests/flask_tests.py b/tests/flask_tests.py index 7e2c9246..384e2e91 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -630,6 +630,21 @@ class ModuleTestCase(unittest.TestCase): assert rv.status_code == 500 assert 'internal server error' == rv.data + def test_templates_and_static(self): + from moduleapp import app + c = app.test_client() + + rv = c.get('/') + assert rv.data == 'Hello from the Frontend' + rv = c.get('/admin/') + assert rv.data == 'Hello from the Admin' + rv = c.get('/admin/static/test.txt') + assert rv.data.strip() == 'Admin File' + + with app.test_request_context(): + assert flask.url_for('admin.static', filename='test.txt') \ + == '/admin/static/test.txt' + class SendfileTestCase(unittest.TestCase): diff --git a/tests/moduleapp/__init__.py b/tests/moduleapp/__init__.py new file mode 100644 index 00000000..35e82d4e --- /dev/null +++ b/tests/moduleapp/__init__.py @@ -0,0 +1,7 @@ +from flask import Flask + +app = Flask(__name__) +from moduleapp.apps.admin import admin +from moduleapp.apps.frontend import frontend +app.register_module(admin) +app.register_module(frontend) diff --git a/tests/moduleapp/apps/__init__.py b/tests/moduleapp/apps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/moduleapp/apps/admin/__init__.py b/tests/moduleapp/apps/admin/__init__.py new file mode 100644 index 00000000..98af2b26 --- /dev/null +++ b/tests/moduleapp/apps/admin/__init__.py @@ -0,0 +1,9 @@ +from flask import Module, render_template + + +admin = Module(__name__, url_prefix='/admin') + + +@admin.route('/') +def index(): + return render_template('admin/index.html') diff --git a/tests/moduleapp/apps/admin/static/test.txt b/tests/moduleapp/apps/admin/static/test.txt new file mode 100644 index 00000000..f220d22f --- /dev/null +++ b/tests/moduleapp/apps/admin/static/test.txt @@ -0,0 +1 @@ +Admin File diff --git a/tests/moduleapp/apps/admin/templates/index.html b/tests/moduleapp/apps/admin/templates/index.html new file mode 100644 index 00000000..eeec199a --- /dev/null +++ b/tests/moduleapp/apps/admin/templates/index.html @@ -0,0 +1 @@ +Hello from the Admin diff --git a/tests/moduleapp/apps/frontend/__init__.py b/tests/moduleapp/apps/frontend/__init__.py new file mode 100644 index 00000000..f83581e7 --- /dev/null +++ b/tests/moduleapp/apps/frontend/__init__.py @@ -0,0 +1,9 @@ +from flask import Module, render_template + + +frontend = Module(__name__) + + +@frontend.route('/') +def index(): + return render_template('frontend/index.html') diff --git a/tests/moduleapp/apps/frontend/templates/index.html b/tests/moduleapp/apps/frontend/templates/index.html new file mode 100644 index 00000000..a062d713 --- /dev/null +++ b/tests/moduleapp/apps/frontend/templates/index.html @@ -0,0 +1 @@ +Hello from the Frontend