[Checkins] SVN: Sandbox/janwijbrand/zope.errorview/trunk/ add functional tests for HTTP based views

Jan-Wijbrand Kolman janwijbrand at gmail.com
Wed Jan 19 05:56:46 EST 2011


Log message for revision 119693:
  add functional tests for HTTP based views

Changed:
  U   Sandbox/janwijbrand/zope.errorview/trunk/buildout.cfg
  U   Sandbox/janwijbrand/zope.errorview/trunk/setup.py
  U   Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.py
  U   Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.zcml
  U   Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/tests/test_exceptionview.py

-=-
Modified: Sandbox/janwijbrand/zope.errorview/trunk/buildout.cfg
===================================================================
--- Sandbox/janwijbrand/zope.errorview/trunk/buildout.cfg	2011-01-19 10:24:30 UTC (rev 119692)
+++ Sandbox/janwijbrand/zope.errorview/trunk/buildout.cfg	2011-01-19 10:56:45 UTC (rev 119693)
@@ -9,6 +9,7 @@
 [test]
 recipe = zc.recipe.testrunner
 eggs = zope.errorview [test]
+defaults = ['--auto-color']
 
 [coverage-test]
 recipe = zc.recipe.testrunner

Modified: Sandbox/janwijbrand/zope.errorview/trunk/setup.py
===================================================================
--- Sandbox/janwijbrand/zope.errorview/trunk/setup.py	2011-01-19 10:24:30 UTC (rev 119692)
+++ Sandbox/janwijbrand/zope.errorview/trunk/setup.py	2011-01-19 10:56:45 UTC (rev 119693)
@@ -51,7 +51,8 @@
       package_dir={'': 'src'},
       namespace_packages=['zope'],
       extras_require={
-          'test':[],
+          'test':[
+          'zope.testing'],
           },
       install_requires=[
           'setuptools',

Modified: Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.py
===================================================================
--- Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.py	2011-01-19 10:24:30 UTC (rev 119692)
+++ Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.py	2011-01-19 10:56:45 UTC (rev 119693)
@@ -79,4 +79,3 @@
         self.request.response.setStatus(405)
         self.request.response.setHeader('Allow', ', '.join(allow))
         return ''
-

Modified: Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.zcml
===================================================================
--- Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.zcml	2011-01-19 10:24:30 UTC (rev 119692)
+++ Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/http.zcml	2011-01-19 10:56:45 UTC (rev 119693)
@@ -6,35 +6,36 @@
   <include package="zope.publisher" file="meta.zcml" />
 
   <view
-    class=".http.ExceptionView"
+    factory=".http.ExceptionView"
     for="zope.interface.common.interfaces.IException"
+    type="zope.publisher.interfaces.http.IHTTPRequest"
     name="index.html"
     permission="zope.Public"
   />
 
-<!--  <view-->
-<!--    factory=".unauthorized.Unauthorized"-->
-<!--    for="zope.security.interfaces.IUnauthorized"-->
-<!--    type="zope.publisher.interfaces.http.IHTTPRequest"-->
-<!--    name="index.html"-->
-<!--    permission="zope.Public"-->
-<!--  />-->
+  <view
+    factory=".http.UnauthorizedView"
+    for="zope.security.interfaces.IUnauthorized"
+    type="zope.publisher.interfaces.http.IHTTPRequest"
+    name="index.html"
+    permission="zope.Public"
+  />
 
-<!--  <view-->
-<!--    factory=".notfound.NotFound"-->
-<!--    for="zope.publisher.interfaces.ITraversalException"-->
-<!--    type="zope.publisher.interfaces.http.IHTTPRequest"-->
-<!--    name="index.html"-->
-<!--    permission="zope.Public"-->
-<!--  />-->
+  <view
+    factory=".http.TraversalExceptionView"
+    for="zope.publisher.interfaces.ITraversalException"
+    type="zope.publisher.interfaces.http.IHTTPRequest"
+    name="index.html"
+    permission="zope.Public"
+  />
 
-<!--  <view-->
-<!--    factory="zope.errorview.methodnotallowed.MethodNotAllowedView"-->
-<!--    for="zope.publisher.interfaces.http.IMethodNotAllowed"-->
-<!--    type="zope.publisher.interfaces.http.IHTTPRequest"-->
-<!--    name="index.html"-->
-<!--    permission="zope.Public"-->
-<!--  />-->
+  <view
+    factory=".http.MethodNotAllowedView"
+    for="zope.publisher.interfaces.http.IMethodNotAllowed"
+    type="zope.publisher.interfaces.http.IHTTPRequest"
+    name="index.html"
+    permission="zope.Public"
+  />
 
   <browser:defaultView
     for="zope.interface.common.interfaces.IException"

Modified: Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/tests/test_exceptionview.py
===================================================================
--- Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/tests/test_exceptionview.py	2011-01-19 10:24:30 UTC (rev 119692)
+++ Sandbox/janwijbrand/zope.errorview/trunk/src/zope/errorview/tests/test_exceptionview.py	2011-01-19 10:56:45 UTC (rev 119693)
@@ -16,24 +16,28 @@
 $Id: test_unauthorized.py 119650 2011-01-18 14:58:35Z janwijbrand $
 """
 from unittest import TestCase
-from zope.errorview.unauthorized import Unauthorized
+from zope.browser.interfaces import ISystemErrorView
+from zope.component import getMultiAdapter, provideAdapter
+from zope.component.testlayer import ZCMLFileLayer
+from zope.errorview import http
+from zope.interface import Interface
 from zope.publisher.browser import TestRequest
-from zope.publisher.interfaces.http import IHTTPException
-from zope.publisher.interfaces.http import MethodNotAllowed
+from zope.publisher.defaultview import getDefaultViewName
+from zope.publisher.http import HTTPRequest
+from zope.publisher.interfaces.http import IHTTPException, IHTTPRequest
+from zope.publisher.interfaces.http import MethodNotAllowed, IMethodNotAllowed
+from zope.publisher.interfaces import TraversalException, IDefaultViewName
 from zope.security.interfaces import Unauthorized
-from zope.publisher.interfaces import TraversalException
-from zope.errorview import http
-from zope.browser.interfaces import ISystemErrorView
+import zope.errorview
 
 class TestErrorViews(TestCase):
 
     def setUp(self):
-        self.request = TestRequest()
+        self.request = HTTPRequest('', {})
 
     def test_exceptionviewbase(self):
         view = http.ExceptionViewBase(Exception(), self.request)
         self.failUnless(IHTTPException.providedBy(view))
-        # Render the view.
         self.assertEquals(str(view), '')
         self.assertEquals(view(), '')
         self.assertEqual(self.request.response.getStatus(), 500)
@@ -43,7 +47,6 @@
         self.failUnless(IHTTPException.providedBy(view))
         self.failUnless(ISystemErrorView.providedBy(view))
         self.assertTrue(view.isSystemError())
-        # Render the view.
         self.assertEquals(str(view), '')
         self.assertEquals(view(), '')
         self.assertEqual(self.request.response.getStatus(), 500)
@@ -51,7 +54,6 @@
     def test_traversalexceptionview(self):
         view = http.TraversalExceptionView(TraversalException(), self.request)
         self.failUnless(IHTTPException.providedBy(view))
-        # Render the view.
         self.assertEquals(str(view), '')
         self.assertEquals(view(), '')
         self.assertEqual(self.request.response.getStatus(), 404)
@@ -60,7 +62,6 @@
     def test_unauthorizedexceptionview(self):
         view = http.UnauthorizedView(Unauthorized(), self.request)
         self.failUnless(IHTTPException.providedBy(view))
-        # Render the view.
         self.assertEquals(str(view), '')
         self.assertEquals(view(), '')
         self.assertEqual(self.request.response.getStatus(), 401)
@@ -72,7 +73,6 @@
         error = MethodNotAllowed(object(), self.request)
         view = http.MethodNotAllowedView(error, self.request)
         self.failUnless(IHTTPException.providedBy(view))
-        # Render the view.
         self.assertEquals(str(view), '')
         self.assertEquals(view(), '')
         self.assertEquals(self.request.response.getStatus(), 405)
@@ -87,8 +87,75 @@
         self.assertEquals(
             self.request.response.getHeader('Allow'), 'GET, POST, PUT, DELETE')
 
+http_layer = ZCMLFileLayer(zope.errorview, zcml_file='http.zcml')
 
+class TestErrorViewsFunctional(TestCase):
 
+    layer = http_layer
 
+    def setUp(self):
+        self.request = HTTPRequest('', {})
 
+    def test_defaultname(self):
+        self.assertEquals(
+            getDefaultViewName(Exception(), self.request), 'index.html')
+        self.assertEquals(
+            getDefaultViewName(
+                TraversalException(), self.request), 'index.html')
+        self.assertEquals(
+            getDefaultViewName(
+                Unauthorized(), self.request), 'index.html')
+        error = MethodNotAllowed(object(), self.request)
+        self.assertEquals(
+            getDefaultViewName(error, self.request), 'index.html')
 
+    def test_exceptionview(self):
+        view = getMultiAdapter((Exception(), self.request), name='index.html')
+        self.failUnless(IHTTPException.providedBy(view))
+        self.assertEquals(str(view), '')
+        self.assertEquals(view(), '')
+        self.assertEqual(self.request.response.getStatus(), 500)
+
+    def test_traversalexceptionview(self):
+        view = getMultiAdapter(
+            (TraversalException(), self.request), name='index.html')
+        self.failUnless(IHTTPException.providedBy(view))
+        self.assertEquals(str(view), '')
+        self.assertEquals(view(), '')
+        self.assertEqual(self.request.response.getStatus(), 404)
+        # XXX test the MKCOL verb here too.
+
+    def test_unauthorizedexceptionview(self):
+        view = getMultiAdapter(
+            (Unauthorized(), self.request), name='index.html')
+        self.failUnless(IHTTPException.providedBy(view))
+        self.assertEquals(str(view), '')
+        self.assertEquals(view(), '')
+        self.assertEqual(self.request.response.getStatus(), 401)
+        self.failUnless(
+            self.request.response.getHeader(
+                'WWW-Authenticate', '', True).startswith('basic'))
+
+    def test_methodnotallowedview(self):
+        error = MethodNotAllowed(object(), self.request)
+        view = getMultiAdapter((error, self.request), name='index.html')
+        self.failUnless(IHTTPException.providedBy(view))
+        self.assertEquals(str(view), '')
+        self.assertEquals(view(), '')
+        self.assertEquals(self.request.response.getStatus(), 405)
+        self.assertEquals(self.request.response.getHeader('Allow'), '')
+
+        class MyMethodNotAllowedView(http.MethodNotAllowedView):
+            def allowed(self):
+                return 'GET', 'POST', 'PUT', 'DELETE'
+
+        provideAdapter(
+            MyMethodNotAllowedView,
+            (IMethodNotAllowed, IHTTPRequest), Interface, 'index.html')
+
+        view = getMultiAdapter((error, self.request), name='index.html')()
+        self.assertEquals(self.request.response.getStatus(), 405)
+        self.assertEquals(
+            self.request.response.getHeader('Allow'), 'GET, POST, PUT, DELETE')
+
+



More information about the checkins mailing list