Share this Page URL
Help

Chapter 32. Exception Views > Step 3: Testing the Exception View - Pg. 228

Exception Views 09 10 </div> 11 </body> 12 </html> 228 There is nothing interesting going on in the template because it has no dynamic components. In configure.zcml you can register the page now by using the following: 01 <configure 02 xmlns="http://namespaces.zope.org/browser" 03 i18n_domain="exceptionview"> 04 05 <page 06 name="index.html" 07 template="error.pt" 08 for=".interfaces.IPaymentException" 09 class=".browser.PaymentExceptionView" 10 permission="zope.Public" 11 /> 12 13 </configure> To register the new package, you add a file named exceptionview-configure.zcml to pack- age-includes, and that file should contain the following line: 01 <include package="book.exceptionview" /> You can now restart Zope 3. But how can you test whether the view works if there is currently no code that raises the exception? Read on. Step 3: Testing the Exception View The easiest way to raise an exception is to write a simple view that does it. It could look something like this (in browser.py): 01 from book.exceptionview.interfaces import PaymentException 02 03 class RaiseExceptionView(object): 04 """The view that raises the exception""" 05 06 def raisePaymentException(self): 07 raise PaymentException, 'You are required to pay.' Now you can register the class method as a view on a folder: 01 <page 02 name="raiseError.html" 03 for="zope.app.folder.interfaces.IFolder" 04 class=".browser.RaiseExceptionView" 05 attribute="raisePaymentException" 06 permission="zope.View" 07 /> At this point, you need to restart Zope now and enter the URL http://localhost:8080/rai- seError.html in your browser. You should now see the Payment Required exception view, as shown in Figure 32.1.