Commit 6fcac0d6 authored by Georg Brandl's avatar Georg Brandl

Move test_SimpleHTTPServer into test_httpservers.

parent 65e5f80c
"""
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()
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment