Skip to content
Browse files

Merge

--HG--
branch : 0.10
  • Loading branch information...
2 parents 4feaebc + 5c5fb42 commit 4db9180c4774ec930e696e81da00c7445edef58c @bbangert bbangert committed Jul 20, 2009
Showing with 35 additions and 2 deletions.
  1. +2 −0 CHANGELOG
  2. +5 −1 pylons/controllers/core.py
  3. +13 −0 tests/test_units/__init__.py
  4. +15 −1 tests/test_units/test_controller.py
View
2 CHANGELOG
@@ -6,6 +6,8 @@ Pylons Changelog
tests. Patches supplied by Michael van Tellingen, fixes #571.
0.9.7.1 (**branch**)
+* Retain the original controller exception when thrown under
+ environ['pylons.controller.exception'] for use in the error controller.
* Fixed bug with unit tests running the app load twice during testing.
Fixes #620.
* Updated project templates to use actual config instance, rather than the
View
6 pylons/controllers/core.py
@@ -84,6 +84,7 @@ def _inspect_call(self, func):
log_debug = self._pylons_log_debug
c = self._py_object.c
+ environ = self._py_object.request.environ
args = None
if argspec[2]:
@@ -112,6 +113,9 @@ def _inspect_call(self, func):
httpe.wsgi_response.code, exc_info=True)
result = httpe
+ # Store the exception in the environ
+ environ['pylons.controller.exception'] = httpe
+
# 304 Not Modified's shouldn't have a content-type set
if result.wsgi_response.status_int == 304:
result.wsgi_response.headers.pop('Content-Type', None)
@@ -124,7 +128,7 @@ def _inspect_call(self, func):
warnings.warn("Raising a paste.httpexceptions.HTTPException is "
"deprecated, use webob.exc.HTTPException instead",
DeprecationWarning, 2)
- result = httpe.response(pylons.request.environ)
+ result = httpe.response(environ)
result.headers.pop('Content-Type')
result._exception = True
View
13 tests/test_units/__init__.py
@@ -14,6 +14,19 @@
except:
pass
+
+class TestMiddleware(object):
+ def __init__(self, app):
+ self.app = app
+
+ def __call__(self, environ, start_response):
+ if 'paste.testing_variables' not in environ:
+ environ['paste.testing_variables'] = {}
+ testenv = environ['paste.testing_variables']
+ testenv['environ'] = environ
+ return self.app(environ, start_response)
+
+
class TestWSGIController(TestCase):
def setUp(self):
c = ContextObj()
View
16 tests/test_units/test_controller.py
@@ -7,7 +7,7 @@
from pylons.controllers import WSGIController
from pylons.controllers.util import redirect_to
-from __init__ import TestWSGIController, SetupCacheGlobal, ControllerWrap
+from __init__ import TestWSGIController, SetupCacheGlobal, ControllerWrap, TestMiddleware
class BasicWSGIController(WSGIController):
def __before__(self):
@@ -35,6 +35,10 @@ def use_redirect(self):
exc = status_map[301]
raise exc('/elsewhere').exception
+ def use_customnotfound(self):
+ exc = status_map[404]
+ raise exc('Custom not found').exception
+
def header_check(self):
pylons.response.headers['Content-Type'] = 'text/plain'
return "Hello all!"
@@ -79,6 +83,7 @@ def __init__(self, *args, **kargs):
self.baseenviron = {}
app = ControllerWrap(BasicWSGIController)
app = self.sap = SetupCacheGlobal(app, self.baseenviron)
+ app = TestMiddleware(app)
app = RegistryManager(app)
self.app = TestApp(app)
@@ -100,6 +105,15 @@ def test_404(self):
resp = self.app.get('/', status=404)
assert resp.status == 404
+ def test_404exception(self):
+ self.environ['paste.config']['global_conf']['debug'] = False
+ self.environ['pylons.routes_dict']['action'] = 'use_customnotfound'
+ resp = self.app.get('/', status=404)
+ assert 'pylons.controller.exception' in resp.environ
+ exc = resp.environ['pylons.controller.exception']
+ assert exc.message == 'Custom not found'
+ assert resp.status == 404
+
def test_private_func(self):
self.baseenviron['pylons.routes_dict']['action'] = '_private'
resp = self.app.get('/', status=404)

0 comments on commit 4db9180

Please sign in to comment.
Something went wrong with that request. Please try again.