Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
8ac25879
Commit
8ac25879
authored
Apr 19, 2010
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added one more Unauthorized test
parent
06318d6b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
7 deletions
+35
-7
src/ZPublisher/tests/exception_handling.txt
src/ZPublisher/tests/exception_handling.txt
+27
-5
src/ZPublisher/tests/test_exception_handling.py
src/ZPublisher/tests/test_exception_handling.py
+8
-2
No files found.
src/ZPublisher/tests/exception_handling.txt
View file @
8ac25879
...
@@ -16,6 +16,7 @@ Create the objects that are raising exceptions.
...
@@ -16,6 +16,7 @@ Create the objects that are raising exceptions.
>>> dummy = app.test_folder_1_._setObject('foo', ExceptionRaiser1())
>>> dummy = app.test_folder_1_._setObject('foo', ExceptionRaiser1())
>>> dummy = app.test_folder_1_._setObject('bar', ExceptionRaiser2())
>>> dummy = app.test_folder_1_._setObject('bar', ExceptionRaiser2())
>>> dummy = app.test_folder_1_._setObject('baz', ExceptionRaiser3())
Handle AttributeError.
Handle AttributeError.
...
@@ -115,8 +116,8 @@ Handle zExceptions.Redirect.
...
@@ -115,8 +116,8 @@ Handle zExceptions.Redirect.
...
...
Redirect: LOCATION
Redirect: LOCATION
Handle zExceptions.Unauthorized
. We take the 'WWW-Authenticate' header as a
Handle zExceptions.Unauthorized
raised by the object. We take the
sign that HTTPResponse._unauthorized was called.
'WWW-Authenticate' header as a
sign that HTTPResponse._unauthorized was called.
>>> from zExceptions import Unauthorized
>>> from zExceptions import Unauthorized
>>> app.test_folder_1_.foo.exception = Unauthorized('ERROR VALUE')
>>> app.test_folder_1_.foo.exception = Unauthorized('ERROR VALUE')
...
@@ -139,13 +140,34 @@ sign that HTTPResponse._unauthorized was called.
...
@@ -139,13 +140,34 @@ sign that HTTPResponse._unauthorized was called.
...
...
Unauthorized: ERROR VALUE
Unauthorized: ERROR VALUE
Handle zExceptions.
Forbidden in BaseRequest.traverse. 'traverse' converts it
Handle zExceptions.
Unauthorized raised by BaseRequest.traverse. We take the
into zExceptions.NotFound if we are not in debug mode
.
'WWW-Authenticate' header as a sign that HTTPResponse._unauthorized was called
.
>>> browser.handleErrors = True
>>> browser.handleErrors = True
>>> browser.open('http://localhost/test_folder_1_/bar')
>>> browser.open('http://localhost/test_folder_1_/bar')
Traceback (most recent call last):
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
HTTPError: HTTP Error 404: Not Found
>>> '<p><strong>Resource not found</strong></p>' in browser.contents
>>> '<p><strong>Resource not found</strong></p>' in browser.contents
True
True
...
@@ -153,7 +175,7 @@ into zExceptions.NotFound if we are not in debug mode.
...
@@ -153,7 +175,7 @@ into zExceptions.NotFound if we are not in debug mode.
True
True
>>> browser.handleErrors = False
>>> browser.handleErrors = False
>>> browser.open('http://localhost/test_folder_1_/ba
r
')
>>> browser.open('http://localhost/test_folder_1_/ba
z
')
Traceback (most recent call last):
Traceback (most recent call last):
...
...
NotFound: <h2>Site Error</h2>
NotFound: <h2>Site Error</h2>
...
...
src/ZPublisher/tests/test_exception_handling.py
View file @
8ac25879
...
@@ -29,7 +29,12 @@ class ExceptionRaiser1(SimpleItem):
...
@@ -29,7 +29,12 @@ class ExceptionRaiser1(SimpleItem):
raise
self
.
exception
raise
self
.
exception
class
ExceptionRaiser2
(
SimpleItem
):
class
ExceptionRaiser2
(
ExceptionRaiser1
):
__roles__
=
()
class
ExceptionRaiser3
(
SimpleItem
):
def
index_html
(
self
):
def
index_html
(
self
):
return
'NO DOCSTRING'
return
'NO DOCSTRING'
...
@@ -39,7 +44,8 @@ def test_suite():
...
@@ -39,7 +44,8 @@ def test_suite():
return
unittest
.
TestSuite
([
return
unittest
.
TestSuite
([
FunctionalDocFileSuite
(
'exception_handling.txt'
,
FunctionalDocFileSuite
(
'exception_handling.txt'
,
globs
=
{
'ExceptionRaiser1'
:
ExceptionRaiser1
,
globs
=
{
'ExceptionRaiser1'
:
ExceptionRaiser1
,
'ExceptionRaiser2'
:
ExceptionRaiser2
,}),
'ExceptionRaiser2'
:
ExceptionRaiser2
,
'ExceptionRaiser3'
:
ExceptionRaiser3
,}),
])
])
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment