[Python-checkins] cpython (2.7): Issue #26609: Fix HTTP server tests to request an absolute URL path

martin.panter python-checkins at python.org
Sat Apr 9 09:44:36 EDT 2016


https://hg.python.org/cpython/rev/2691f81a89a7
changeset:   100892:2691f81a89a7
branch:      2.7
parent:      100885:43a6e7104b78
user:        Martin Panter <vadmium+py at gmail.com>
date:        Sat Apr 09 04:56:10 2016 +0000
summary:
  Issue #26609: Fix HTTP server tests to request an absolute URL path

files:
  Lib/test/test_httpservers.py |  37 +++++++++++++++++------
  1 files changed, 27 insertions(+), 10 deletions(-)


diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -288,6 +288,7 @@
         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 @@
 
     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 @@
         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

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list