[Checkins] SVN: zope.app.wsgi/branches/janjaapdriessen-webtest/src/zope/app/wsgi/test Tests for handle_errors for Browser and http caller.

Jan-Jaap Driessen jdriessen at thehealthagency.com
Tue Mar 15 18:37:19 EDT 2011


Log message for revision 120959:
  Tests for handle_errors for Browser and http caller.

Changed:
  U   zope.app.wsgi/branches/janjaapdriessen-webtest/src/zope/app/wsgi/testing.py
  U   zope.app.wsgi/branches/janjaapdriessen-webtest/src/zope/app/wsgi/testlayer.txt

-=-
Modified: zope.app.wsgi/branches/janjaapdriessen-webtest/src/zope/app/wsgi/testing.py
===================================================================
--- zope.app.wsgi/branches/janjaapdriessen-webtest/src/zope/app/wsgi/testing.py	2011-03-15 22:36:47 UTC (rev 120958)
+++ zope.app.wsgi/branches/janjaapdriessen-webtest/src/zope/app/wsgi/testing.py	2011-03-15 22:37:19 UTC (rev 120959)
@@ -54,6 +54,9 @@
               </body>
             </html>'''
 
+class ErrorRaisingView(FileView):
+    def __call__(self):
+        return 1/0
 
 class SillyMiddleWare(object):
     def __init__(self, application):

Modified: zope.app.wsgi/branches/janjaapdriessen-webtest/src/zope/app/wsgi/testlayer.txt
===================================================================
--- zope.app.wsgi/branches/janjaapdriessen-webtest/src/zope/app/wsgi/testlayer.txt	2011-03-15 22:36:47 UTC (rev 120958)
+++ zope.app.wsgi/branches/janjaapdriessen-webtest/src/zope/app/wsgi/testlayer.txt	2011-03-15 22:37:19 UTC (rev 120959)
@@ -10,6 +10,12 @@
     ...     IndexView,
     ...     checker.NamesChecker(['browserDefault', '__call__']),
     ...     )
+    >>> from zope.app.wsgi.testing import ErrorRaisingView
+    >>> component.provideAdapter(ErrorRaisingView, name='error.html')
+    >>> checker.defineChecker(
+    ...     ErrorRaisingView,
+    ...     checker.NamesChecker(['browserDefault', '__call__']),
+    ...     )
 
 The `silly middleware` has injected information into the page:
 
@@ -25,6 +31,33 @@
       </body>
     </html>
 
+The default behavior of the browser is to handle errors::
+
+    >>> browser.open('http://localhost/error.html')
+    Traceback (most recent call last):
+    ...
+    HTTPError: HTTP Error 500: Internal Server Error
+
+One can set error handling behavior::
+
+    >>> browser.handleErrors = False
+    >>> browser.open('http://localhost/error.html')
+    Traceback (most recent call last):
+    ...
+    ZeroDivisionError: integer division or modulo by zero
+
+The http caller is more low level than the Browser.
+It exposes the same error handling parameter::
+
+    >>> from zope.app.wsgi.testlayer import http
+    >>> response = http('GET /error.html HTTP/1.1')
+    >>> response.getStatus() == 500
+    True
+    >>> http('GET /error.html HTTP/1.1', handle_errors=False)
+    Traceback (most recent call last):
+    ...
+    ZeroDivisionError: integer division or modulo by zero
+
 Clean up:
 
     >>> import zope.publisher.interfaces.browser
@@ -36,3 +69,11 @@
     ...     zope.publisher.interfaces.browser.IBrowserPublisher,
     ...     'index.html',
     ...     )
+    >>> checker.undefineChecker(ErrorRaisingView)
+    >>> component.provideAdapter(
+    ...     None,
+    ...     (interface.Interface,
+    ...     zope.publisher.interfaces.browser.IBrowserRequest),
+    ...     zope.publisher.interfaces.browser.IBrowserPublisher,
+    ...     'error.html',
+    ...     )



More information about the checkins mailing list