[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Traversing/tests - testNamespaceTrversal.py:1.4 testPhysicalLocationAdapters.py:1.2

Jim Fulton jim@zope.com
Sat, 13 Jul 2002 10:19:07 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Traversing/tests
In directory cvs.zope.org:/tmp/cvs-serv1111/lib/python/Zope/App/Traversing/tests

Modified Files:
	testNamespaceTrversal.py testPhysicalLocationAdapters.py 
Log Message:
Fixed bug in context management when uri segments that produce only
side effects (e.g. ++skin++ZopeTop) are used.

Fixed up absolute url bread crumbs to not show side-effect steps in
bread crumbs, while retaining them in the breadcrumb urls.

Refactored side-effect handling slightly (changed context data names)
in absolute url and physical path code.

Added tests for side effect handling for absolute url, physical path,
and namespace handling code.


=== Zope3/lib/python/Zope/App/Traversing/tests/testNamespaceTrversal.py 1.3 => 1.4 ===
     def setUp(self):
         from Zope.App.Traversing.Namespaces import provideNamespaceHandler
         from Zope.App.Traversing.AttrItemNamespaces import attr, item
+        from Zope.App.Traversing.SkinNamespace import skin
         provideNamespaceHandler('attribute', attr)
         provideNamespaceHandler('item', item)
+        provideNamespaceHandler('skin', skin)
 
 
     def testAttr(self):
@@ -47,6 +49,24 @@
         traverser = Traverser(c)
         v = traverser.traverse('++item++a')
         self.assertEqual(v, 'avalue')
+
+    def testSideEffectsContextDetail(self):
+        """Check to make sure that when we traverse something in context,
+        that we get the right context for the result."""
+        from Zope.Proxy.ContextWrapper \
+             import ContextWrapper, getWrapperContainer
+        from Zope.App.Traversing.Traverser import Traverser
+        from Zope.Publisher.Browser.BrowserRequest import TestRequest
+        
+        c1 = C()
+        c2 = C()
+        c2c1 = ContextWrapper(c2, c1)
+        
+        traverser = Traverser(c2c1)
+        v = traverser.traverse('++skin++ZopeTop', request=TestRequest())
+        self.assertEqual(v, c2)
+        self.failUnless(getWrapperContainer(v) is c2c1)
+        
         
         
 


=== Zope3/lib/python/Zope/App/Traversing/tests/testPhysicalLocationAdapters.py 1.1 => 1.2 ===
         self.assertRaises(TypeError, adapter.getPhysicalPath)
         self.assertRaises(TypeError, adapter.getPhysicalRoot)
 
+    def testWSideEffectDataInFront(self):
+        provideAdapter(None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
+        provideAdapter(IContainmentRoot, IPhysicallyLocatable,
+                       RootPhysicallyLocatable)
+
+        root = Root()
+        root = ContextWrapper(root, root, name='.',
+                              side_effect_name="++skin++ZopeTop")
+        f1 = ContextWrapper(C(), root, name='f1')
+        f2 = ContextWrapper(C(),   f1, name='f2')
+        f3 = ContextWrapper(C(),   f2, name='f3')
+
+        adapter = getAdapter(f3, IPhysicallyLocatable)
+
+        self.assertEqual(adapter.getPhysicalPath(), ('', 'f1', 'f2', 'f3'))
+        self.assertEqual(adapter.getPhysicalRoot(), root)
+        
+        adapter = getAdapter(C(), IPhysicallyLocatable)
+        self.assertRaises(TypeError, adapter.getPhysicalPath)
+        self.assertRaises(TypeError, adapter.getPhysicalRoot)
+
+    def testWSideEffectDataInMiddle(self):
+        provideAdapter(None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
+        provideAdapter(IContainmentRoot, IPhysicallyLocatable,
+                       RootPhysicallyLocatable)
+
+        root = Root()
+        c = C()
+        f1 = ContextWrapper(c, root, name='f1')
+        f1 = ContextWrapper(c, f1, name='.',
+                            side_effect_name="++skin++ZopeTop")
+        f2 = ContextWrapper(C(),   f1, name='f2')
+        f3 = ContextWrapper(C(),   f2, name='f3')
+
+        adapter = getAdapter(f3, IPhysicallyLocatable)
+
+        self.assertEqual(adapter.getPhysicalPath(), ('', 'f1', 'f2', 'f3'))
+        self.assertEqual(adapter.getPhysicalRoot(), root)
+        
+        adapter = getAdapter(C(), IPhysicallyLocatable)
+        self.assertRaises(TypeError, adapter.getPhysicalPath)
+        self.assertRaises(TypeError, adapter.getPhysicalRoot)
+
 def test_suite():
     return TestSuite((
         makeSuite(Test),