diff --git a/tests/blueprintapp/__init__.py b/tests/blueprintapp/__init__.py new file mode 100644 index 00000000..fa76807c --- /dev/null +++ b/tests/blueprintapp/__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_blueprint(admin) +app.register_blueprint(frontend) diff --git a/tests/blueprintapp/apps/__init__.py b/tests/blueprintapp/apps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/blueprintapp/apps/admin/__init__.py b/tests/blueprintapp/apps/admin/__init__.py new file mode 100644 index 00000000..fe33e3e9 --- /dev/null +++ b/tests/blueprintapp/apps/admin/__init__.py @@ -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') diff --git a/tests/blueprintapp/apps/admin/static/css/test.css b/tests/blueprintapp/apps/admin/static/css/test.css new file mode 100644 index 00000000..b9f564de --- /dev/null +++ b/tests/blueprintapp/apps/admin/static/css/test.css @@ -0,0 +1 @@ +/* nested file */ diff --git a/tests/blueprintapp/apps/admin/static/test.txt b/tests/blueprintapp/apps/admin/static/test.txt new file mode 100644 index 00000000..f220d22f --- /dev/null +++ b/tests/blueprintapp/apps/admin/static/test.txt @@ -0,0 +1 @@ +Admin File diff --git a/tests/blueprintapp/apps/admin/templates/admin/index.html b/tests/blueprintapp/apps/admin/templates/admin/index.html new file mode 100644 index 00000000..eeec199a --- /dev/null +++ b/tests/blueprintapp/apps/admin/templates/admin/index.html @@ -0,0 +1 @@ +Hello from the Admin diff --git a/tests/blueprintapp/apps/frontend/__init__.py b/tests/blueprintapp/apps/frontend/__init__.py new file mode 100644 index 00000000..e98ff280 --- /dev/null +++ b/tests/blueprintapp/apps/frontend/__init__.py @@ -0,0 +1,8 @@ +from flask import Blueprint, render_template + +frontend = Blueprint(__name__) + + +@frontend.route('/') +def index(): + return render_template('frontend/index.html') diff --git a/tests/blueprintapp/apps/frontend/templates/frontend/index.html b/tests/blueprintapp/apps/frontend/templates/frontend/index.html new file mode 100644 index 00000000..a062d713 --- /dev/null +++ b/tests/blueprintapp/apps/frontend/templates/frontend/index.html @@ -0,0 +1 @@ +Hello from the Frontend diff --git a/tests/flask_tests.py b/tests/flask_tests.py index 75ffa095..9a0905c1 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -433,7 +433,7 @@ class BasicFunctionalityTestCase(unittest.TestCase): def test_teardown_request_handler_debug_mode(self): called = [] app = flask.Flask(__name__) - app.debug = True + app.testing = True @app.teardown_request def teardown_request(exc): called.append(True) @@ -819,7 +819,7 @@ class JSONTestCase(unittest.TestCase): def test_json_body_encoding(self): app = flask.Flask(__name__) - app.debug = True + app.testing = True @app.route('/') def index(): return flask.request.json @@ -1139,7 +1139,7 @@ class ModuleTestCase(unittest.TestCase): def test_templates_and_static(self): app = moduleapp - app.debug = True + app.testing = True c = app.test_client() rv = c.get('/') @@ -1293,6 +1293,36 @@ class BlueprintTestCase(unittest.TestCase): self.assertEqual(c.get('/1/bar').data, u'23') 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):