Move test_SimpleHTTPServer into test_httpservers.

This commit is contained in:
Georg Brandl 2010-08-02 18:56:54 +00:00
parent 65e5f80c48
commit 6fcac0d6f6
2 changed files with 33 additions and 46 deletions

View File

@ -1,41 +0,0 @@
"""
These tests only check url parsing for now.
We don't want to require the 'network' resource.
"""
import os, unittest
from http.server import SimpleHTTPRequestHandler
from test import support
class SocketlessRequestHandler(SimpleHTTPRequestHandler):
def __init__(self):
pass
class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
""" Test url parsing """
def setUp (self):
self.translated = os.getcwd()
self.translated = os.path.join(self.translated, 'filename')
self.handler = SocketlessRequestHandler ()
def test_queryArguments (self):
path = self.handler.translate_path ('/filename')
self.assertEquals (path, self.translated)
path = self.handler.translate_path ('/filename?foo=bar')
self.assertEquals (path, self.translated)
path = self.handler.translate_path ('/filename?a=b&spam=eggs#zot')
self.assertEquals (path, self.translated)
def test_startWithDoubleSlash (self):
path = self.handler.translate_path ('//filename')
self.assertEquals (path, self.translated)
path = self.handler.translate_path ('//filename?foo=bar')
self.assertEquals (path, self.translated)
def test_main():
support.run_unittest(SimpleHTTPRequestHandlerTestCase)
if __name__ == "__main__":
test_main()

View File

@ -401,13 +401,41 @@ class CGIHTTPServerTestCase(BaseTestCase):
(res.read(), res.getheader('Content-type'), res.status))
class SocketlessRequestHandler(SimpleHTTPRequestHandler):
def __init__(self):
pass
class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
""" Test url parsing """
def setUp(self):
self.translated = os.getcwd()
self.translated = os.path.join(self.translated, 'filename')
self.handler = SocketlessRequestHandler()
def test_query_arguments(self):
path = self.handler.translate_path('/filename')
self.assertEqual(path, self.translated)
path = self.handler.translate_path('/filename?foo=bar')
self.assertEqual(path, self.translated)
path = self.handler.translate_path('/filename?a=b&spam=eggs#zot')
self.assertEqual(path, self.translated)
def test_start_with_double_slash(self):
path = self.handler.translate_path('//filename')
self.assertEqual(path, self.translated)
path = self.handler.translate_path('//filename?foo=bar')
self.assertEqual(path, self.translated)
def test_main(verbose=None):
cwd = os.getcwd()
try:
cwd = os.getcwd()
support.run_unittest(BaseHTTPServerTestCase,
SimpleHTTPServerTestCase,
CGIHTTPServerTestCase
)
support.run_unittest(
BaseHTTPServerTestCase,
SimpleHTTPServerTestCase,
CGIHTTPServerTestCase,
SimpleHTTPRequestHandlerTestCase,
)
finally:
os.chdir(cwd)