Browse Source

Added a testcase for the improved module support

pull/112/head
Armin Ronacher 15 years ago
parent
commit
d67a36cbdb
  1. 4
      flask/module.py
  2. 15
      tests/flask_tests.py
  3. 7
      tests/moduleapp/__init__.py
  4. 0
      tests/moduleapp/apps/__init__.py
  5. 9
      tests/moduleapp/apps/admin/__init__.py
  6. 1
      tests/moduleapp/apps/admin/static/test.txt
  7. 1
      tests/moduleapp/apps/admin/templates/index.html
  8. 9
      tests/moduleapp/apps/frontend/__init__.py
  9. 1
      tests/moduleapp/apps/frontend/templates/index.html

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

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

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)

0
tests/moduleapp/apps/__init__.py

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')

1
tests/moduleapp/apps/admin/static/test.txt

@ -0,0 +1 @@
Admin File

1
tests/moduleapp/apps/admin/templates/index.html

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

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')

1
tests/moduleapp/apps/frontend/templates/index.html

@ -0,0 +1 @@
Hello from the Frontend
Loading…
Cancel
Save