Skip to content

Commit

Permalink
Merge pull request #11 from paramsingh/debugtoolbar
Browse files Browse the repository at this point in the history
BU-7: Create a method to init DebugToolbar in CustomFlask
  • Loading branch information
paramsingh authored Feb 22, 2018
2 parents 896deaf + 466ea75 commit c4340f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
16 changes: 12 additions & 4 deletions brainzutils/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CustomFlask(Flask):
"""Custom version of Flask with our bells and whistles."""

def __init__(self, import_name, config_file=None, debug=None,
use_flask_uuid=False, use_debug_toolbar=False,
use_flask_uuid=False,
*args, **kwargs):
"""Create an instance of Flask app.
Expand All @@ -20,8 +20,6 @@ def __init__(self, import_name, config_file=None, debug=None,
Should be in a form of Python module.
debug (bool): Override debug value.
use_flask_uuid (bool): Turn on Flask-UUID extension if set to True.
use_debug_toolbar (bool): Turn on Flask-DebugToolbar extension in
debug mode if set to True.
"""
super(CustomFlask, self).__init__(import_name, *args, **kwargs)
if config_file:
Expand All @@ -30,9 +28,19 @@ def __init__(self, import_name, config_file=None, debug=None,
self.debug = debug
if use_flask_uuid:
FlaskUUID(self)
if use_debug_toolbar and self.debug:


def init_debug_toolbar(self):
"""This method initializes the Flask-Debug extension toolbar for the
Flask app.
Note that the Flask-Debug extension requires app.debug be true
and the SECRET_KEY be defined in app.config.
"""
if self.debug:
DebugToolbarExtension(self)


def init_loggers(self,
file_config=None,
email_config=None,
Expand Down
23 changes: 22 additions & 1 deletion brainzutils/flask/test/test_main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
import unittest
from brainzutils import flask

from brainzutils import flask

class FlaskTestCase(unittest.TestCase):

def test_create_app(self):
app = flask.CustomFlask(__name__)
self.assertIsNotNone(app)

def test_debug_toolbar(self):
""" Tests that debug toolbar loads if initialized correctly
"""

# create an app
app = flask.CustomFlask(__name__)
self.assertIsNotNone(app)
app.debug = True
app.config['SECRET_KEY'] = 'this is a totally secret key btw'
app.init_debug_toolbar()

# add a dummy route
@app.route('/')
def index():
return '<html><body>test</body></html>'

client = app.test_client()
response = client.get('/')
self.assertEqual(response.status_code, 200)
self.assertIn('flDebug', str(response.data))

0 comments on commit c4340f3

Please sign in to comment.