blob: 7dee6f5e8ac5b43cb5abd4c508efccd17df5e591 [file] [log] [blame]
Georg Brandlf899dfa2008-05-18 09:12:20 +00001"""Unittests for the various HTTPServer modules.
2
3Written by Cody A.W. Somerville <cody-somerville@ubuntu.com>,
4Josip Dzolonga, and Michael Otteneder for the 2007/08 GHOP contest.
5"""
6
7from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
8from SimpleHTTPServer import SimpleHTTPRequestHandler
9from CGIHTTPServer import CGIHTTPRequestHandler
Gregory P. Smith923ba362009-04-06 06:33:26 +000010import CGIHTTPServer
Georg Brandlf899dfa2008-05-18 09:12:20 +000011
12import os
13import sys
Senthil Kumaranb643fc62010-09-30 06:40:56 +000014import re
Georg Brandlf899dfa2008-05-18 09:12:20 +000015import base64
16import shutil
17import urllib
18import httplib
19import tempfile
Georg Brandlf899dfa2008-05-18 09:12:20 +000020
21import unittest
Senthil Kumaranb643fc62010-09-30 06:40:56 +000022
23from StringIO import StringIO
24
Georg Brandlf899dfa2008-05-18 09:12:20 +000025from test import test_support
Victor Stinner6a102812010-04-27 23:55:59 +000026threading = test_support.import_module('threading')
Georg Brandlf899dfa2008-05-18 09:12:20 +000027
28
29class NoLogRequestHandler:
30 def log_message(self, *args):
31 # don't write log messages to stderr
32 pass
33
Senthil Kumaranb643fc62010-09-30 06:40:56 +000034class SocketlessRequestHandler(BaseHTTPRequestHandler):
35 def __init__(self):
36 self.get_called = False
37 self.protocol_version = "HTTP/1.1"
38
39 def do_GET(self):
40 self.get_called = True
41 self.send_response(200)
42 self.send_header('Content-Type', 'text/html')
43 self.end_headers()
44 self.wfile.write('<html><body>Data</body></html>\r\n')
45
46 def log_message(self, format, *args):
47 pass
48
49
Georg Brandlf899dfa2008-05-18 09:12:20 +000050
51class TestServerThread(threading.Thread):
52 def __init__(self, test_object, request_handler):
53 threading.Thread.__init__(self)
54 self.request_handler = request_handler
55 self.test_object = test_object
Georg Brandlf899dfa2008-05-18 09:12:20 +000056
57 def run(self):
58 self.server = HTTPServer(('', 0), self.request_handler)
59 self.test_object.PORT = self.server.socket.getsockname()[1]
Antoine Pitrou1ca8c192010-04-25 21:15:50 +000060 self.test_object.server_started.set()
61 self.test_object = None
Georg Brandlf899dfa2008-05-18 09:12:20 +000062 try:
Antoine Pitrou1ca8c192010-04-25 21:15:50 +000063 self.server.serve_forever(0.05)
Georg Brandlf899dfa2008-05-18 09:12:20 +000064 finally:
65 self.server.server_close()
66
67 def stop(self):
68 self.server.shutdown()
69
70
71class BaseTestCase(unittest.TestCase):
72 def setUp(self):
Antoine Pitrou85bd5872009-10-27 18:50:52 +000073 self._threads = test_support.threading_setup()
Nick Coghlan87c03b32009-10-17 15:23:08 +000074 os.environ = test_support.EnvironmentVarGuard()
Antoine Pitrou1ca8c192010-04-25 21:15:50 +000075 self.server_started = threading.Event()
Georg Brandlf899dfa2008-05-18 09:12:20 +000076 self.thread = TestServerThread(self, self.request_handler)
77 self.thread.start()
Antoine Pitrou1ca8c192010-04-25 21:15:50 +000078 self.server_started.wait()
Georg Brandlf899dfa2008-05-18 09:12:20 +000079
80 def tearDown(self):
Georg Brandlf899dfa2008-05-18 09:12:20 +000081 self.thread.stop()
Nick Coghlan87c03b32009-10-17 15:23:08 +000082 os.environ.__exit__()
Antoine Pitrou85bd5872009-10-27 18:50:52 +000083 test_support.threading_cleanup(*self._threads)
Georg Brandlf899dfa2008-05-18 09:12:20 +000084
85 def request(self, uri, method='GET', body=None, headers={}):
86 self.connection = httplib.HTTPConnection('localhost', self.PORT)
87 self.connection.request(method, uri, body, headers)
88 return self.connection.getresponse()
89
Senthil Kumaranb643fc62010-09-30 06:40:56 +000090class BaseHTTPRequestHandlerTestCase(unittest.TestCase):
91 """Test the functionaility of the BaseHTTPServer focussing on
92 BaseHTTPRequestHandler.
93 """
94
95 HTTPResponseMatch = re.compile('HTTP/1.[0-9]+ 200 OK')
96
97 def setUp (self):
98 self.handler = SocketlessRequestHandler()
99
100 def send_typical_request(self, message):
101 input = StringIO(message)
102 output = StringIO()
103 self.handler.rfile = input
104 self.handler.wfile = output
105 self.handler.handle_one_request()
106 output.seek(0)
107 return output.readlines()
108
109 def verify_get_called(self):
110 self.assertTrue(self.handler.get_called)
111
112 def verify_expected_headers(self, headers):
113 for fieldName in 'Server: ', 'Date: ', 'Content-Type: ':
114 self.assertEqual(sum(h.startswith(fieldName) for h in headers), 1)
115
116 def verify_http_server_response(self, response):
117 match = self.HTTPResponseMatch.search(response)
118 self.assertTrue(match is not None)
119
120 def test_http_1_1(self):
121 result = self.send_typical_request('GET / HTTP/1.1\r\n\r\n')
122 self.verify_http_server_response(result[0])
123 self.verify_expected_headers(result[1:-1])
124 self.verify_get_called()
125 self.assertEqual(result[-1], '<html><body>Data</body></html>\r\n')
126
127 def test_http_1_0(self):
128 result = self.send_typical_request('GET / HTTP/1.0\r\n\r\n')
129 self.verify_http_server_response(result[0])
130 self.verify_expected_headers(result[1:-1])
131 self.verify_get_called()
132 self.assertEqual(result[-1], '<html><body>Data</body></html>\r\n')
133
134 def test_http_0_9(self):
135 result = self.send_typical_request('GET / HTTP/0.9\r\n\r\n')
136 self.assertEqual(len(result), 1)
137 self.assertEqual(result[0], '<html><body>Data</body></html>\r\n')
138 self.verify_get_called()
139
140 def test_with_continue_1_0(self):
141 result = self.send_typical_request('GET / HTTP/1.0\r\nExpect: 100-continue\r\n\r\n')
142 self.verify_http_server_response(result[0])
143 self.verify_expected_headers(result[1:-1])
144 self.verify_get_called()
145 self.assertEqual(result[-1], '<html><body>Data</body></html>\r\n')
146
Georg Brandlf899dfa2008-05-18 09:12:20 +0000147
148class BaseHTTPServerTestCase(BaseTestCase):
149 class request_handler(NoLogRequestHandler, BaseHTTPRequestHandler):
150 protocol_version = 'HTTP/1.1'
151 default_request_version = 'HTTP/1.1'
152
153 def do_TEST(self):
154 self.send_response(204)
155 self.send_header('Content-Type', 'text/html')
156 self.send_header('Connection', 'close')
157 self.end_headers()
158
159 def do_KEEP(self):
160 self.send_response(204)
161 self.send_header('Content-Type', 'text/html')
162 self.send_header('Connection', 'keep-alive')
163 self.end_headers()
164
165 def do_KEYERROR(self):
166 self.send_error(999)
167
168 def do_CUSTOM(self):
169 self.send_response(999)
170 self.send_header('Content-Type', 'text/html')
171 self.send_header('Connection', 'close')
172 self.end_headers()
173
174 def setUp(self):
175 BaseTestCase.setUp(self)
176 self.con = httplib.HTTPConnection('localhost', self.PORT)
177 self.con.connect()
178
179 def test_command(self):
180 self.con.request('GET', '/')
181 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000182 self.assertEqual(res.status, 501)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000183
184 def test_request_line_trimming(self):
185 self.con._http_vsn_str = 'HTTP/1.1\n'
186 self.con.putrequest('GET', '/')
187 self.con.endheaders()
188 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000189 self.assertEqual(res.status, 501)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000190
191 def test_version_bogus(self):
192 self.con._http_vsn_str = 'FUBAR'
193 self.con.putrequest('GET', '/')
194 self.con.endheaders()
195 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000196 self.assertEqual(res.status, 400)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000197
198 def test_version_digits(self):
199 self.con._http_vsn_str = 'HTTP/9.9.9'
200 self.con.putrequest('GET', '/')
201 self.con.endheaders()
202 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000203 self.assertEqual(res.status, 400)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000204
205 def test_version_none_get(self):
206 self.con._http_vsn_str = ''
207 self.con.putrequest('GET', '/')
208 self.con.endheaders()
209 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000210 self.assertEqual(res.status, 501)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000211
212 def test_version_none(self):
213 self.con._http_vsn_str = ''
214 self.con.putrequest('PUT', '/')
215 self.con.endheaders()
216 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000217 self.assertEqual(res.status, 400)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000218
219 def test_version_invalid(self):
220 self.con._http_vsn = 99
221 self.con._http_vsn_str = 'HTTP/9.9'
222 self.con.putrequest('GET', '/')
223 self.con.endheaders()
224 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000225 self.assertEqual(res.status, 505)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000226
227 def test_send_blank(self):
228 self.con._http_vsn_str = ''
229 self.con.putrequest('', '')
230 self.con.endheaders()
231 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000232 self.assertEqual(res.status, 400)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000233
234 def test_header_close(self):
235 self.con.putrequest('GET', '/')
236 self.con.putheader('Connection', 'close')
237 self.con.endheaders()
238 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000239 self.assertEqual(res.status, 501)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000240
241 def test_head_keep_alive(self):
242 self.con._http_vsn_str = 'HTTP/1.1'
243 self.con.putrequest('GET', '/')
244 self.con.putheader('Connection', 'keep-alive')
245 self.con.endheaders()
246 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000247 self.assertEqual(res.status, 501)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000248
249 def test_handler(self):
250 self.con.request('TEST', '/')
251 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000252 self.assertEqual(res.status, 204)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000253
254 def test_return_header_keep_alive(self):
255 self.con.request('KEEP', '/')
256 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000257 self.assertEqual(res.getheader('Connection'), 'keep-alive')
Georg Brandlf899dfa2008-05-18 09:12:20 +0000258 self.con.request('TEST', '/')
Brian Curtin55b62512010-10-31 00:36:01 +0000259 self.addCleanup(self.con.close)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000260
261 def test_internal_key_error(self):
262 self.con.request('KEYERROR', '/')
263 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000264 self.assertEqual(res.status, 999)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000265
266 def test_return_custom_status(self):
267 self.con.request('CUSTOM', '/')
268 res = self.con.getresponse()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000269 self.assertEqual(res.status, 999)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000270
271
272class SimpleHTTPServerTestCase(BaseTestCase):
273 class request_handler(NoLogRequestHandler, SimpleHTTPRequestHandler):
274 pass
275
276 def setUp(self):
277 BaseTestCase.setUp(self)
Georg Brandl7bb16532008-05-20 06:47:31 +0000278 self.cwd = os.getcwd()
279 basetempdir = tempfile.gettempdir()
280 os.chdir(basetempdir)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000281 self.data = 'We are the knights who say Ni!'
Georg Brandl7bb16532008-05-20 06:47:31 +0000282 self.tempdir = tempfile.mkdtemp(dir=basetempdir)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000283 self.tempdir_name = os.path.basename(self.tempdir)
Georg Brandl7bb16532008-05-20 06:47:31 +0000284 temp = open(os.path.join(self.tempdir, 'test'), 'wb')
285 temp.write(self.data)
286 temp.close()
Georg Brandlf899dfa2008-05-18 09:12:20 +0000287
288 def tearDown(self):
289 try:
Georg Brandl7bb16532008-05-20 06:47:31 +0000290 os.chdir(self.cwd)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000291 try:
292 shutil.rmtree(self.tempdir)
293 except:
294 pass
295 finally:
296 BaseTestCase.tearDown(self)
297
298 def check_status_and_reason(self, response, status, data=None):
299 body = response.read()
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000300 self.assertTrue(response)
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000301 self.assertEqual(response.status, status)
302 self.assertIsNotNone(response.reason)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000303 if data:
304 self.assertEqual(data, body)
305
306 def test_get(self):
307 #constructs the path relative to the root directory of the HTTPServer
Georg Brandl7bb16532008-05-20 06:47:31 +0000308 response = self.request(self.tempdir_name + '/test')
Georg Brandlf899dfa2008-05-18 09:12:20 +0000309 self.check_status_and_reason(response, 200, data=self.data)
310 response = self.request(self.tempdir_name + '/')
311 self.check_status_and_reason(response, 200)
312 response = self.request(self.tempdir_name)
313 self.check_status_and_reason(response, 301)
314 response = self.request('/ThisDoesNotExist')
315 self.check_status_and_reason(response, 404)
316 response = self.request('/' + 'ThisDoesNotExist' + '/')
317 self.check_status_and_reason(response, 404)
318 f = open(os.path.join(self.tempdir_name, 'index.html'), 'w')
319 response = self.request('/' + self.tempdir_name + '/')
320 self.check_status_and_reason(response, 200)
321 if os.name == 'posix':
322 # chmod won't work as expected on Windows platforms
323 os.chmod(self.tempdir, 0)
324 response = self.request(self.tempdir_name + '/')
325 self.check_status_and_reason(response, 404)
326 os.chmod(self.tempdir, 0755)
327
328 def test_head(self):
329 response = self.request(
Georg Brandl7bb16532008-05-20 06:47:31 +0000330 self.tempdir_name + '/test', method='HEAD')
Georg Brandlf899dfa2008-05-18 09:12:20 +0000331 self.check_status_and_reason(response, 200)
332 self.assertEqual(response.getheader('content-length'),
333 str(len(self.data)))
334 self.assertEqual(response.getheader('content-type'),
335 'application/octet-stream')
336
337 def test_invalid_requests(self):
338 response = self.request('/', method='FOO')
339 self.check_status_and_reason(response, 501)
340 # requests must be case sensitive,so this should fail too
341 response = self.request('/', method='get')
342 self.check_status_and_reason(response, 501)
343 response = self.request('/', method='GETs')
344 self.check_status_and_reason(response, 501)
345
346
347cgi_file1 = """\
348#!%s
349
350print "Content-type: text/html"
351print
352print "Hello World"
353"""
354
355cgi_file2 = """\
356#!%s
357import cgi
358
359print "Content-type: text/html"
360print
361
362form = cgi.FieldStorage()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000363print "%%s, %%s, %%s" %% (form.getfirst("spam"), form.getfirst("eggs"),
364 form.getfirst("bacon"))
Georg Brandlf899dfa2008-05-18 09:12:20 +0000365"""
366
367class CGIHTTPServerTestCase(BaseTestCase):
368 class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler):
369 pass
370
371 def setUp(self):
372 BaseTestCase.setUp(self)
373 self.parent_dir = tempfile.mkdtemp()
374 self.cgi_dir = os.path.join(self.parent_dir, 'cgi-bin')
375 os.mkdir(self.cgi_dir)
376
Florent Xicluna0805e6e2010-03-22 17:18:18 +0000377 # The shebang line should be pure ASCII: use symlink if possible.
378 # See issue #7668.
379 if hasattr(os, 'symlink'):
380 self.pythonexe = os.path.join(self.parent_dir, 'python')
381 os.symlink(sys.executable, self.pythonexe)
382 else:
383 self.pythonexe = sys.executable
384
Georg Brandlf899dfa2008-05-18 09:12:20 +0000385 self.file1_path = os.path.join(self.cgi_dir, 'file1.py')
386 with open(self.file1_path, 'w') as file1:
Florent Xicluna0805e6e2010-03-22 17:18:18 +0000387 file1.write(cgi_file1 % self.pythonexe)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000388 os.chmod(self.file1_path, 0777)
389
390 self.file2_path = os.path.join(self.cgi_dir, 'file2.py')
391 with open(self.file2_path, 'w') as file2:
Florent Xicluna0805e6e2010-03-22 17:18:18 +0000392 file2.write(cgi_file2 % self.pythonexe)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000393 os.chmod(self.file2_path, 0777)
394
Georg Brandl7bb16532008-05-20 06:47:31 +0000395 self.cwd = os.getcwd()
Georg Brandlf899dfa2008-05-18 09:12:20 +0000396 os.chdir(self.parent_dir)
397
398 def tearDown(self):
399 try:
Georg Brandl7bb16532008-05-20 06:47:31 +0000400 os.chdir(self.cwd)
Florent Xicluna0805e6e2010-03-22 17:18:18 +0000401 if self.pythonexe != sys.executable:
402 os.remove(self.pythonexe)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000403 os.remove(self.file1_path)
404 os.remove(self.file2_path)
405 os.rmdir(self.cgi_dir)
406 os.rmdir(self.parent_dir)
407 finally:
408 BaseTestCase.tearDown(self)
409
Gregory P. Smith923ba362009-04-06 06:33:26 +0000410 def test_url_collapse_path_split(self):
411 test_vectors = {
412 '': ('/', ''),
413 '..': IndexError,
414 '/.//..': IndexError,
415 '/': ('/', ''),
416 '//': ('/', ''),
417 '/\\': ('/', '\\'),
418 '/.//': ('/', ''),
419 'cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
420 '/cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
421 'a': ('/', 'a'),
422 '/a': ('/', 'a'),
423 '//a': ('/', 'a'),
424 './a': ('/', 'a'),
425 './C:/': ('/C:', ''),
426 '/a/b': ('/a', 'b'),
427 '/a/b/': ('/a/b', ''),
428 '/a/b/c/..': ('/a/b', ''),
429 '/a/b/c/../d': ('/a/b', 'd'),
430 '/a/b/c/../d/e/../f': ('/a/b/d', 'f'),
431 '/a/b/c/../d/e/../../f': ('/a/b', 'f'),
432 '/a/b/c/../d/e/.././././..//f': ('/a/b', 'f'),
433 '../a/b/c/../d/e/.././././..//f': IndexError,
434 '/a/b/c/../d/e/../../../f': ('/a', 'f'),
435 '/a/b/c/../d/e/../../../../f': ('/', 'f'),
436 '/a/b/c/../d/e/../../../../../f': IndexError,
437 '/a/b/c/../d/e/../../../../f/..': ('/', ''),
438 }
439 for path, expected in test_vectors.iteritems():
440 if isinstance(expected, type) and issubclass(expected, Exception):
441 self.assertRaises(expected,
442 CGIHTTPServer._url_collapse_path_split, path)
443 else:
444 actual = CGIHTTPServer._url_collapse_path_split(path)
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000445 self.assertEqual(expected, actual,
446 msg='path = %r\nGot: %r\nWanted: %r' %
447 (path, actual, expected))
Gregory P. Smith923ba362009-04-06 06:33:26 +0000448
Georg Brandlf899dfa2008-05-18 09:12:20 +0000449 def test_headers_and_content(self):
450 res = self.request('/cgi-bin/file1.py')
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000451 self.assertEqual(('Hello World\n', 'text/html', 200),
452 (res.read(), res.getheader('Content-type'), res.status))
Georg Brandlf899dfa2008-05-18 09:12:20 +0000453
454 def test_post(self):
455 params = urllib.urlencode({'spam' : 1, 'eggs' : 'python', 'bacon' : 123456})
456 headers = {'Content-type' : 'application/x-www-form-urlencoded'}
457 res = self.request('/cgi-bin/file2.py', 'POST', params, headers)
458
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000459 self.assertEqual(res.read(), '1, python, 123456\n')
Georg Brandlf899dfa2008-05-18 09:12:20 +0000460
461 def test_invaliduri(self):
462 res = self.request('/cgi-bin/invalid')
463 res.read()
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000464 self.assertEqual(res.status, 404)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000465
466 def test_authorization(self):
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000467 headers = {'Authorization' : 'Basic %s' %
468 base64.b64encode('username:pass')}
Georg Brandlf899dfa2008-05-18 09:12:20 +0000469 res = self.request('/cgi-bin/file1.py', 'GET', headers=headers)
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000470 self.assertEqual(('Hello World\n', 'text/html', 200),
471 (res.read(), res.getheader('Content-type'), res.status))
Georg Brandlf899dfa2008-05-18 09:12:20 +0000472
Gregory P. Smith923ba362009-04-06 06:33:26 +0000473 def test_no_leading_slash(self):
474 # http://bugs.python.org/issue2254
475 res = self.request('cgi-bin/file1.py')
Florent Xiclunabc27c6a2010-03-19 18:34:55 +0000476 self.assertEqual(('Hello World\n', 'text/html', 200),
Gregory P. Smith923ba362009-04-06 06:33:26 +0000477 (res.read(), res.getheader('Content-type'), res.status))
478
Senthil Kumarana9bd0cc2010-10-03 18:16:52 +0000479 def test_os_environ_is_not_altered(self):
480 signature = "Test CGI Server"
481 os.environ['SERVER_SOFTWARE'] = signature
482 res = self.request('/cgi-bin/file1.py')
483 self.assertEqual((b'Hello World\n', 'text/html', 200),
484 (res.read(), res.getheader('Content-type'), res.status))
485 self.assertEqual(os.environ['SERVER_SOFTWARE'], signature)
Georg Brandlf899dfa2008-05-18 09:12:20 +0000486
487def test_main(verbose=None):
488 try:
489 cwd = os.getcwd()
Senthil Kumaranb643fc62010-09-30 06:40:56 +0000490 test_support.run_unittest(BaseHTTPRequestHandlerTestCase,
491 BaseHTTPServerTestCase,
492 SimpleHTTPServerTestCase,
493 CGIHTTPServerTestCase
494 )
Georg Brandlf899dfa2008-05-18 09:12:20 +0000495 finally:
496 os.chdir(cwd)
497
498if __name__ == '__main__':
499 test_main()