summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/tests/test_util.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-07-08 14:27:12 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-07-08 14:27:12 (GMT)
commitce5fe83878c56ac17007e88148714ee523e64c94 (patch)
treed93797d6393b3836dc31f40a21f568889eb58de0 /Lib/packaging/tests/test_util.py
parentf8bebf8566bc31e4fe90c5c5f10bfa72f3b90c91 (diff)
downloadcpython-ce5fe83878c56ac17007e88148714ee523e64c94.zip
cpython-ce5fe83878c56ac17007e88148714ee523e64c94.tar.gz
cpython-ce5fe83878c56ac17007e88148714ee523e64c94.tar.bz2
Factor out code used by packaging commands for HTTP requests (#12169).
We now have one function to prepare multipart POST requests, and we use CRLF, as recommended by the HTTP spec (#10150). Initial patch by John Edmonds.
Diffstat (limited to 'Lib/packaging/tests/test_util.py')
-rw-r--r--Lib/packaging/tests/test_util.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/Lib/packaging/tests/test_util.py b/Lib/packaging/tests/test_util.py
index e3ccfd5..21ac4e2 100644
--- a/Lib/packaging/tests/test_util.py
+++ b/Lib/packaging/tests/test_util.py
@@ -19,7 +19,7 @@ from packaging.util import (
get_compiler_versions, _MAC_OS_X_LD_VERSION, byte_compile, find_packages,
spawn, get_pypirc_path, generate_pypirc, read_pypirc, resolve_name, iglob,
RICH_GLOB, egginfo_to_distinfo, is_setuptools, is_distutils, is_packaging,
- get_install_method, cfg_to_args)
+ get_install_method, cfg_to_args, encode_multipart)
PYPIRC = """\
@@ -54,6 +54,23 @@ username:tarek
password:xxx
"""
+EXPECTED_MULTIPART_OUTPUT = [
+ b'---x',
+ b'Content-Disposition: form-data; name="username"',
+ b'',
+ b'wok',
+ b'---x',
+ b'Content-Disposition: form-data; name="password"',
+ b'',
+ b'secret',
+ b'---x',
+ b'Content-Disposition: form-data; name="picture"; filename="wok.png"',
+ b'',
+ b'PNG89',
+ b'---x--',
+ b'',
+]
+
class FakePopen:
test_class = None
@@ -525,6 +542,13 @@ class UtilTestCase(support.EnvironRestorer,
self.assertEqual(args['scripts'], dist.scripts)
self.assertEqual(args['py_modules'], dist.py_modules)
+ def test_encode_multipart(self):
+ fields = [('username', 'wok'), ('password', 'secret')]
+ files = [('picture', 'wok.png', b'PNG89')]
+ content_type, body = encode_multipart(fields, files, b'-x')
+ self.assertEqual(b'multipart/form-data; boundary=-x', content_type)
+ self.assertEqual(EXPECTED_MULTIPART_OUTPUT, body.split(b'\r\n'))
+
class GlobTestCaseBase(support.TempdirManager,
support.LoggingCatcher,