[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Publisher/Browser/tests - testDirectives.py:1.8

Jim Fulton jim@zope.com
Thu, 20 Jun 2002 10:37:31 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv26058/lib/python/Zope/App/Publisher/Browser/tests

Modified Files:
	testDirectives.py 
Log Message:
Made it possible for named views with pages to provide their own
publishTraverse and browserDefault implementations. The publishTraverse should
delegate to super(Klass, self) if it's traversal fails.



=== Zope3/lib/python/Zope/App/Publisher/Browser/tests/testDirectives.py 1.7 => 1.8 ===
 request = Request(IBrowserPresentation)
 
+class VT(V1, object):
+    def publishTraverse(self, request, name):
+        try:
+            return int(name)
+        except:
+            return super(VT, self).publishTraverse(request, name)
+
 class Ob:
     __implements__ = IC
 
@@ -269,6 +276,34 @@
         self.assertEqual(v(), 'done')
         v = getView(ob, 'test.html', request)
         self.assertEqual(str(v()), '<html><body><p>done</p></body></html>\n')
+
+    def testNamedViewPageViewsCustomTraversr(self):
+        self.assertEqual(queryView(ob, 'test', request), None)
+
+        xmlconfig(StringIO(template %
+            """
+            <browser:view
+                  name="test"
+                  factory="Zope.App.Publisher.Browser.tests.testDirectives.VT"
+                  for="Zope.ComponentArchitecture.tests.TestViews.IC">
+
+                <browser:page name="index.html" attribute="index" /> 
+                <browser:page name="action.html" attribute="action" /> 
+            </browser:view>
+            """
+            ))
+
+        view = getView(ob, 'test', request)
+        self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))
+
+
+        v = view.publishTraverse(request, 'index.html')
+        self.assertEqual(v(), 'V1 here')
+        v = view.publishTraverse(request, 'action.html')
+        self.assertEqual(v(), 'done')
+
+        v = view.publishTraverse(request, '42')
+        self.assertEqual(v, 42)
 
     def testNamedViewPageViewsNoDefault(self):
         self.assertEqual(queryView(ob, 'test', request),