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

Marius Gedminas mgedmin@codeworks.lt
Thu, 17 Apr 2003 04:52:58 -0400


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

Modified Files:
	test_http.py 
Log Message:
Added unit test for HTTPRequest.__deduceServerURL and cleaned up the code a bit.
Changed HTTPRequest.setApplicationServer to omit the port if it is the default
for the protocol.


=== Zope3/src/zope/publisher/tests/test_http.py 1.12 => 1.13 ===
--- Zope3/src/zope/publisher/tests/test_http.py:1.12	Tue Apr 15 05:37:29 2003
+++ Zope3/src/zope/publisher/tests/test_http.py	Thu Apr 17 04:52:58 2003
@@ -221,6 +221,16 @@
         self.assertEquals(req._app_server, 'https://foo')
         req.setApplicationServer('foo', proto='https', port=8080)
         self.assertEquals(req._app_server, 'https://foo:8080')
+        req.setApplicationServer('foo', proto='http', port='9673')
+        self.assertEquals(req._app_server, 'http://foo:9673')
+        req.setApplicationServer('foo', proto='https', port=443)
+        self.assertEquals(req._app_server, 'https://foo')
+        req.setApplicationServer('foo', proto='https', port='443')
+        self.assertEquals(req._app_server, 'https://foo')
+        req.setApplicationServer('foo', port=80)
+        self.assertEquals(req._app_server, 'http://foo')
+        req.setApplicationServer('foo', proto='telnet', port=80)
+        self.assertEquals(req._app_server, 'telnet://foo:80')
 
     def test_setApplicationNames(self):
         req = self._createRequest()
@@ -258,6 +268,26 @@
         verifyObject(IHTTPRequest, rq)
         verifyObject(IHTTPCredentials, rq)
         verifyObject(IHTTPApplicationRequest, rq)
+
+    def testDeduceServerURL(self):
+        req = self._createRequest()
+        deduceServerURL = req._HTTPRequest__deduceServerURL
+        req._environ = {'HTTP_HOST': 'example.com:80'}
+        self.assertEquals(deduceServerURL(), 'http://example.com')
+        req._environ = {'HTTP_HOST': 'example.com:8080'}
+        self.assertEquals(deduceServerURL(), 'http://example.com:8080')
+        req._environ = {'HTTP_HOST': 'example.com:443', 'HTTPS': 'on'}
+        self.assertEquals(deduceServerURL(), 'https://example.com')
+        req._environ = {'HTTP_HOST': 'example.com:80', 'HTTPS': 'ON'}
+        self.assertEquals(deduceServerURL(), 'https://example.com:80')
+        req._environ = {'HTTP_HOST': 'example.com:8080',
+                        'SERVER_PORT_SECURE': '1'}
+        self.assertEquals(deduceServerURL(), 'https://example.com:8080')
+        req._environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT':'8080',
+                        'SERVER_PORT_SECURE': '0'}
+        self.assertEquals(deduceServerURL(), 'http://example.com:8080')
+        req._environ = {'SERVER_NAME': 'example.com'}
+        self.assertEquals(deduceServerURL(), 'http://example.com')
 
 
 def test_suite():