Skip to content

Commit

Permalink
Send an event when rendering an exception view.
Browse files Browse the repository at this point in the history
  • Loading branch information
janjaapdriessen committed Jan 19, 2011
1 parent d3147c2 commit 5fdfe4c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/zope/errorview/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from zope.browser.interfaces import ISystemErrorView
from zope.interface import implements
from zope.publisher.interfaces.http import IHTTPException
from zope.event import notify
from zope.errorview.interfaces import HandleExceptionEvent


class SystemErrorViewMixin(object):
Expand All @@ -40,6 +42,7 @@ def render(self):
return u''

def __call__(self):
notify(HandleExceptionEvent(self.request))
self.update()
return self.render()

Expand Down
12 changes: 12 additions & 0 deletions src/zope/errorview/interfaces.py
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
33 changes: 33 additions & 0 deletions src/zope/errorview/tests/test_event.py
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))

0 comments on commit 5fdfe4c

Please sign in to comment.