Added a migrated moduleapp as blueprint app

This commit is contained in:
Armin Ronacher 2011-06-17 03:39:49 +02:00
parent e17e74d3a7
commit 37fab78887
9 changed files with 65 additions and 3 deletions

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_blueprint(admin)
app.register_blueprint(frontend)

View File

View File

@ -0,0 +1,13 @@
from flask import Blueprint, render_template
admin = Blueprint(__name__, url_prefix='/admin')
@admin.route('/')
def index():
return render_template('admin/index.html')
@admin.route('/index2')
def index2():
return render_template('./admin/index.html')

View File

@ -0,0 +1 @@
/* nested file */

View File

@ -0,0 +1 @@
Admin File

View File

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

View File

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

View File

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

View File

@ -433,7 +433,7 @@ class BasicFunctionalityTestCase(unittest.TestCase):
def test_teardown_request_handler_debug_mode(self): def test_teardown_request_handler_debug_mode(self):
called = [] called = []
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.debug = True app.testing = True
@app.teardown_request @app.teardown_request
def teardown_request(exc): def teardown_request(exc):
called.append(True) called.append(True)
@ -819,7 +819,7 @@ class JSONTestCase(unittest.TestCase):
def test_json_body_encoding(self): def test_json_body_encoding(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.debug = True app.testing = True
@app.route('/') @app.route('/')
def index(): def index():
return flask.request.json return flask.request.json
@ -1139,7 +1139,7 @@ class ModuleTestCase(unittest.TestCase):
def test_templates_and_static(self): def test_templates_and_static(self):
app = moduleapp app = moduleapp
app.debug = True app.testing = True
c = app.test_client() c = app.test_client()
rv = c.get('/') rv = c.get('/')
@ -1293,6 +1293,36 @@ class BlueprintTestCase(unittest.TestCase):
self.assertEqual(c.get('/1/bar').data, u'23') self.assertEqual(c.get('/1/bar').data, u'23')
self.assertEqual(c.get('/2/bar').data, u'19') self.assertEqual(c.get('/2/bar').data, u'19')
def test_templates_and_static(self):
from blueprintapp 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/index2')
assert rv.data == 'Hello from the Admin'
rv = c.get('/admin/static/test.txt')
assert rv.data.strip() == 'Admin File'
rv = c.get('/admin/static/css/test.css')
assert rv.data.strip() == '/* nested file */'
with app.test_request_context():
assert flask.url_for('admin.static', filename='test.txt') \
== '/admin/static/test.txt'
with app.test_request_context():
try:
flask.render_template('missing.html')
except TemplateNotFound, e:
assert e.name == 'missing.html'
else:
assert 0, 'expected exception'
with flask.Flask(__name__).test_request_context():
assert flask.render_template('nested/nested.txt') == 'I\'m nested'
class SendfileTestCase(unittest.TestCase): class SendfileTestCase(unittest.TestCase):