Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tschorr authored and pbauer committed May 18, 2018
1 parent 19c9c0b commit 98675dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/Testing/tests/test_testbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ def test_handle_errors_true(self):
self.folder._setObject('stub', ExceptionStub())
browser = Browser()

with self.assertRaises(HTTPError):
# HTTP errors only for WSGI
with self.assertRaises(ValueError):
browser.open('http://localhost/test_folder_1_/stub')
self.assertTrue(browser.headers['status'].startswith('500'))
self.assertIsNone(browser.contents)

with self.assertRaises(HTTPError):
browser.open('http://localhost/nothing-is-here')
Expand Down Expand Up @@ -165,8 +166,10 @@ def test_raise_http_errors_false(self):
browser = Browser()
browser.raiseHttpErrors = False

browser.open('http://localhost/test_folder_1_/stub')
self.assertTrue(browser.headers['status'].startswith('500'))
# HTTP errors only for WSGI
with self.assertRaises(ValueError):
browser.open('http://localhost/test_folder_1_/stub')
self.assertIsNone(browser.contents)

browser.open('http://localhost/nothing-is-here')
self.assertTrue(browser.headers['status'].startswith('404'))
Expand Down
9 changes: 5 additions & 4 deletions src/ZPublisher/httpexceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ def __call__(self, environ, start_response):
except HTTPException as exc:
return exc(environ, start_response)
except Exception as exc:
if self.debug_mode or environ.get('x-wsgiorg.throw_errors', False):
if self.debug_mode:
# In debug mode, let the web server log a real
# traceback
raise
if environ.get('wsgi.errors') is not None:
elif environ.get('wsgi.errors') is not None:
# s. https://www.python.org/dev/peps/pep-0333/#id27
# Imho InternalError is the generic error case
# Imho the catch all InternalError is the generic error case
# that should not be handled by the application but
# rather the WSGI server. This way the error along with
# the traceback ends up in the concfigured logs.
# the traceback ends up in the configured logs.
# 'wsgi.errors' must be defined according to PEP-0333
raise
return self.catch_all_response(exc)(environ, start_response)

Expand Down

0 comments on commit 98675dd

Please sign in to comment.