From b8550877e86244485b72cb64fad829edcaa4d992 Mon Sep 17 00:00:00 2001 From: Steven Seguin Date: Thu, 2 Jun 2016 12:56:44 -0700 Subject: [PATCH] allow debug toolbar path base to be configured --- aiohttp_debugtoolbar/main.py | 24 ++++++++++++------------ tests/test_debug.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/aiohttp_debugtoolbar/main.py b/aiohttp_debugtoolbar/main.py index e5180240..e02ee152 100644 --- a/aiohttp_debugtoolbar/main.py +++ b/aiohttp_debugtoolbar/main.py @@ -40,6 +40,7 @@ 'button_style': '', 'max_request_history': 100, 'max_visible_requests': 10, + 'path_prefix': '/_debugtoolbar', } @@ -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] diff --git a/tests/test_debug.py b/tests/test_debug.py index afa529c8..f1dd5906 100644 --- a/tests/test_debug.py +++ b/tests/test_debug.py @@ -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 @@ -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()