[Zope-Checkins] SVN: Zope/trunk/src/ZPublisher/tests/ - added some functional tests for exception handling
Yvo Schubbe
y.2010 at wcm-solutions.de
Fri Apr 16 05:57:37 EDT 2010
Log message for revision 110963:
- added some functional tests for exception handling
Changed:
A Zope/trunk/src/ZPublisher/tests/exception_handling.txt
A Zope/trunk/src/ZPublisher/tests/test_exception_handling.py
-=-
Added: Zope/trunk/src/ZPublisher/tests/exception_handling.txt
===================================================================
--- Zope/trunk/src/ZPublisher/tests/exception_handling.txt (rev 0)
+++ Zope/trunk/src/ZPublisher/tests/exception_handling.txt 2010-04-16 09:57:37 UTC (rev 110963)
@@ -0,0 +1,166 @@
+Exception handling
+------------------
+
+These tests capture the current behavior. Maybe some of that behavior should
+be changed. The behavior caused by handleErrors=False shows only up in tests.
+
+
+Create the browser object we'll be using.
+
+ >>> from Testing.testbrowser import Browser
+ >>> browser = Browser()
+ >>> # XXX: browser has no API for disabling redirects
+ >>> browser.mech_browser.set_handle_redirect(False)
+
+Create the objects that are raising exceptions.
+
+ >>> dummy = app.test_folder_1_._setObject('foo', ExceptionRaiser1())
+ >>> dummy = app.test_folder_1_._setObject('bar', ExceptionRaiser2())
+
+Handle AttributeError.
+
+ >>> app.test_folder_1_.foo.exception = AttributeError('ERROR VALUE')
+
+ >>> browser.handleErrors = True
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 500: Internal Server Error
+ >>> 'Error Type: AttributeError' in browser.contents
+ True
+ >>> 'Error Value: ERROR VALUE' in browser.contents
+ True
+
+ >>> browser.handleErrors = False
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ AttributeError: ERROR VALUE
+ >>> browser.contents
+
+Handle ImportError.
+
+ >>> app.test_folder_1_.foo.exception = ImportError('ERROR VALUE')
+
+ >>> browser.handleErrors = True
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 500: Internal Server Error
+ >>> 'Error Type: ImportError' in browser.contents
+ True
+ >>> 'Error Value: ERROR VALUE' in browser.contents
+ True
+
+ >>> browser.handleErrors = False
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ ImportError: ERROR VALUE
+ >>> browser.contents
+
+Handle zope.publisher.interfaces.NotFound.
+
+ >>> from zope.publisher.interfaces import NotFound
+ >>> app.test_folder_1_.foo.exception = NotFound('OBJECT','NAME')
+
+ >>> browser.handleErrors = True
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 404: Not Found
+ >>> 'Error Type: NotFound' in browser.contents
+ True
+ >>> "Error Value: Object: 'OBJECT', name: 'NAME'" in browser.contents
+ True
+
+ >>> browser.handleErrors = False
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ NotFound: Object: 'OBJECT', name: 'NAME'
+ >>> browser.contents
+
+Don't handle SystemExit, even if handleErrors is True.
+
+ >>> app.test_folder_1_.foo.exception = SystemExit('ERROR VALUE')
+
+ >>> browser.handleErrors = True
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ SystemExit: ERROR VALUE
+ >>> browser.contents
+
+ >>> browser.handleErrors = False
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ SystemExit: ERROR VALUE
+ >>> browser.contents
+
+Handle zExceptions.Redirect.
+
+ >>> from zExceptions import Redirect
+ >>> app.test_folder_1_.foo.exception = Redirect('LOCATION')
+
+ >>> browser.handleErrors = True
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 302: Moved Temporarily
+ >>> browser.contents
+ ''
+ >>> browser.headers['Location']
+ 'LOCATION'
+
+ >>> browser.handleErrors = False
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ Redirect: LOCATION
+ >>> browser.contents
+
+Handle zExceptions.Unauthorized.
+
+ >>> from zExceptions import Unauthorized
+ >>> app.test_folder_1_.foo.exception = Unauthorized('ERROR VALUE')
+
+ >>> browser.handleErrors = True
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 401: Unauthorized
+ >>> 'Error Type: Unauthorized' in browser.contents
+ True
+ >>> 'Error Value: ERROR VALUE' in browser.contents
+ True
+
+ >>> browser.handleErrors = False
+ >>> browser.open('http://localhost/test_folder_1_/foo')
+ Traceback (most recent call last):
+ ...
+ Unauthorized: ERROR VALUE
+ >>> browser.contents
+
+Handle zExceptions.Forbidden in BaseRequest.traverse. 'traverse' converts it
+into zExceptions.NotFound if we are not in debug mode.
+
+ >>> browser.handleErrors = True
+ >>> browser.open('http://localhost/test_folder_1_/bar')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 404: Not Found
+ >>> '<p><strong>Resource not found</strong></p>' in browser.contents
+ True
+ >>> '<p><b>Resource:</b> index_html</p>' in browser.contents
+ True
+
+ >>> browser.handleErrors = False
+ >>> browser.open('http://localhost/test_folder_1_/bar')
+ Traceback (most recent call last):
+ ...
+ NotFound: <h2>Site Error</h2>
+ ...<p><strong>Resource not found</strong></p>...
+ ...<p><b>Resource:</b> index_html</p>...
+ >>> browser.contents
Property changes on: Zope/trunk/src/ZPublisher/tests/exception_handling.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Added: Zope/trunk/src/ZPublisher/tests/test_exception_handling.py
===================================================================
--- Zope/trunk/src/ZPublisher/tests/test_exception_handling.py (rev 0)
+++ Zope/trunk/src/ZPublisher/tests/test_exception_handling.py 2010-04-16 09:57:37 UTC (rev 110963)
@@ -0,0 +1,46 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Functional tests for exception handling.
+
+$Id$
+"""
+
+import unittest
+from Testing.ZopeTestCase import FunctionalDocFileSuite
+
+from OFS.SimpleItem import SimpleItem
+
+
+class ExceptionRaiser1(SimpleItem):
+
+ def index_html(self):
+ """DOCSTRING
+ """
+ raise self.exception
+
+
+class ExceptionRaiser2(SimpleItem):
+
+ def index_html(self):
+ return 'NO DOCSTRING'
+
+
+def test_suite():
+ return unittest.TestSuite([
+ FunctionalDocFileSuite('exception_handling.txt',
+ globs={'ExceptionRaiser1': ExceptionRaiser1,
+ 'ExceptionRaiser2': ExceptionRaiser2,}),
+ ])
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: Zope/trunk/src/ZPublisher/tests/test_exception_handling.py
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
More information about the Zope-Checkins
mailing list