[Zope-Checkins] SVN: Zope/branches/2.12/src/ZPublisher/tests/ - added one more Unauthorized test

Yvo Schubbe y.2010 at wcm-solutions.de
Mon Apr 19 05:41:24 EDT 2010


Log message for revision 111074:
  - added one more Unauthorized test

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

-=-
Modified: Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt
===================================================================
--- Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt	2010-04-19 09:29:33 UTC (rev 111073)
+++ Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt	2010-04-19 09:41:23 UTC (rev 111074)
@@ -16,6 +16,7 @@
  
     >>> dummy = app.test_folder_1_._setObject('foo', ExceptionRaiser1())
     >>> dummy = app.test_folder_1_._setObject('bar', ExceptionRaiser2())
+    >>> dummy = app.test_folder_1_._setObject('baz', ExceptionRaiser3())
 
 Handle AttributeError.
 
@@ -115,8 +116,8 @@
     ...
     Redirect: LOCATION
 
-Handle zExceptions.Unauthorized. We take the 'WWW-Authenticate' header as a
-sign that HTTPResponse._unauthorized was called.
+Handle zExceptions.Unauthorized raised by the object. We take the
+'WWW-Authenticate' header as a sign that HTTPResponse._unauthorized was called.
 
     >>> from zExceptions import Unauthorized
     >>> app.test_folder_1_.foo.exception = Unauthorized('ERROR VALUE')
@@ -139,13 +140,34 @@
     ...
     Unauthorized: ERROR VALUE
 
-Handle zExceptions.Forbidden in BaseRequest.traverse. 'traverse' converts it
-into zExceptions.NotFound if we are not in debug mode.
+Handle zExceptions.Unauthorized raised by BaseRequest.traverse. We take the
+'WWW-Authenticate' header as a sign that HTTPResponse._unauthorized was called.
 
     >>> browser.handleErrors = True
     >>> browser.open('http://localhost/test_folder_1_/bar')
     Traceback (most recent call last):
     ...
+    HTTPError: HTTP Error 401: Unauthorized
+    >>> 'Site Error' in browser.contents
+    True
+    >>> 'You are not authorized to access this resource.' in browser.contents
+    True
+    >>> browser.headers['WWW-Authenticate']
+    'basic realm="Zope2"'
+
+    >>> browser.handleErrors = False
+    >>> browser.open('http://localhost/test_folder_1_/bar')
+    Traceback (most recent call last):
+    ...
+    Unauthorized: <strong>You are not authorized to access this resource...
+
+Handle zExceptions.Forbidden raised by 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_/baz')
+    Traceback (most recent call last):
+    ...
     HTTPError: HTTP Error 404: Not Found
     >>> '<p><strong>Resource not found</strong></p>' in browser.contents
     True
@@ -153,7 +175,7 @@
     True
 
     >>> browser.handleErrors = False
-    >>> browser.open('http://localhost/test_folder_1_/bar')
+    >>> browser.open('http://localhost/test_folder_1_/baz')
     Traceback (most recent call last):
     ...
     NotFound:   <h2>Site Error</h2>

Modified: Zope/branches/2.12/src/ZPublisher/tests/test_exception_handling.py
===================================================================
--- Zope/branches/2.12/src/ZPublisher/tests/test_exception_handling.py	2010-04-19 09:29:33 UTC (rev 111073)
+++ Zope/branches/2.12/src/ZPublisher/tests/test_exception_handling.py	2010-04-19 09:41:23 UTC (rev 111074)
@@ -29,8 +29,13 @@
         raise self.exception
 
 
-class ExceptionRaiser2(SimpleItem):
+class ExceptionRaiser2(ExceptionRaiser1):
 
+    __roles__ = ()
+
+
+class ExceptionRaiser3(SimpleItem):
+
     def index_html(self):
         return 'NO DOCSTRING'
 
@@ -39,7 +44,8 @@
     return unittest.TestSuite([
         FunctionalDocFileSuite('exception_handling.txt',
             globs={'ExceptionRaiser1': ExceptionRaiser1,
-                   'ExceptionRaiser2': ExceptionRaiser2,}),
+                   'ExceptionRaiser2': ExceptionRaiser2,
+                   'ExceptionRaiser3': ExceptionRaiser3,}),
         ])
 
 if __name__ == '__main__':



More information about the Zope-Checkins mailing list