[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/tests - testHTTPServer.py:1.1.2.12
Shane Hathaway
shane@cvs.zope.org
Thu, 31 Jan 2002 11:33:46 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Server/tests
In directory cvs.zope.org:/tmp/cvs-serv14226/tests
Modified Files:
Tag: Zope-3x-branch
testHTTPServer.py
Log Message:
- Parse newlines, rather than requiring CRLFs, in the HTTP server.
- Fixed chunking to use hexadecimal.
- Renamed modules and classes to fit with Zope 3 naming conventions.
- Put buffer classes in their own module.
- Provided a way to insert TCPWatch in the HTTP server tests.
=== Zope3/lib/python/Zope/Server/tests/testHTTPServer.py 1.1.2.11 => 1.1.2.12 ===
LOCALHOST = '127.0.0.1'
+SERVER_PORT = 0 # Set these port numbers to 0 to auto-bind, or
+CONNECT_TO_PORT = 0 # use specific numbers to inspect using TCPWatch.
+
my_adj = Adjustments()
# Reduce overflows to make testing easier.
@@ -77,10 +80,12 @@
def setUp(self):
td.setThreadCount(4)
self.orig_map_size = len(socket_map)
- # Bind to any port on localhost.
- self.server = EchoHTTPServer(LOCALHOST, 0, task_dispatcher=td,
- adj=my_adj)
- self.port = self.server.socket.getsockname()[1]
+ self.server = EchoHTTPServer(LOCALHOST, SERVER_PORT,
+ task_dispatcher=td, adj=my_adj)
+ if CONNECT_TO_PORT == 0:
+ self.port = self.server.socket.getsockname()[1]
+ else:
+ self.port = CONNECT_TO_PORT
self.run_loop = 1
self.counter = 0
self.thread = Thread(target=self.loop)
@@ -172,6 +177,26 @@
self.failUnlessEqual(length, len(response_body))
self.failUnlessEqual(response_body, expect_body)
+ def testWithoutCRLF(self):
+ # Tests the use of just newlines rather than CR/LFs.
+ data = "Echo\nthis\r\nplease"
+ s = ("GET / HTTP/1.0\n"
+ "Connection: close\n"
+ "Content-Length: %d\n"
+ "\n"
+ "%s") % (len(data), data)
+
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.connect((LOCALHOST, self.port))
+ sock.send(s)
+ response = ClientHTTPResponse(sock)
+ response.begin()
+ self.failUnlessEqual(int(response.status), 200)
+ length = int(response.getheader('Content-Length', '0'))
+ response_body = response.read(length)
+ self.failUnlessEqual(length, len(data))
+ self.failUnlessEqual(response_body, data)
+
def testLargeBody(self):
# Tests the use of multiple requests in a single connection.
h = HTTPConnection(LOCALHOST, self.port)
@@ -226,7 +251,7 @@
self.failUnlessEqual(response_body, '')
def testChunkingRequestWithContent(self):
- control_line="32;\r\n"
+ control_line="20;\r\n" # 20 hex = 32 dec
s = 'This string has 32 characters.\r\n'
expect = s * 12