[Zope-Checkins] CVS: Products/SiteAccess/tests - __init__.py:1.2
testVirtualHostMonster.py:1.2
Evan Simpson
evan at 4-am.com
Wed Dec 10 12:53:18 EST 2003
Update of /cvs-repository/Products/SiteAccess/tests
In directory cvs.zope.org:/tmp/cvs-serv13873/lib/python/Products/SiteAccess/tests
Added Files:
__init__.py testVirtualHostMonster.py
Log Message:
Collector #809: Added and documented Traversable.py methods absolute_url_path and virtual_url_path, and reverted earlier change to absolute_url behaviour.
=== Products/SiteAccess/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 10 12:53:18 2003
+++ Products/SiteAccess/tests/__init__.py Wed Dec 10 12:52:47 2003
@@ -0,0 +1 @@
+# SiteAccess test package
=== Products/SiteAccess/tests/testVirtualHostMonster.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 10 12:53:18 2003
+++ Products/SiteAccess/tests/testVirtualHostMonster.py Wed Dec 10 12:52:47 2003
@@ -0,0 +1,101 @@
+"""Virtual Host Monster regression tests.
+
+These tests mainly verify that OFS.Traversable.absolute_url()
+works correctly in a VHM environment.
+
+Also see http://zope.org/Collectors/Zope/809
+
+Note: Tests require Zope >= 2.7
+
+$Id$
+"""
+
+from Testing.makerequest import makerequest
+
+import Zope
+Zope.startup()
+
+import unittest
+
+
+class VHMRegressions(unittest.TestCase):
+
+ def setUp(self):
+ get_transaction().begin()
+ self.app = makerequest(Zope.app())
+ try:
+ self.app.manage_addProduct['SiteAccess'].manage_addVirtualHostMonster('VHM')
+ self.app.manage_addFolder('folder')
+ self.app.folder.manage_addDTMLMethod('doc', '')
+ self.app.REQUEST.set('PARENTS', [self.app])
+ self.traverse = self.app.REQUEST.traverse
+ except:
+ self.tearDown()
+
+ def tearDown(self):
+ get_transaction().abort()
+ self.app._p_jar.close()
+
+ def testAbsoluteUrl(self):
+ m = self.app.folder.doc.absolute_url
+ self.assertEqual(m(), 'http://foo/folder/doc')
+
+ def testAbsoluteUrlPath(self):
+ m = self.app.folder.doc.absolute_url_path
+ self.assertEqual(m(), '/folder/doc')
+
+ def testVirtualUrlPath(self):
+ m = self.app.folder.doc.absolute_url
+ self.assertEqual(m(relative=1), 'folder/doc')
+ m = self.app.folder.doc.virtual_url_path
+ self.assertEqual(m(), 'folder/doc')
+
+ def testPhysicalPath(self):
+ m = self.app.folder.doc.getPhysicalPath
+ self.assertEqual(m(), ('', 'folder', 'doc'))
+
+def gen_cases():
+ for vbase, ubase in (
+ ('', 'http://foo'),
+ ('/VirtualHostBase/http/example.com:80', 'http://example.com'),
+ ):
+ yield vbase, '', '', 'folder/doc', ubase
+ for vr, _vh, p in (
+ ('folder', '', 'doc'),
+ ('folder', 'foo', 'doc'),
+ ('', 'foo', 'folder/doc'),
+ ):
+ vparts = [vbase, vr, 'VirtualHostRoot']
+ if not vr:
+ del vparts[1]
+ if _vh:
+ vparts.append('_vh_' + _vh)
+ yield '/'.join(vparts), vr, _vh, p, ubase
+
+for i, (vaddr, vr, _vh, p, ubase) in enumerate(gen_cases()):
+ def test(self):
+ ob = self.traverse('%s/%s/' % (vaddr, p))
+ vhp = '/' + '/'.join([x for x in _vh, p if x])
+ self.assertEqual(ob.absolute_url(), ubase + vhp)
+ self.assertEqual(ob.absolute_url_path(), vhp)
+ self.assertEqual(ob.absolute_url(relative=1), p)
+ self.assertEqual(ob.virtual_url_path(), p)
+ self.assertEqual(ob.getPhysicalPath(), ('', 'folder', 'doc'))
+
+ app = ob.aq_parent.aq_parent
+ self.assertEqual(app.absolute_url(), ubase + '/' + _vh)
+ self.assertEqual(app.absolute_url_path(), '/' + _vh)
+ self.assertEqual(app.absolute_url(relative=1), '')
+ self.assertEqual(app.virtual_url_path(), '')
+
+ setattr(VHMRegressions, 'testTraverse%s' % i, test)
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(VHMRegressions))
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
More information about the Zope-Checkins
mailing list