Skip to content

Commit c4340f3

Browse files
authored
Merge pull request #11 from paramsingh/debugtoolbar
BU-7: Create a method to init DebugToolbar in CustomFlask
2 parents 896deaf + 466ea75 commit c4340f3

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

brainzutils/flask/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class CustomFlask(Flask):
88
"""Custom version of Flask with our bells and whistles."""
99

1010
def __init__(self, import_name, config_file=None, debug=None,
11-
use_flask_uuid=False, use_debug_toolbar=False,
11+
use_flask_uuid=False,
1212
*args, **kwargs):
1313
"""Create an instance of Flask app.
1414
@@ -20,8 +20,6 @@ def __init__(self, import_name, config_file=None, debug=None,
2020
Should be in a form of Python module.
2121
debug (bool): Override debug value.
2222
use_flask_uuid (bool): Turn on Flask-UUID extension if set to True.
23-
use_debug_toolbar (bool): Turn on Flask-DebugToolbar extension in
24-
debug mode if set to True.
2523
"""
2624
super(CustomFlask, self).__init__(import_name, *args, **kwargs)
2725
if config_file:
@@ -30,9 +28,19 @@ def __init__(self, import_name, config_file=None, debug=None,
3028
self.debug = debug
3129
if use_flask_uuid:
3230
FlaskUUID(self)
33-
if use_debug_toolbar and self.debug:
31+
32+
33+
def init_debug_toolbar(self):
34+
"""This method initializes the Flask-Debug extension toolbar for the
35+
Flask app.
36+
37+
Note that the Flask-Debug extension requires app.debug be true
38+
and the SECRET_KEY be defined in app.config.
39+
"""
40+
if self.debug:
3441
DebugToolbarExtension(self)
3542

43+
3644
def init_loggers(self,
3745
file_config=None,
3846
email_config=None,
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
import unittest
2-
from brainzutils import flask
32

3+
from brainzutils import flask
44

55
class FlaskTestCase(unittest.TestCase):
66

77
def test_create_app(self):
88
app = flask.CustomFlask(__name__)
99
self.assertIsNotNone(app)
10+
11+
def test_debug_toolbar(self):
12+
""" Tests that debug toolbar loads if initialized correctly
13+
"""
14+
15+
# create an app
16+
app = flask.CustomFlask(__name__)
17+
self.assertIsNotNone(app)
18+
app.debug = True
19+
app.config['SECRET_KEY'] = 'this is a totally secret key btw'
20+
app.init_debug_toolbar()
21+
22+
# add a dummy route
23+
@app.route('/')
24+
def index():
25+
return '<html><body>test</body></html>'
26+
27+
client = app.test_client()
28+
response = client.get('/')
29+
self.assertEqual(response.status_code, 200)
30+
self.assertIn('flDebug', str(response.data))

0 commit comments

Comments
 (0)