Skip to content
Myr

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

9 files+45 added−2 removed

modified:flask/module.py+2 added-2 removed
10 unmodified lines
1112from flask.helpers import _PackageBoundObject131415def _register_module(module):15def _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 lines
98 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)]103104 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 lines
added:tests/moduleapp/apps/admin/static/test.txt+1 added
1Admin File
added:tests/moduleapp/apps/admin/templates/index.html+1 added
added:tests/moduleapp/apps/admin/__init__.py+9 added
1from flask import Module, render_template234admin = Module(__name__, url_prefix='/admin')567@admin.route('/')8def index():9 return render_template('admin/index.html')
added:tests/moduleapp/apps/frontend/templates/index.html+1 added
added:tests/moduleapp/apps/frontend/__init__.py+9 added
1from flask import Module, render_template234frontend = Module(__name__)567@frontend.route('/')8def index():9 return render_template('frontend/index.html')
added:tests/moduleapp/apps/__init__.py
added:tests/moduleapp/__init__.py+7 added
1from flask import Flask23app = Flask(__name__)4from moduleapp.apps.admin import admin5from moduleapp.apps.frontend import frontend6app.register_module(admin)7app.register_module(frontend)
modified:tests/flask_tests.py+15 added
628 unmodified lines
629 rv = c.get('/error')630 assert rv.status_code == 500631 assert 'internal server error' == rv.data632633 def test_templates_and_static(self):634 from moduleapp import app635 c = app.test_client()636637 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'643644 with app.test_request_context():645 assert flask.url_for('admin.static', filename='test.txt') \646 == '/admin/static/test.txt'647648649class SendfileTestCase(unittest.TestCase):650651 def test_send_file_regular(self):652 app = flask.Flask(__name__)
260 unmodified lines