[Zope3-checkins] SVN: Zope3/trunk/src/zope/traversing/ clean imports, merge ftests into tests

Bernd Dorn bernd.dorn at lovelysystems.com
Tue Mar 27 08:32:03 EDT 2007


Log message for revision 73719:
  clean imports, merge ftests into tests

Changed:
  U   Zope3/trunk/src/zope/traversing/adapters.py
  U   Zope3/trunk/src/zope/traversing/browser/absoluteurl.py
  U   Zope3/trunk/src/zope/traversing/browser/tests.py
  D   Zope3/trunk/src/zope/traversing/ftests/
  A   Zope3/trunk/src/zope/traversing/tests/ftesting.zcml
  A   Zope3/trunk/src/zope/traversing/tests/layer.py
  A   Zope3/trunk/src/zope/traversing/tests/test_skinf.py
  A   Zope3/trunk/src/zope/traversing/tests/test_vhosting.py

-=-
Modified: Zope3/trunk/src/zope/traversing/adapters.py
===================================================================
--- Zope3/trunk/src/zope/traversing/adapters.py	2007-03-27 12:21:50 UTC (rev 73718)
+++ Zope3/trunk/src/zope/traversing/adapters.py	2007-03-27 12:32:02 UTC (rev 73719)
@@ -15,7 +15,7 @@
 
 $Id$
 """
-from types import StringTypes, MethodType
+from types import StringTypes
 
 import zope.interface
 import zope.component

Modified: Zope3/trunk/src/zope/traversing/browser/absoluteurl.py
===================================================================
--- Zope3/trunk/src/zope/traversing/browser/absoluteurl.py	2007-03-27 12:21:50 UTC (rev 73718)
+++ Zope3/trunk/src/zope/traversing/browser/absoluteurl.py	2007-03-27 12:32:02 UTC (rev 73719)
@@ -19,7 +19,6 @@
 import zope.component
 from zope.interface import implements
 from zope.proxy import sameProxiedObjects
-from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.publisher.browser import BrowserView
 from zope.traversing.browser.interfaces import IAbsoluteURL
 from zope.i18nmessageid import MessageFactory

Modified: Zope3/trunk/src/zope/traversing/browser/tests.py
===================================================================
--- Zope3/trunk/src/zope/traversing/browser/tests.py	2007-03-27 12:21:50 UTC (rev 73718)
+++ Zope3/trunk/src/zope/traversing/browser/tests.py	2007-03-27 12:32:02 UTC (rev 73719)
@@ -21,7 +21,7 @@
 from zope.component import getMultiAdapter
 from zope.traversing.browser.absoluteurl import absoluteURL
 from zope.traversing.browser.interfaces import IAbsoluteURL
-from zope.traversing.testing import browserView, browserResource
+from zope.traversing.testing import browserView
 from zope.i18n.interfaces import IUserPreferredCharsets
 from zope.interface import Interface, implements
 from zope.interface.verify import verifyObject

Copied: Zope3/trunk/src/zope/traversing/tests/ftesting.zcml (from rev 73718, Zope3/trunk/src/zope/traversing/ftests/ftesting.zcml)

Copied: Zope3/trunk/src/zope/traversing/tests/layer.py (from rev 73718, Zope3/trunk/src/zope/traversing/ftests/layer.py)

Copied: Zope3/trunk/src/zope/traversing/tests/test_skinf.py (from rev 73718, Zope3/trunk/src/zope/traversing/ftests/test_skin.py)
===================================================================
--- Zope3/trunk/src/zope/traversing/ftests/test_skin.py	2007-03-27 12:21:50 UTC (rev 73718)
+++ Zope3/trunk/src/zope/traversing/tests/test_skinf.py	2007-03-27 12:32:02 UTC (rev 73719)
@@ -0,0 +1,36 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Functional tests for skin traversing
+
+$Id$
+"""
+import unittest
+from zope.app.testing import functional
+from zope.publisher.interfaces import NotFound
+from zope.traversing.tests.layer import TraversingLayer
+
+class TestSkin(functional.BrowserTestCase):
+
+    def test_missing_skin(self):
+        self.assertRaises(NotFound, self.publish, "/++skin++missingskin")
+
+def test_suite():
+    suite = unittest.TestSuite()
+    TestSkin.layer = TraversingLayer
+    suite.addTest(unittest.makeSuite(TestSkin))
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main()

