Log message for revision 110964:
  - backported functional tests for exception handling from trunk

Changed:
  A   Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt
  A   Zope/branches/2.12/src/ZPublisher/tests/test_exception_handling.py

-=-
Copied: Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt (from 
rev 110963, Zope/trunk/src/ZPublisher/tests/exception_handling.txt)
===================================================================
--- Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt              
                (rev 0)
+++ Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt      
2010-04-16 10:16:47 UTC (rev 110964)
@@ -0,0 +1,158 @@
+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 Products.Five.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
+
+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
+
+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'
+
+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.handleErrors = False
+    >>> browser.open('http://localhost/test_folder_1_/foo')
+    Traceback (most recent call last):
+    ...
+    SystemExit: ERROR VALUE
+
+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
+
+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
+
+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>...

Copied: Zope/branches/2.12/src/ZPublisher/tests/test_exception_handling.py 
(from rev 110963, Zope/trunk/src/ZPublisher/tests/test_exception_handling.py)
===================================================================
--- Zope/branches/2.12/src/ZPublisher/tests/test_exception_handling.py          
                (rev 0)
+++ Zope/branches/2.12/src/ZPublisher/tests/test_exception_handling.py  
2010-04-16 10:16:47 UTC (rev 110964)
@@ -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')

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to