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
63c7bb8e
Commit
63c7bb8e
authored
Apr 16, 2010
by
Browse files
Options
Browse Files
Download
Plain Diff
- backported functional tests for exception handling from trunk
parents
65a68f7b
2bf6e0dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
204 additions
and
0 deletions
+204
-0
src/ZPublisher/tests/exception_handling.txt
src/ZPublisher/tests/exception_handling.txt
+158
-0
src/ZPublisher/tests/test_exception_handling.py
src/ZPublisher/tests/test_exception_handling.py
+46
-0
No files found.
src/ZPublisher/tests/exception_handling.txt
0 → 100644
View file @
63c7bb8e
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>...
src/ZPublisher/tests/test_exception_handling.py
0 → 100644
View file @
63c7bb8e
##############################################################################
#
# 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'
)
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