Copied: Zope3/trunk/src/zope/traversing/tests/test_vhosting.py (from rev 73718, Zope3/trunk/src/zope/traversing/ftests/test_vhosting.py)
===================================================================
--- Zope3/trunk/src/zope/traversing/ftests/test_vhosting.py	2007-03-27 12:21:50 UTC (rev 73718)
+++ Zope3/trunk/src/zope/traversing/tests/test_vhosting.py	2007-03-27 12:32:02 UTC (rev 73719)
@@ -0,0 +1,192 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Functional tests for virtual hosting.
+
+$Id$
+"""
+import unittest
+import transaction
+from zope.traversing.api import traverse
+from zope.traversing.testing import browserResource
+from zope.security.checker import defineChecker, NamesChecker, NoProxy
+from zope.security.checker import _checkers, undefineChecker
+
+from zope.app.testing import functional
+from zope.app.folder import Folder
+from zope.app.publisher.browser.resource import Resource
+from zope.app.container.contained import Contained
+from zope.app.zptpage.zptpage import ZPTPage
+from zope.traversing.tests.layer import TraversingLayer
+
+class MyObj(Contained):
+    def __getitem__(self, key):
+        return traverse(self, '/foo/bar/' + key)
+
+
+class TestVirtualHosting(functional.BrowserTestCase):
+
+    def setUp(self):
+        functional.BrowserTestCase.setUp(self)
+        defineChecker(MyObj, NoProxy)
+
+    def tearDown(self):
+        functional.BrowserTestCase.tearDown(self)
+        undefineChecker(MyObj)
+
+    def test_request_url(self):
+        self.addPage('/pt', u'<span tal:replace="request/URL"/>')
+        self.verify('/pt', 'http://localhost/pt\n')
+        self.verify('/++vh++/++/pt',
+                    'http://localhost/pt\n')
+        self.verify('/++vh++https:otherhost:443/++/pt',
+                    'https://otherhost/pt\n')
+        self.verify('/++vh++https:otherhost:443/fake/folders/++/pt',
+                    'https://otherhost/fake/folders/pt\n')
+
+        self.addPage('/foo/bar/pt', u'<span tal:replace="request/URL"/>')
+        self.verify('/foo/bar/pt', 'http://localhost/foo/bar/pt\n')
+        self.verify('/foo/bar/++vh++/++/pt',
+                    'http://localhost/pt\n')
+        self.verify('/foo/bar/++vh++https:otherhost:443/++/pt',
+                    'https://otherhost/pt\n')
+        self.verify('/foo/++vh++https:otherhost:443/fake/folders/++/bar/pt',
+                    'https://otherhost/fake/folders/bar/pt\n')
+
+    def test_request_base(self):
+        self.addPage('/pt', u'<head></head>')
+        self.verify('/pt/',
+                    '<head>\n<base href="http://localhost/pt" />\n'
+                    '</head>\n')
+        self.verify('/++vh++/++/pt/',
+                    '<head>\n<base href="http://localhost/pt" />\n'
+                    '</head>\n')
+        self.verify('/++vh++https:otherhost:443/++/pt/',
+                    '<head>\n'
+                    '<base href="https://otherhost/pt" />'
+                    '\n</head>\n')
+        self.verify('/++vh++https:otherhost:443/fake/folders/++/pt/',
+                    '<head>\n<base href='
+                    '"https://otherhost/fake/folders/pt" />'
+                    '\n</head>\n')
+
+        self.addPage('/foo/bar/pt', u'<head></head>')
+        self.verify('/foo/bar/pt/',
+                    '<head>\n<base '
+                    'href="http://localhost/foo/bar/pt" />\n'
+                    '</head>\n')
+        self.verify('/foo/bar/++vh++/++/pt/',
+                    '<head>\n<base href="http://localhost/pt" />\n'
+                    '</head>\n')
+        self.verify('/foo/bar/++vh++https:otherhost:443/++/pt/',
+                    '<head>\n'
+                    '<base href="https://otherhost/pt" />'
+                    '\n</head>\n')
+        self.verify('/foo/++vh++https:otherhost:443/fake/folders/++/bar/pt/',
+                    '<head>\n<base href='
+                    '"https://otherhost/fake/folders/bar/pt" />'
+                    '\n</head>\n')
+
+    def test_request_redirect(self):
+        self.addPage('/foo/index.html', u'Spam')
+        self.verifyRedirect('/foo', 'http://localhost/foo/index.html')
+        self.verifyRedirect('/++vh++https:otherhost:443/++/foo',
+                            'https://otherhost/foo/index.html')
+        self.verifyRedirect('/foo/++vh++https:otherhost:443/bar/++',
+                            'https://otherhost/bar/index.html')
+
+    def test_absolute_url(self):
+        self.addPage('/pt', u'<span tal:replace="template/@@absolute_url"/>')
+        self.verify('/pt', 'http://localhost/pt\n')
+        self.verify('/++vh++/++/pt',
+                    'http://localhost/pt\n')
+        self.verify('/++vh++https:otherhost:443/++/pt',
+                    'https://otherhost/pt\n')
+        self.verify('/++vh++https:otherhost:443/fake/folders/++/pt',
+                    'https://otherhost/fake/folders/pt\n')
+
+        self.addPage('/foo/bar/pt',
+                     u'<span tal:replace="template/@@absolute_url"/>')
+        self.verify('/foo/bar/pt', 'http://localhost/foo/bar/pt\n')
+        self.verify('/foo/bar/++vh++/++/pt',
+                    'http://localhost/pt\n')
+        self.verify('/foo/bar/++vh++https:otherhost:443/++/pt',
+                    'https://otherhost/pt\n')
+        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):
+        browserResource('quux', Resource)
+        # Only register the checker once, so that multiple test runs pass.
+        if Resource not in _checkers:
+            defineChecker(Resource, NamesChecker(['__call__']))
+        self.addPage('/foo/bar/pt',
+                     u'<span tal:replace="context/++resource++quux" />')
+        self.verify('/foo/bar/pt', 'http://localhost/@@/quux\n')
+        self.verify('/foo/++vh++https:otherhost:443/fake/folders/++/bar/pt',
+                    'https://otherhost/fake/folders/@@/quux\n')
+
+    def createFolders(self, path):
+        """addFolders('/a/b/c/d') would traverse and/or create three nested
+        folders (a, b, c) and return a tuple (c, 'd') where c is a Folder
+        instance at /a/b/c."""
+        folder = self.getRootFolder()
+        if path[0] == '/':
+            path = path[1:]
+        path = path.split('/')
+        for id in path[:-1]:
+            try:
+                folder = folder[id]
+            except KeyError:
+                folder[id] = Folder()
+                folder = folder[id]
+        return folder, path[-1]
+
+    def createObject(self, path, obj):
+        folder, id = self.createFolders(path)
+        folder[id] = obj
+        transaction.commit()
+
+    def addPage(self, path, content):
+        page = ZPTPage()
+        page.source = content
+        self.createObject(path, page)
+
+    def verify(self, path, content):
+        result = self.publish(path)
+        self.assertEquals(result.getStatus(), 200)
+        self.assertEquals(result.getBody(), content)
+
+    def verifyRedirect(self, path, location):
+        result = self.publish(path)
+        self.assertEquals(result.getStatus(), 302)
+        self.assertEquals(result.getHeader('Location'), location)
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    TestVirtualHosting.layer = TraversingLayer
+    suite.addTest(unittest.makeSuite(TestVirtualHosting))
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main()



More information about the Zope3-Checkins mailing list