Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a testcase for the improved module support

  • Loading branch information...
commit d67a36cbdb20bfd9cd9931bceb8e6e3c27e9263f 1 parent 665fa2a
@mitsuhiko authored
View
4 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 @@ def __init__(self, import_name, name=None, url_prefix=None,
_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
View
15 tests/flask_tests.py
@@ -630,6 +630,21 @@ def error():
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):
View
7 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)
View
0  tests/moduleapp/apps/__init__.py
No changes.
View
9 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')
View
1  tests/moduleapp/apps/admin/static/test.txt
@@ -0,0 +1 @@
+Admin File
View
1  tests/moduleapp/apps/admin/templates/index.html
@@ -0,0 +1 @@
+Hello from the Admin
View
9 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')
View
1  tests/moduleapp/apps/frontend/templates/index.html
@@ -0,0 +1 @@
+Hello from the Frontend
Please sign in to comment.
Something went wrong with that request. Please try again.