cpython: 0e19f421dc9e (original) (raw)
--- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -284,6 +284,7 @@ class SimpleHTTPServerTestCase(BaseTestC self.data = b'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[](#l1.7) with open(os.path.join(self.tempdir, 'test'), 'wb') as temp:[](#l1.8) temp.write(self.data)[](#l1.9)
@@ -330,7 +331,7 @@ class SimpleHTTPServerTestCase(BaseTestC filename = os.fsdecode(support.TESTFN_UNDECODABLE) + '.txt' with open(os.path.join(self.tempdir, filename), 'wb') as f: f.write(support.TESTFN_UNDECODABLE)
response = self.request(self.tempdir_name + '/')[](#l1.15)
response = self.request(self.base_url + '/')[](#l1.16) if sys.platform == 'darwin':[](#l1.17) # On Mac OS the HFS+ filesystem replaces bytes that aren't valid[](#l1.18) # UTF-8 into a percent-encoded value.[](#l1.19)
@@ -344,27 +345,27 @@ class SimpleHTTPServerTestCase(BaseTestC .encode(enc, 'surrogateescape'), body) self.assertIn(('>%s<' % html.escape(filename)) .encode(enc, 'surrogateescape'), body)
response = self.request(self.tempdir_name + '/' + quotedname)[](#l1.24)
response = self.request(self.base_url + '/' + quotedname)[](#l1.25) self.check_status_and_reason(response, HTTPStatus.OK,[](#l1.26) data=support.TESTFN_UNDECODABLE)[](#l1.27)
def test_get(self): #constructs the path relative to the root directory of the HTTPServer
response = self.request(self.tempdir_name + '/test')[](#l1.31)
response = self.request(self.base_url + '/test')[](#l1.32) self.check_status_and_reason(response, HTTPStatus.OK, data=self.data)[](#l1.33) # check for trailing "/" which should return 404. See Issue17324[](#l1.34)
response = self.request(self.tempdir_name + '/test/')[](#l1.35)
response = self.request(self.base_url + '/test/')[](#l1.36) self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)[](#l1.37)
response = self.request(self.tempdir_name + '/')[](#l1.38)
response = self.request(self.base_url + '/')[](#l1.39) self.check_status_and_reason(response, HTTPStatus.OK)[](#l1.40)
response = self.request(self.tempdir_name)[](#l1.41)
response = self.request(self.base_url)[](#l1.42) self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY)[](#l1.43)
response = self.request(self.tempdir_name + '/?hi=2')[](#l1.44)
response = self.request(self.base_url + '/?hi=2')[](#l1.45) self.check_status_and_reason(response, HTTPStatus.OK)[](#l1.46)
response = self.request(self.tempdir_name + '?hi=1')[](#l1.47)
response = self.request(self.base_url + '?hi=1')[](#l1.48) self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY)[](#l1.49) self.assertEqual(response.getheader("Location"),[](#l1.50)
self.tempdir_name + "/?hi=1")[](#l1.51)
self.base_url + "/?hi=1")[](#l1.52) response = self.request('/ThisDoesNotExist')[](#l1.53) self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)[](#l1.54) response = self.request('/' + 'ThisDoesNotExist' + '/')[](#l1.55)
@@ -373,7 +374,7 @@ class SimpleHTTPServerTestCase(BaseTestC data = b"Dummy index file\r\n" with open(os.path.join(self.tempdir_name, 'index.html'), 'wb') as f: f.write(data)
response = self.request('/' + self.tempdir_name + '/')[](#l1.60)
response = self.request(self.base_url + '/')[](#l1.61) self.check_status_and_reason(response, HTTPStatus.OK, data)[](#l1.62)
# chmod() doesn't work as expected on Windows, and filesystem @@ -381,14 +382,14 @@ class SimpleHTTPServerTestCase(BaseTestC if os.name == 'posix' and os.geteuid() != 0: os.chmod(self.tempdir, 0) try:
response = self.request(self.tempdir_name + '/')[](#l1.69)
response = self.request(self.base_url + '/')[](#l1.70) self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)[](#l1.71) finally:[](#l1.72) os.chmod(self.tempdir, 0o755)[](#l1.73)
def test_head(self): response = self.request(
self.tempdir_name + '/test', method='HEAD')[](#l1.77)
self.base_url + '/test', method='HEAD')[](#l1.78) self.check_status_and_reason(response, HTTPStatus.OK)[](#l1.79) self.assertEqual(response.getheader('content-length'),[](#l1.80) str(len(self.data)))[](#l1.81)
@@ -404,6 +405,22 @@ class SimpleHTTPServerTestCase(BaseTestC response = self.request('/', method='GETs') self.check_status_and_reason(response, HTTPStatus.NOT_IMPLEMENTED)
- def test_path_without_leading_slash(self):
response = self.request(self.tempdir_name + '/test')[](#l1.87)
self.check_status_and_reason(response, HTTPStatus.OK, data=self.data)[](#l1.88)
response = self.request(self.tempdir_name + '/test/')[](#l1.89)
self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)[](#l1.90)
response = self.request(self.tempdir_name + '/')[](#l1.91)
self.check_status_and_reason(response, HTTPStatus.OK)[](#l1.92)
response = self.request(self.tempdir_name)[](#l1.93)
self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY)[](#l1.94)
response = self.request(self.tempdir_name + '/?hi=2')[](#l1.95)
self.check_status_and_reason(response, HTTPStatus.OK)[](#l1.96)
response = self.request(self.tempdir_name + '?hi=1')[](#l1.97)
self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY)[](#l1.98)
self.assertEqual(response.getheader("Location"),[](#l1.99)
self.tempdir_name + "/?hi=1")[](#l1.100)