Merge pull request #76 from cleverdevil/next

Adds new debug middleware.
This commit is contained in:
cleverdevil
2012-03-15 13:55:26 -07:00
4 changed files with 196 additions and 12 deletions

View File

@@ -1,7 +1,5 @@
from paste.errordocument import make_errordocument
from paste.translogger import TransLogger
from weberror.errormiddleware import ErrorMiddleware
from weberror.evalexception import EvalException
from core import (
abort, override_template, Pecan, load_app, redirect, render,
@@ -10,8 +8,8 @@ from core import (
from recursive import RecursiveMiddleware
from decorators import expose
from hooks import RequestViewerHook
from templating import error_formatters
from static import SharedDataMiddleware
from debug import DebugMiddleware
from configuration import set_config
from configuration import _runtime_conf as conf
@@ -35,27 +33,28 @@ def make_app(root, static_root=None, debug=False, errorcfg={},
# Instantiate the WSGI app by passing **kw onward
app = Pecan(root, **kw)
# Optionally wrap the app in another WSGI app
if wrap_app:
app = wrap_app(app)
# Included for internal redirect support
app = RecursiveMiddleware(app)
# Support for interactive debugging (and error reporting)
# When in debug mode, load our exception dumping middleware
if debug:
app = EvalException(
app,
templating_formatters=error_formatters,
**errorcfg
)
else:
app = ErrorMiddleware(app, **errorcfg)
app = DebugMiddleware(app)
# Configuration for serving custom error messages
if hasattr(conf.app, 'errors'):
app = make_errordocument(app, conf, **dict(conf.app.errors))
# Support for serving static files (for development convenience)
if static_root:
app = SharedDataMiddleware(app, static_root)
# Support for simple Apache-style logs
if isinstance(logging, dict) or logging == True:
app = TransLogger(app, **(isinstance(logging, dict) and logging or {}))
return app

160
pecan/debug.py Normal file

File diff suppressed because one or more lines are too long

View File

@@ -743,7 +743,7 @@ class TestRedirect(unittest.TestCase):
def testing(self):
return 'it worked!'
return TestApp(make_app(RootController(), debug=True))
return TestApp(make_app(RootController(), debug=False))
def test_index(self):
r = self.app_.get('/')

25
pecan/tests/test_debug.py Normal file
View File

@@ -0,0 +1,25 @@
from unittest import TestCase
from webtest import TestApp
from pecan.debug import DebugMiddleware
class TestDebugMiddleware(TestCase):
def setUp(self):
def conditional_error_app(environ, start_response):
if environ['PATH_INFO'] == '/error':
assert 1 == 2
start_response("200 OK", [('Content-type', 'text/plain')])
return ['requested page returned']
self.app = TestApp(DebugMiddleware(conditional_error_app))
def test_middleware_passes_through_when_no_exception_raised(self):
r = self.app.get('/')
assert r.status_int == 200
assert r.body == 'requested page returned'
def test_middleware_gives_stack_trace_on_errors(self):
r = self.app.get('/error', expect_errors=True)
assert r.status_int == 400
assert 'AssertionError' in r.body