summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Bicking <ian@ianbicking.org>2005-08-22 19:40:42 +0000
committerIan Bicking <ian@ianbicking.org>2005-08-22 19:40:42 +0000
commit80850e575b77d241f3da8a94bafa7a3a10c827d2 (patch)
tree6672e057cbd1b97cc7984ffc9016f05eb0b4d0c6
parent1d5489838fedbbb32048c551242b050bbc679338 (diff)
downloadpaste-git-80850e575b77d241f3da8a94bafa7a3a10c827d2.tar.gz
Got exception tests working; error_catcher filter now paste-deploy-ified
-rw-r--r--paste/exceptions/errormiddleware.py23
-rw-r--r--paste/fixture.py18
-rw-r--r--tests/test_exceptions/__init__.py (renamed from tests/exceptions/__init__.py)0
-rw-r--r--tests/test_exceptions/test_error_middleware.py (renamed from tests/exceptions/test_error_middleware.py)26
-rw-r--r--tests/test_exceptions/test_formatter.py (renamed from tests/exceptions/test_formatter.py)0
-rw-r--r--tests/test_exceptions/test_reporter.py (renamed from tests/exceptions/test_reporter.py)0
6 files changed, 28 insertions, 39 deletions
diff --git a/paste/exceptions/errormiddleware.py b/paste/exceptions/errormiddleware.py
index 0f4541c..ad960fc 100644
--- a/paste/exceptions/errormiddleware.py
+++ b/paste/exceptions/errormiddleware.py
@@ -26,20 +26,10 @@ class ErrorMiddleware(object):
error_caching_wsgi_app = ErrorMiddleware(wsgi_app)
- These configuration keys are used:
-
- ``debug``:
- show the errors in the browser
- ``error_email``:
- if present, send errors to this email address
- ``error_log``:
- if present, write errors to this file
- ``show_exceptions_in_error_log``:
- if true (the default) then write errors to wsgi.errors
-
- By setting 'paste.throw_errors' to a true value, this middleware is
- disabled. This can be useful in a testing environment where you don't
- want errors to be caught and transformed.
+ By setting 'paste.throw_errors' in the request environment to a
+ true value, this middleware is disabled. This can be useful in a
+ testing environment where you don't want errors to be caught and
+ transformed.
"""
def __init__(self, application, global_conf,
@@ -136,7 +126,7 @@ class ErrorMiddleware(object):
error_email=self.error_email,
error_log=self.error_log,
show_exceptions_in_wsgi_errors=self.show_exceptions_in_wsgi_errors,
- error_email_from=self.error_email_from,
+ error_email_from=self.from_address,
smtp_server=self.smtp_server,
error_subject_prefix=self.error_subject_prefix,
error_message=self.error_message)
@@ -187,10 +177,11 @@ def handle_exception(exc_info, error_stream, html=True,
debug_mode=False,
error_email=None,
error_log=None,
- show_exceptions_in_wsgi_errors=False
+ show_exceptions_in_wsgi_errors=False,
error_email_from='errors@localhost',
smtp_server='localhost',
error_subject_prefix='',
+ error_message=None,
):
"""
You can also use exception handling outside of a web context,
diff --git a/paste/fixture.py b/paste/fixture.py
index 9016c18..0e722b5 100644
--- a/paste/fixture.py
+++ b/paste/fixture.py
@@ -500,24 +500,6 @@ def setup_module(module=None):
module = sys._getframe().f_back.f_globals['__name__']
if isinstance(module, (str, unicode)):
module = sys.modules[module]
- try:
- CONFIG.current_config()
- except AttributeError:
- # No config setup yet
- start_dir = os.path.abspath(os.path.dirname(module.__file__))
- while 1:
- if not start_dir or start_dir == os.sep:
- break
- if os.path.exists(os.path.join(start_dir, 'server.conf')):
- server_conf_path = os.path.join(start_dir, 'server.conf')
- conf = pyconfig.setup_config(
- server_conf_path, add_config={'testing': True})
- app = TestApp(server.make_app(CONFIG.current_conf()),
- CONFIG.current_conf())
- module.app = app
- module.CONFIG = CONFIG
- break
- start_dir = os.path.dirname(start_dir)
if hasattr(module, 'reset_state'):
module.reset_state()
diff --git a/tests/exceptions/__init__.py b/tests/test_exceptions/__init__.py
index 792d600..792d600 100644
--- a/tests/exceptions/__init__.py
+++ b/tests/test_exceptions/__init__.py
diff --git a/tests/exceptions/test_error_middleware.py b/tests/test_exceptions/test_error_middleware.py
index 956aa26..c7f6370 100644
--- a/tests/exceptions/test_error_middleware.py
+++ b/tests/test_exceptions/test_error_middleware.py
@@ -1,14 +1,30 @@
-from fixture import *
-from paste.errormiddleware import ErrorMiddleware
+from paste.fixture import *
+from paste.exceptions.errormiddleware import ErrorMiddleware
from paste import lint
def do_request(app, expect_status=500):
app = lint.middleware(app)
app = ErrorMiddleware(app, {}, debug=True)
+ app = clear_middleware(app)
testapp = TestApp(app)
- res = TestApp.get('', status=expect_status)
+ res = testapp.get('', status=expect_status,
+ expect_errors=True)
return res
+def clear_middleware(app):
+ """
+ The fixture sets paste.throw_errors, which suppresses exactly what
+ we want to test in this case.
+ """
+ def clear_throw_errors(environ, start_response):
+ def replacement(status, headers, exc_info=None):
+ return start_response(status, headers)
+ if 'paste.throw_errors' in environ:
+ del environ['paste.throw_errors']
+ return app(environ, replacement)
+ return clear_throw_errors
+
+
############################################################
## Applications that raise exceptions
############################################################
@@ -53,13 +69,13 @@ def test_start_res():
print res
assert 'ValueError: hi' in res
assert 'test_error_middleware.py' in res
- assert 'line 17 in <tt>start_response_app</tt>' in res
+ assert 'line 38 in <tt>start_response_app</tt>' in res
def test_after_start():
res = do_request(after_start_response_app, 200)
print res
assert 'ValueError: error2' in res
- assert 'line 21' in res
+ assert 'line 42' in res
def test_iter_app():
res = do_request(iter_app, 200)
diff --git a/tests/exceptions/test_formatter.py b/tests/test_exceptions/test_formatter.py
index 53b0d10..53b0d10 100644
--- a/tests/exceptions/test_formatter.py
+++ b/tests/test_exceptions/test_formatter.py
diff --git a/tests/exceptions/test_reporter.py b/tests/test_exceptions/test_reporter.py
index da6c470..da6c470 100644
--- a/tests/exceptions/test_reporter.py
+++ b/tests/test_exceptions/test_reporter.py