-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send an event when rendering an exception view.
- Loading branch information
1 parent
d3147c2
commit 5fdfe4c
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from zope.interface import Interface, implements, Attribute | ||
|
||
class IHandleExceptionEvent(Interface): | ||
"""Event fired when handling an exception.""" | ||
|
||
request = Attribute('The current request') | ||
|
||
class HandleExceptionEvent(object): | ||
implements(IHandleExceptionEvent) | ||
|
||
def __init__(self, request): | ||
self.request = request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2011 Zope Foundation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# 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. | ||
# | ||
############################################################################## | ||
|
||
from unittest import TestCase | ||
|
||
import zope.component.eventtesting | ||
from zope.publisher.http import HTTPRequest | ||
|
||
from zope.errorview.http import ExceptionViewBase | ||
from zope.errorview.interfaces import IHandleExceptionEvent | ||
|
||
|
||
class TestEvent(TestCase): | ||
def setUp(self): | ||
zope.component.eventtesting.setUp() | ||
self.request = HTTPRequest('', {}) | ||
|
||
def test_event(self): | ||
view = ExceptionViewBase(Exception(), self.request)() | ||
event = zope.component.eventtesting.getEvents()[0] | ||
self.assertEqual(event.request, self.request) | ||
self.assertTrue(IHandleExceptionEvent.providedBy(event)) |