]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/tests/test_upload.py
51c2f05eb0834048bd8ada9e5cc49371435a2fa7
1 # -*- encoding: utf8 -*-
2 """Tests for distutils.command.upload."""
5 from test
.test_support
import run_unittest
7 from distutils
.command
import upload
as upload_mod
8 from distutils
.command
.upload
import upload
9 from distutils
.core
import Distribution
11 from distutils
.tests
.test_config
import PYPIRC
, PyPIRCCommandTestCase
13 PYPIRC_LONG_PASSWORD
= """\
22 password:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
28 repository:http://another.pypi/
32 PYPIRC_NOPASSWORD
= """\
42 class FakeOpen(object):
44 def __init__(self
, url
):
46 if not isinstance(url
, str):
56 class uploadTestCase(PyPIRCCommandTestCase
):
59 super(uploadTestCase
, self
).setUp()
60 self
.old_open
= upload_mod
.urlopen
61 upload_mod
.urlopen
= self
._urlopen
65 upload_mod
.urlopen
= self
.old_open
66 super(uploadTestCase
, self
).tearDown()
68 def _urlopen(self
, url
):
69 self
.last_open
= FakeOpen(url
)
72 def test_finalize_options(self
):
75 self
.write_file(self
.rc
, PYPIRC
)
78 cmd
.finalize_options()
79 for attr
, waited
in (('username', 'me'), ('password', 'secret'),
81 ('repository', 'http://pypi.python.org/pypi')):
82 self
.assertEqual(getattr(cmd
, attr
), waited
)
84 def test_saved_password(self
):
85 # file with no password
86 self
.write_file(self
.rc
, PYPIRC_NOPASSWORD
)
91 cmd
.finalize_options()
92 self
.assertEqual(cmd
.password
, None)
94 # make sure we get it as well, if another command
95 # initialized it at the dist level
98 cmd
.finalize_options()
99 self
.assertEqual(cmd
.password
, 'xxx')
101 def test_upload(self
):
103 path
= os
.path
.join(tmp
, 'xxx')
104 self
.write_file(path
)
105 command
, pyversion
, filename
= 'xxx', '2.6', path
106 dist_files
= [(command
, pyversion
, filename
)]
107 self
.write_file(self
.rc
, PYPIRC_LONG_PASSWORD
)
110 pkg_dir
, dist
= self
.create_dist(dist_files
=dist_files
, author
=u
'dédé')
112 cmd
.ensure_finalized()
116 self
.assertIn('dédé', self
.last_open
.req
.data
)
117 headers
= dict(self
.last_open
.req
.headers
)
118 self
.assertEqual(headers
['Content-length'], '2085')
119 self
.assertTrue(headers
['Content-type'].startswith('multipart/form-data'))
120 self
.assertEqual(self
.last_open
.req
.get_method(), 'POST')
121 self
.assertEqual(self
.last_open
.req
.get_full_url(),
122 'http://pypi.python.org/pypi')
123 self
.assertTrue('xxx' in self
.last_open
.req
.data
)
124 auth
= self
.last_open
.req
.headers
['Authorization']
125 self
.assertFalse('\n' in auth
)
128 return unittest
.makeSuite(uploadTestCase
)
130 if __name__
== "__main__":
131 run_unittest(test_suite())