[Zope3-checkins] CVS: Zope3/src/zope/app/traversing/ftests - test_vhosting.py:1.5

Marius Gedminas mgedmin@codeworks.lt
Mon, 28 Apr 2003 09:14:51 -0400


Update of /cvs-repository/Zope3/src/zope/app/traversing/ftests
In directory cvs.zope.org:/tmp/cvs-serv25303/src/zope/app/traversing/ftests

Modified Files:
	test_vhosting.py 
Log Message:
Virtual hosting did not work correctly in all cases (e.g. service configuration
paths did not have leading path elements truncated when they should have).
This is now fixed by adding a method getVirtualHostRoot to IVirtualHostRequest
and making AbsoluteURL views use that for identifying the virtual host root
instead of relying on special context wrappers.  Also added a functional test
to prevent regressions.



=== Zope3/src/zope/app/traversing/ftests/test_vhosting.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/traversing/ftests/test_vhosting.py:1.4	Fri Apr 18 02:42:52 2003
+++ Zope3/src/zope/app/traversing/ftests/test_vhosting.py	Mon Apr 28 09:14:20 2003
@@ -24,6 +24,18 @@
 from zope.component.resource import provideResource
 from zope.publisher.interfaces.browser import IBrowserPresentation
 from zope.app.publisher.browser.resource import Resource
+from zope.app.traversing import traverse
+from zope.security.checker import defineChecker, NoProxy
+from zope.proxy.context import ContextMethod
+
+__metaclass__ = type
+
+class MyObj:
+    def __getitem__(wrapped_self, key):
+        return traverse(wrapped_self, '/foo/bar/' + key)
+    __getitem__ = ContextMethod(__getitem__)
+
+defineChecker(MyObj, NoProxy)
 
 class TestVirtualHosting(BrowserTestCase):
 
@@ -108,6 +120,14 @@
         self.verify('/foo/++vh++https:otherhost:443/fake/folders/++/bar/pt',
                     'https://otherhost/fake/folders/bar/pt\n')
 
+    def test_absolute_url_absolute_traverse(self):
+        self.createObject('/foo/bar/obj', MyObj())
+        self.addPage('/foo/bar/pt',
+                     u'<span tal:replace="container/obj/pt/@@absolute_url"/>')
+        self.verify('/foo/bar/pt', 'http://localhost/foo/bar/pt\n')
+        self.verify('/foo/++vh++https:otherhost:443/bar/pt',
+                    'https://otherhost/bar/pt\n')
+
     def test_resources(self):
         provideResource('quux', IBrowserPresentation, Resource)
         self.addPage('/foo/bar/pt',
@@ -132,12 +152,15 @@
                 folder = folder[id]
         return folder, path[-1]
 
-    def addPage(self, path, content):
+    def createObject(self, path, obj):
         folder, id = self.createFolders(path)
+        folder.setObject(id, obj)
+        get_transaction().commit()
+
+    def addPage(self, path, content):
         page = ZPTPage()
         page.source = content
-        folder.setObject(id, page)
-        get_transaction().commit()
+        self.createObject(path, page)
 
     def verify(self, path, content):
         result = self.publish(path)