summaryrefslogtreecommitdiff
path: root/Lib/test/test_urllib2_localnet.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-02-07 12:15:22 -0800
committerGitHub <noreply@github.com>2022-02-07 12:15:22 -0800
commit9539400390494f4930c245b3f98453592f4a1a8c (patch)
tree6818f21d40020edfe495aeed8e4ba864a5110a1c /Lib/test/test_urllib2_localnet.py
parent9c45390208df712126c59f7c2b6f8d2b4e19ccf7 (diff)
downloadcpython-git-9539400390494f4930c245b3f98453592f4a1a8c.tar.gz
[3.10] bpo-46648: Rewrite test_urllib2.test_issue16464() with a local HTTP server (GH-31186) (GH-31189)
Re-enable test_issue16464() of test_urllib2, move it to urllib2_localnet and use the local HTTP server rather than an external HTTP server. (cherry picked from commit 8e98175a03fe03d62822d96007a74e5273013764) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Diffstat (limited to 'Lib/test/test_urllib2_localnet.py')
-rw-r--r--Lib/test/test_urllib2_localnet.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py
index 0b2d07ce61..1b2baf2f36 100644
--- a/Lib/test/test_urllib2_localnet.py
+++ b/Lib/test/test_urllib2_localnet.py
@@ -660,6 +660,24 @@ class TestUrlopen(unittest.TestCase):
(index, len(lines[index]), len(line)))
self.assertEqual(index + 1, len(lines))
+ def test_issue16464(self):
+ # See https://bugs.python.org/issue16464
+ # and https://bugs.python.org/issue46648
+ handler = self.start_server([
+ (200, [], b'any'),
+ (200, [], b'any'),
+ ])
+ opener = urllib.request.build_opener()
+ request = urllib.request.Request("http://localhost:%s" % handler.port)
+ self.assertEqual(None, request.data)
+
+ opener.open(request, "1".encode("us-ascii"))
+ self.assertEqual(b"1", request.data)
+ self.assertEqual("1", request.get_header("Content-length"))
+
+ opener.open(request, "1234567890".encode("us-ascii"))
+ self.assertEqual(b"1234567890", request.data)
+ self.assertEqual("10", request.get_header("Content-length"))
def setUpModule():
thread_info = threading_helper.threading_setup()