Issue #26609: Fix HTTP server tests to request an absolute URL path
This commit is contained in:
parent
7784888cce
commit
af58c857a8
|
@ -288,6 +288,7 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
|||
self.data = 'We are the knights who say Ni!'
|
||||
self.tempdir = tempfile.mkdtemp(dir=basetempdir)
|
||||
self.tempdir_name = os.path.basename(self.tempdir)
|
||||
self.base_url = '/' + self.tempdir_name
|
||||
temp = open(os.path.join(self.tempdir, 'test'), 'wb')
|
||||
temp.write(self.data)
|
||||
temp.close()
|
||||
|
@ -312,39 +313,39 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
|||
|
||||
def test_get(self):
|
||||
#constructs the path relative to the root directory of the HTTPServer
|
||||
response = self.request(self.tempdir_name + '/test')
|
||||
response = self.request(self.base_url + '/test')
|
||||
self.check_status_and_reason(response, 200, data=self.data)
|
||||
# check for trailing "/" which should return 404. See Issue17324
|
||||
response = self.request(self.tempdir_name + '/test/')
|
||||
response = self.request(self.base_url + '/test/')
|
||||
self.check_status_and_reason(response, 404)
|
||||
response = self.request(self.tempdir_name + '/')
|
||||
response = self.request(self.base_url + '/')
|
||||
self.check_status_and_reason(response, 200)
|
||||
response = self.request(self.tempdir_name)
|
||||
response = self.request(self.base_url)
|
||||
self.check_status_and_reason(response, 301)
|
||||
response = self.request(self.tempdir_name + '/?hi=2')
|
||||
response = self.request(self.base_url + '/?hi=2')
|
||||
self.check_status_and_reason(response, 200)
|
||||
response = self.request(self.tempdir_name + '?hi=1')
|
||||
response = self.request(self.base_url + '?hi=1')
|
||||
self.check_status_and_reason(response, 301)
|
||||
self.assertEqual(response.getheader("Location"),
|
||||
self.tempdir_name + "/?hi=1")
|
||||
self.base_url + "/?hi=1")
|
||||
response = self.request('/ThisDoesNotExist')
|
||||
self.check_status_and_reason(response, 404)
|
||||
response = self.request('/' + 'ThisDoesNotExist' + '/')
|
||||
self.check_status_and_reason(response, 404)
|
||||
with open(os.path.join(self.tempdir_name, 'index.html'), 'w') as fp:
|
||||
response = self.request('/' + self.tempdir_name + '/')
|
||||
response = self.request(self.base_url + '/')
|
||||
self.check_status_and_reason(response, 200)
|
||||
# chmod() doesn't work as expected on Windows, and filesystem
|
||||
# permissions are ignored by root on Unix.
|
||||
if os.name == 'posix' and os.geteuid() != 0:
|
||||
os.chmod(self.tempdir, 0)
|
||||
response = self.request(self.tempdir_name + '/')
|
||||
response = self.request(self.base_url + '/')
|
||||
self.check_status_and_reason(response, 404)
|
||||
os.chmod(self.tempdir, 0755)
|
||||
|
||||
def test_head(self):
|
||||
response = self.request(
|
||||
self.tempdir_name + '/test', method='HEAD')
|
||||
self.base_url + '/test', method='HEAD')
|
||||
self.check_status_and_reason(response, 200)
|
||||
self.assertEqual(response.getheader('content-length'),
|
||||
str(len(self.data)))
|
||||
|
@ -360,6 +361,22 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
|||
response = self.request('/', method='GETs')
|
||||
self.check_status_and_reason(response, 501)
|
||||
|
||||
def test_path_without_leading_slash(self):
|
||||
response = self.request(self.tempdir_name + '/test')
|
||||
self.check_status_and_reason(response, HTTPStatus.OK, data=self.data)
|
||||
response = self.request(self.tempdir_name + '/test/')
|
||||
self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)
|
||||
response = self.request(self.tempdir_name + '/')
|
||||
self.check_status_and_reason(response, HTTPStatus.OK)
|
||||
response = self.request(self.tempdir_name)
|
||||
self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY)
|
||||
response = self.request(self.tempdir_name + '/?hi=2')
|
||||
self.check_status_and_reason(response, HTTPStatus.OK)
|
||||
response = self.request(self.tempdir_name + '?hi=1')
|
||||
self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY)
|
||||
self.assertEqual(response.getheader("Location"),
|
||||
self.tempdir_name + "/?hi=1")
|
||||
|
||||
|
||||
cgi_file1 = """\
|
||||
#!%s
|
||||
|
|
Loading…
Reference in New Issue