summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/tests
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
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')
-rw-r--r--Lib/packaging/tests/test_command_register.py10
-rw-r--r--Lib/packaging/tests/test_command_upload_docs.py27
-rw-r--r--Lib/packaging/tests/test_util.py26
3 files changed, 31 insertions, 32 deletions
diff --git a/Lib/packaging/tests/test_command_register.py b/Lib/packaging/tests/test_command_register.py
index 7aa487a..183f84e 100644
--- a/Lib/packaging/tests/test_command_register.py
+++ b/Lib/packaging/tests/test_command_register.py
@@ -152,7 +152,7 @@ class RegisterTestCase(support.TempdirManager,
req1 = dict(self.conn.reqs[0].headers)
req2 = dict(self.conn.reqs[1].headers)
self.assertEqual(req2['Content-length'], req1['Content-length'])
- self.assertIn('xxx', self.conn.reqs[1].data)
+ self.assertIn(b'xxx', self.conn.reqs[1].data)
def test_password_not_in_file(self):
@@ -180,8 +180,8 @@ class RegisterTestCase(support.TempdirManager,
self.assertEqual(len(self.conn.reqs), 1)
req = self.conn.reqs[0]
headers = dict(req.headers)
- self.assertEqual(headers['Content-length'], '608')
- self.assertIn('tarek', req.data)
+ self.assertEqual(headers['Content-length'], '628')
+ self.assertIn(b'tarek', req.data)
def test_password_reset(self):
# this test runs choice 3
@@ -195,8 +195,8 @@ class RegisterTestCase(support.TempdirManager,
self.assertEqual(len(self.conn.reqs), 1)
req = self.conn.reqs[0]
headers = dict(req.headers)
- self.assertEqual(headers['Content-length'], '290')
- self.assertIn('tarek', req.data)
+ self.assertEqual(headers['Content-length'], '298')
+ self.assertIn(b'tarek', req.data)
@unittest.skipUnless(DOCUTILS_SUPPORT, 'needs docutils')
def test_strict(self):
diff --git a/Lib/packaging/tests/test_command_upload_docs.py b/Lib/packaging/tests/test_command_upload_docs.py
index 9876d18..4070279 100644
--- a/Lib/packaging/tests/test_command_upload_docs.py
+++ b/Lib/packaging/tests/test_command_upload_docs.py
@@ -9,8 +9,7 @@ except ImportError:
_ssl = None
from packaging.command import upload_docs as upload_docs_mod
-from packaging.command.upload_docs import (upload_docs, zip_dir,
- encode_multipart)
+from packaging.command.upload_docs import upload_docs, zip_dir
from packaging.dist import Distribution
from packaging.errors import PackagingFileError, PackagingOptionError
@@ -23,23 +22,6 @@ except ImportError:
PyPIServerTestCase = object
-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'',
-]
-
PYPIRC = """\
[distutils]
index-servers = server1
@@ -108,13 +90,6 @@ class UploadDocsTestCase(support.TempdirManager,
zip_f = zipfile.ZipFile(compressed)
self.assertEqual(zip_f.namelist(), ['index.html', 'docs/index.html'])
- 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'))
-
def prepare_command(self):
self.cmd.upload_dir = self.prepare_sample_dir()
self.cmd.ensure_finalized()
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,