[Zope3-checkins] CVS: Zope3/src/zope/publisher/tests - test_http.py:1.12

Albertas Agejevas alga@codeworks.lt
Tue, 15 Apr 2003 05:37:29 -0400


Update of /cvs-repository/Zope3/src/zope/publisher/tests
In directory cvs.zope.org:/tmp/cvs-serv21534/src/zope/publisher/tests

Modified Files:
	test_http.py 
Log Message:
Virtual Hosting support in the request.

Added a new namespace ++vh++ with a handler which sets the server URL and
the application URL in the request.

Functional tests for virtual hosting.

Vrtual hosting support in @@absoulute_url is not implemented yet.



=== Zope3/src/zope/publisher/tests/test_http.py 1.11 => 1.12 ===
--- Zope3/src/zope/publisher/tests/test_http.py:1.11	Fri Apr 11 08:55:41 2003
+++ Zope3/src/zope/publisher/tests/test_http.py	Tue Apr 15 05:37:29 2003
@@ -213,8 +213,52 @@
         r = self._createRequest(extra_env={'REQUEST_METHOD':'eggs'})
         self.assertEqual(r.method, 'EGGS')
 
+    def test_setApplicationServer(self):
+        req = self._createRequest()
+        req.setApplicationServer('foo')
+        self.assertEquals(req._app_server, 'http://foo')
+        req.setApplicationServer('foo', proto='https')
+        self.assertEquals(req._app_server, 'https://foo')
+        req.setApplicationServer('foo', proto='https', port=8080)
+        self.assertEquals(req._app_server, 'https://foo:8080')
+
+    def test_setApplicationNames(self):
+        req = self._createRequest()
+        names = ['x', 'y', 'z']
+        req.setApplicationNames(names)
+        self.assertEquals(req._app_names, ['x', 'y', 'z'])
+        names[0] = 'muahahahaha'
+        self.assertEquals(req._app_names, ['x', 'y', 'z'])
+
+    def test_setVirtualHostRoot(self):
+        req = self._createRequest()
+        req._traversed_names = ['x', 'y']
+        req.setVirtualHostRoot()
+        self.assertEquals(req._vh_trunc, 3)
+
+    def test_traverse(self):
+        # setting _vh_trunc *before* traversal is a no-op
+        req = self._createRequest()
+        req._vh_trunc = 1
+        req.traverse(self.app)
+        self.assertEquals(req._traversed_names, ['folder', 'item'])
+
+        # setting it during traversal matters
+        req = self._createRequest()
+        def hook(self, object, req=req):
+            req._vh_trunc = 1
+        req.publication.callTraversalHooks = hook
+        req.traverse(self.app)
+        self.assertEquals(req._traversed_names, ['item'])
+
     def testInterface(self):
-        verifyObject(IHTTPRequest, self._createRequest())
+        from zope.publisher.interfaces.http import IHTTPCredentials
+        from zope.publisher.interfaces.http import IHTTPApplicationRequest
+        rq = self._createRequest()
+        verifyObject(IHTTPRequest, rq)
+        verifyObject(IHTTPCredentials, rq)
+        verifyObject(IHTTPApplicationRequest, rq)
+
 
 def test_suite():
     loader = unittest.TestLoader()