summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-04-09 04:56:10 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-04-09 04:56:10 (GMT)
commitaf58c857a8b699236aed6d70a29189c4cf4383f4 (patch)
tree9f0948c7b3c613fab9cc32f99568e419cacc743b /Lib
parent7784888cced3cc75eddf8069d5b4981357d19c4c (diff)
downloadcpython-af58c857a8b699236aed6d70a29189c4cf4383f4.zip
cpython-af58c857a8b699236aed6d70a29189c4cf4383f4.tar.gz
cpython-af58c857a8b699236aed6d70a29189c4cf4383f4.tar.bz2
Issue #26609: Fix HTTP server tests to request an absolute URL path
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_httpservers.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index c84f48f..ab74e5b 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -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