Added a testcase for the improved module support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 665fa2a · Browse files · 9 files·+45 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+45 added−2 removed
- tests:+43 added−0 removed
- other:+2 added−2 removed
Provenance
- Commit
d67a36c- Tree
61f0257- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
665fa2a
9 files changed+45 added−2 removed
modified:flask/module.py+2 added-2 removed
10 unmodified lines11 12 from flask.helpers import _PackageBoundObject13 14 15-def _register_module(module):15+def _register_module(module, static_path):16 """Internal helper function that returns a function for recording17 that registers the `send_static_file` function for the module on18 the application of necessary. It also registers the module on19 the application.78 unmodified lines98 name = import_name.rsplit('.', 1)[1]99 _PackageBoundObject.__init__(self, import_name)100 self.name = name101 self.url_prefix = url_prefix102- self._register_events = [_register_module(self)]102+ self._register_events = [_register_module(self, static_path)]103 104 def route(self, rule, **options):105 """Like :meth:`Flask.route` but for a module. The endpoint for the106 :func:`url_for` function is prefixed with the name of the module.81 unmodified linesadded:tests/moduleapp/apps/admin/static/test.txt+1 added
1+Admin Fileadded:tests/moduleapp/apps/admin/templates/index.html+1 added
1Hello from the Adminadded:tests/moduleapp/apps/admin/__init__.py+9 added
1+from flask import Module, render_template2+3+4+admin = Module(__name__, url_prefix='/admin')5+6+7+@admin.route('/')8+def index():9+ return render_template('admin/index.html')added:tests/moduleapp/apps/frontend/templates/index.html+1 added
1Hello from the Frontendadded:tests/moduleapp/apps/frontend/__init__.py+9 added
1+from flask import Module, render_template2+3+4+frontend = Module(__name__)5+6+7+@frontend.route('/')8+def index():9+ return render_template('frontend/index.html')added:tests/moduleapp/apps/__init__.py
added:tests/moduleapp/__init__.py+7 added
1+from flask import Flask2+3+app = Flask(__name__)4+from moduleapp.apps.admin import admin5+from moduleapp.apps.frontend import frontend6+app.register_module(admin)7+app.register_module(frontend)modified:tests/flask_tests.py+15 added
628 unmodified lines629 rv = c.get('/error')630 assert rv.status_code == 500631 assert 'internal server error' == rv.data632 633+ def test_templates_and_static(self):634+ from moduleapp import app635+ c = app.test_client()636 637+ rv = c.get('/')638+ assert rv.data == 'Hello from the Frontend'639+ rv = c.get('/admin/')640+ assert rv.data == 'Hello from the Admin'641+ rv = c.get('/admin/static/test.txt')642+ assert rv.data.strip() == 'Admin File'643+644+ with app.test_request_context():645+ assert flask.url_for('admin.static', filename='test.txt') \646+ == '/admin/static/test.txt'647+648+649 class SendfileTestCase(unittest.TestCase):650 651 def test_send_file_regular(self):652 app = flask.Flask(__name__)260 unmodified lines