Added a testcase for the improved module support

This commit is contained in:
Armin Ronacher 2010-07-04 14:12:29 +02:00
parent 665fa2a32b
commit d67a36cbdb
9 changed files with 45 additions and 2 deletions

View file

@ -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

View file

@ -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):

View file

@ -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 file

View file

@ -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 file

@ -0,0 +1 @@
Admin File

View file

@ -0,0 +1 @@
Hello from the Admin

View file

@ -0,0 +1,9 @@
from flask import Module, render_template
frontend = Module(__name__)
@frontend.route('/')
def index():
return render_template('frontend/index.html')

View file

@ -0,0 +1 @@
Hello from the Frontend