summaryrefslogtreecommitdiff
path: root/cherrypy/test
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2008-11-08 23:30:21 +0000
committerRobert Brewer <fumanchu@aminus.org>2008-11-08 23:30:21 +0000
commit4cba9acfc2af2ec487d36452060c651c4472a4e9 (patch)
treed7450ac7b684b0b94ec06d9ec5d976cd1b4954f6 /cherrypy/test
parent7d39e1464b57ff28a8e87312079c38e5c71db2ab (diff)
downloadcherrypy-git-cherrypy-3.1.1.tar.gz
Merge from trunk for today's fixes [2072] to [2080].cherrypy-3.1.1
--HG-- branch : cherrypy-3.1.x
Diffstat (limited to 'cherrypy/test')
-rw-r--r--cherrypy/test/test_conn.py6
-rw-r--r--cherrypy/test/test_http.py12
-rw-r--r--cherrypy/test/test_logging.py18
-rw-r--r--cherrypy/test/test_objectmapping.py2
-rw-r--r--cherrypy/test/test_refleaks.py2
-rwxr-xr-xcherrypy/test/test_session.py4
-rw-r--r--cherrypy/test/test_xmlrpc.py12
-rw-r--r--cherrypy/test/webtest.py14
8 files changed, 34 insertions, 36 deletions
diff --git a/cherrypy/test/test_conn.py b/cherrypy/test/test_conn.py
index 8a9bff29..c1f902c5 100644
--- a/cherrypy/test/test_conn.py
+++ b/cherrypy/test/test_conn.py
@@ -171,6 +171,12 @@ class ConnectionTests(helper.CPWebCase):
# Make another request on the same connection, which should error.
self.assertRaises(httplib.NotConnected, self.getPage, "/")
+
+ # Try HEAD. See http://www.cherrypy.org/ticket/864.
+ self.getPage("/stream", method='HEAD')
+ self.assertStatus('200 OK')
+ self.assertBody('')
+ self.assertNoHeader("Transfer-Encoding")
else:
self.PROTOCOL = "HTTP/1.0"
diff --git a/cherrypy/test/test_http.py b/cherrypy/test/test_http.py
index 92162bcc..ae7886c7 100644
--- a/cherrypy/test/test_http.py
+++ b/cherrypy/test/test_http.py
@@ -70,9 +70,9 @@ class HTTPTests(helper.CPWebCase):
# will hang. Verify that CP times out the socket and responds
# with 411 Length Required.
if self.scheme == "https":
- c = httplib.HTTPSConnection("127.0.0.1:%s" % self.PORT)
+ c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
else:
- c = httplib.HTTPConnection("127.0.0.1:%s" % self.PORT)
+ c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT))
c.request("POST", "/")
self.assertEqual(c.getresponse().status, 411)
@@ -87,9 +87,9 @@ class HTTPTests(helper.CPWebCase):
# post file
if self.scheme == 'https':
- c = httplib.HTTPS('127.0.0.1:%s' % self.PORT)
+ c = httplib.HTTPS('%s:%s' % (self.interface(), self.PORT))
else:
- c = httplib.HTTP('127.0.0.1:%s' % self.PORT)
+ c = httplib.HTTP('%s:%s' % (self.interface(), self.PORT))
c.putrequest('POST', '/post_multipart')
c.putheader('Content-Type', content_type)
c.putheader('Content-Length', str(len(body)))
@@ -110,9 +110,9 @@ class HTTPTests(helper.CPWebCase):
# Test missing version in Request-Line
if self.scheme == 'https':
- c = httplib.HTTPSConnection('127.0.0.1:%s' % self.PORT)
+ c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
else:
- c = httplib.HTTPConnection('127.0.0.1:%s' % self.PORT)
+ c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT))
c._output('GET /')
c._send_output()
response = c.response_class(c.sock, strict=c.strict, method='GET')
diff --git a/cherrypy/test/test_logging.py b/cherrypy/test/test_logging.py
index 58b7f5da..cb560e33 100644
--- a/cherrypy/test/test_logging.py
+++ b/cherrypy/test/test_logging.py
@@ -79,14 +79,7 @@ class AccessLogTests(helper.CPWebCase, logtest.LogCase):
self.assertBody('content')
self.assertStatus(200)
- host = self.HOST
- if host == '0.0.0.0':
- # INADDR_ANY, which should respond on localhost.
- host = "127.0.0.1"
- if host == '::':
- # IN6ADDR_ANY, which should respond on localhost.
- host = "::1"
- intro = '%s - - [' % host
+ intro = '%s - - [' % self.interface()
self.assertLog(-1, intro)
@@ -105,14 +98,7 @@ class AccessLogTests(helper.CPWebCase, logtest.LogCase):
self.assertBody('content')
self.assertStatus(200)
- host = self.HOST
- if host == '0.0.0.0':
- # INADDR_ANY, which should respond on localhost.
- host = "127.0.0.1"
- if host == '::':
- # IN6ADDR_ANY, which should respond on localhost.
- host = "::1"
- intro = '%s - - [' % host
+ intro = '%s - - [' % self.interface()
self.assertLog(-1, intro)
if [k for k, v in self.headers if k.lower() == 'content-length']:
diff --git a/cherrypy/test/test_objectmapping.py b/cherrypy/test/test_objectmapping.py
index 1c163c30..7883cd96 100644
--- a/cherrypy/test/test_objectmapping.py
+++ b/cherrypy/test/test_objectmapping.py
@@ -244,7 +244,7 @@ class ObjectMappingTest(helper.CPWebCase):
self.script_name = ""
# Test absoluteURI's in the Request-Line
- self.getPage('http://127.0.0.1/')
+ self.getPage('http://%s:%s/' % (self.interface(), self.PORT))
self.assertBody('world')
# Test that the "isolated" app doesn't leak url's into the root app.
diff --git a/cherrypy/test/test_refleaks.py b/cherrypy/test/test_refleaks.py
index c4941817..a71f9d25 100644
--- a/cherrypy/test/test_refleaks.py
+++ b/cherrypy/test/test_refleaks.py
@@ -88,7 +88,7 @@ class ReferenceTests(helper.CPWebCase):
success = []
def getpage():
- host = '%s:%s' % (self.HOST, self.PORT)
+ host = '%s:%s' % (self.interface(), self.PORT)
if self.scheme == 'https':
c = httplib.HTTPSConnection(host)
else:
diff --git a/cherrypy/test/test_session.py b/cherrypy/test/test_session.py
index 927d79f4..778725aa 100755
--- a/cherrypy/test/test_session.py
+++ b/cherrypy/test/test_session.py
@@ -193,9 +193,9 @@ class SessionTest(helper.CPWebCase):
def request(index):
if self.scheme == 'https':
- c = httplib.HTTPSConnection('127.0.0.1:%s' % self.PORT)
+ c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
else:
- c = httplib.HTTPConnection('127.0.0.1:%s' % self.PORT)
+ c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT))
for i in xrange(request_count):
c.putrequest('GET', '/')
for k, v in cookies:
diff --git a/cherrypy/test/test_xmlrpc.py b/cherrypy/test/test_xmlrpc.py
index 08ebfa3a..5b50d40c 100644
--- a/cherrypy/test/test_xmlrpc.py
+++ b/cherrypy/test/test_xmlrpc.py
@@ -116,19 +116,11 @@ class XmlRpcTest(helper.CPWebCase):
except AttributeError:
pass
- host = self.HOST
- if host == '0.0.0.0':
- # INADDR_ANY, which should respond on localhost.
- host = "127.0.0.1"
- if host == '::':
- # IN6ADDR_ANY, which should respond on localhost.
- host = "::1"
-
if scheme == "https":
- url = 'https://%s:%s/xmlrpc/' % (host, self.PORT)
+ url = 'https://%s:%s/xmlrpc/' % (self.interface(), self.PORT)
proxy = xmlrpclib.ServerProxy(url, transport=HTTPSTransport())
else:
- url = 'http://%s:%s/xmlrpc/' % (host, self.PORT)
+ url = 'http://%s:%s/xmlrpc/' % (self.interface(), self.PORT)
proxy = xmlrpclib.ServerProxy(url)
# begin the tests ...
diff --git a/cherrypy/test/webtest.py b/cherrypy/test/webtest.py
index cfcdcd56..ab622d5f 100644
--- a/cherrypy/test/webtest.py
+++ b/cherrypy/test/webtest.py
@@ -192,6 +192,20 @@ class WebCase(TestCase):
self.set_persistent(on)
persistent = property(_get_persistent, _set_persistent)
+ def interface(self):
+ """Return an IP address for a client connection.
+
+ If the server is listening on '0.0.0.0' (INADDR_ANY)
+ or '::' (IN6ADDR_ANY), this will return the proper localhost."""
+ host = self.HOST
+ if host == '0.0.0.0':
+ # INADDR_ANY, which should respond on localhost.
+ return "127.0.0.1"
+ if host == '::':
+ # IN6ADDR_ANY, which should respond on localhost.
+ return "::1"
+ return host
+
def getPage(self, url, headers=None, method="GET", body=None, protocol=None):
"""Open the url with debugging support. Return status, headers, body."""
ServerError.on = False