Skip to content

Commit

Permalink
Merge pull request #42 from sseg/path_prefix
Browse files Browse the repository at this point in the history
allow debug toolbar path base to be configured
  • Loading branch information
asvetlov committed Jun 3, 2016
2 parents ce53c61 + b855087 commit 511efff
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
24 changes: 12 additions & 12 deletions aiohttp_debugtoolbar/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'button_style': '',
'max_request_history': 100,
'max_visible_requests': 10,
'path_prefix': '/_debugtoolbar',
}


Expand All @@ -65,34 +66,33 @@ def setup(app, **kw):

exc_handlers = ExceptionDebugView()

app.router.add_static('/_debugtoolbar/static', static_location,
path_prefix = config['path_prefix']
app.router.add_static(path_prefix + '/static', static_location,
name=STATIC_ROUTE_NAME)

app.router.add_route('GET', '/_debugtoolbar/source', exc_handlers.source,
app.router.add_route('GET', path_prefix + '/source', exc_handlers.source,
name='debugtoolbar.source')
app.router.add_route('GET', '/_debugtoolbar/execute', exc_handlers.execute,
app.router.add_route('GET', path_prefix + '/execute', exc_handlers.execute,
name='debugtoolbar.execute')
# app.router.add_route('GET', '/_debugtoolbar/console',
# app.router.add_route('GET', path_prefix + '/console',
# exc_handlers.console,
# name='debugtoolbar.console')
app.router.add_route('GET', '/_debugtoolbar/exception',
app.router.add_route('GET', path_prefix + '/exception',
exc_handlers.exception,
name='debugtoolbar.exception')
# TODO: fix when sql will be ported
# app.router.add_route('GET', '_debugtoolbar/sqlalchemy/sql_select',
# app.router.add_route('GET', path_prefix + '/sqlalchemy/sql_select',
# name='debugtoolbar.sql_select')
# app.router.add_route('GET', '_debugtoolbar/sqlalchemy/sql_explain',
# app.router.add_route('GET', path_prefix + '/sqlalchemy/sql_explain',
# name='debugtoolbar.sql_explain')

app.router.add_route('GET', '/_debugtoolbar/sse', views.sse,
app.router.add_route('GET', path_prefix + '/sse', views.sse,
name='debugtoolbar.sse')

app.router.add_route('GET', '/_debugtoolbar/{request_id}',
app.router.add_route('GET', path_prefix + '/_debugtoolbar/{request_id}',
views.request_view, name='debugtoolbar.request')
app.router.add_route('GET', '/_debugtoolbar', views.request_view,
app.router.add_route('GET', path_prefix, views.request_view,
name='debugtoolbar.main')
app.router.add_route('GET', '/_debugtoolbar', views.request_view,
name='debugtoolbar')

def settings_opt(name):
return app[APP_KEY]['settings'][name]
Expand Down
28 changes: 28 additions & 0 deletions tests/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
:copyright: (c) 2011 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD license.
"""
import aiohttp
import aiohttp_jinja2
import asyncio
import pytest
import re
import sys
import unittest
Expand Down Expand Up @@ -151,3 +155,27 @@ def test_debug_help(self):

assert 'Help on list object' in x
assert '__delitem__' in x


@pytest.mark.run_loop
def test_alternate_debug_path(loop, create_server):
@asyncio.coroutine
def handler(request):
return aiohttp_jinja2.render_template(
'tplt.html', request,
{'head': 'HEAD', 'text': 'text'})
path_prefix = '/arbitrary_path'
app, url = yield from create_server(path_prefix=path_prefix)
app.router.add_route('GET', '/', handler)

conn = aiohttp.TCPConnector(loop=loop, force_close=True)
cookie = {"pdtb_active": "pDebugPerformancePanel"}
resp = yield from aiohttp.request('GET', url + '/', cookies=cookie,
loop=loop, connector=conn)

url = url + path_prefix
resp = yield from aiohttp.request('GET', url, loop=loop, connector=conn)
yield from resp.text()
assert 200 == resp.status
resp.close()
conn.close()

0 comments on commit 511efff

Please sign in to comment.