2010-01-23 20:33:32 -04:00
|
|
|
# -*- encoding: utf8 -*-
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
"""Tests for distutils.command.upload."""
|
2008-05-11 11:00:00 -03:00
|
|
|
import os
|
|
|
|
import unittest
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
from test.test_support import run_unittest
|
2008-05-11 11:00:00 -03:00
|
|
|
|
2009-06-15 20:30:13 -03:00
|
|
|
from distutils.command import upload as upload_mod
|
2008-05-11 11:00:00 -03:00
|
|
|
from distutils.command.upload import upload
|
|
|
|
from distutils.core import Distribution
|
|
|
|
|
|
|
|
from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
|
|
|
|
|
2009-12-20 19:23:34 -04:00
|
|
|
PYPIRC_LONG_PASSWORD = """\
|
|
|
|
[distutils]
|
|
|
|
|
|
|
|
index-servers =
|
|
|
|
server1
|
|
|
|
server2
|
|
|
|
|
|
|
|
[server1]
|
|
|
|
username:me
|
|
|
|
password:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
|
|
|
|
|
|
[server2]
|
|
|
|
username:meagain
|
|
|
|
password: secret
|
|
|
|
realm:acme
|
|
|
|
repository:http://another.pypi/
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2009-01-08 19:56:31 -04:00
|
|
|
PYPIRC_NOPASSWORD = """\
|
|
|
|
[distutils]
|
|
|
|
|
|
|
|
index-servers =
|
|
|
|
server1
|
|
|
|
|
|
|
|
[server1]
|
|
|
|
username:me
|
|
|
|
"""
|
|
|
|
|
2009-06-15 20:30:13 -03:00
|
|
|
class FakeOpen(object):
|
2009-03-31 17:53:55 -03:00
|
|
|
|
2009-06-15 20:30:13 -03:00
|
|
|
def __init__(self, url):
|
|
|
|
self.url = url
|
|
|
|
if not isinstance(url, str):
|
|
|
|
self.req = url
|
|
|
|
else:
|
|
|
|
self.req = None
|
|
|
|
self.msg = 'OK'
|
2009-03-31 17:53:55 -03:00
|
|
|
|
2009-06-15 20:30:13 -03:00
|
|
|
def getcode(self):
|
|
|
|
return 200
|
2009-03-31 17:53:55 -03:00
|
|
|
|
2009-01-08 19:56:31 -04:00
|
|
|
|
2008-05-11 11:00:00 -03:00
|
|
|
class uploadTestCase(PyPIRCCommandTestCase):
|
|
|
|
|
2009-03-31 17:53:55 -03:00
|
|
|
def setUp(self):
|
|
|
|
super(uploadTestCase, self).setUp()
|
2009-06-15 20:30:13 -03:00
|
|
|
self.old_open = upload_mod.urlopen
|
|
|
|
upload_mod.urlopen = self._urlopen
|
|
|
|
self.last_open = None
|
2009-03-31 17:53:55 -03:00
|
|
|
|
|
|
|
def tearDown(self):
|
2009-06-15 20:30:13 -03:00
|
|
|
upload_mod.urlopen = self.old_open
|
2009-03-31 17:53:55 -03:00
|
|
|
super(uploadTestCase, self).tearDown()
|
|
|
|
|
2009-06-15 20:30:13 -03:00
|
|
|
def _urlopen(self, url):
|
|
|
|
self.last_open = FakeOpen(url)
|
|
|
|
return self.last_open
|
|
|
|
|
2008-05-11 11:00:00 -03:00
|
|
|
def test_finalize_options(self):
|
|
|
|
|
|
|
|
# new format
|
2009-03-31 17:53:55 -03:00
|
|
|
self.write_file(self.rc, PYPIRC)
|
2008-05-11 11:00:00 -03:00
|
|
|
dist = Distribution()
|
|
|
|
cmd = upload(dist)
|
|
|
|
cmd.finalize_options()
|
|
|
|
for attr, waited in (('username', 'me'), ('password', 'secret'),
|
|
|
|
('realm', 'pypi'),
|
|
|
|
('repository', 'http://pypi.python.org/pypi')):
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(getattr(cmd, attr), waited)
|
2008-05-11 11:00:00 -03:00
|
|
|
|
2009-01-08 19:56:31 -04:00
|
|
|
def test_saved_password(self):
|
|
|
|
# file with no password
|
2009-03-31 17:53:55 -03:00
|
|
|
self.write_file(self.rc, PYPIRC_NOPASSWORD)
|
2009-01-08 19:56:31 -04:00
|
|
|
|
|
|
|
# make sure it passes
|
|
|
|
dist = Distribution()
|
|
|
|
cmd = upload(dist)
|
|
|
|
cmd.finalize_options()
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(cmd.password, None)
|
2009-01-08 19:56:31 -04:00
|
|
|
|
|
|
|
# make sure we get it as well, if another command
|
|
|
|
# initialized it at the dist level
|
|
|
|
dist.password = 'xxx'
|
|
|
|
cmd = upload(dist)
|
|
|
|
cmd.finalize_options()
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(cmd.password, 'xxx')
|
2008-05-11 11:00:00 -03:00
|
|
|
|
2009-03-31 17:53:55 -03:00
|
|
|
def test_upload(self):
|
|
|
|
tmp = self.mkdtemp()
|
|
|
|
path = os.path.join(tmp, 'xxx')
|
|
|
|
self.write_file(path)
|
|
|
|
command, pyversion, filename = 'xxx', '2.6', path
|
|
|
|
dist_files = [(command, pyversion, filename)]
|
2009-12-20 19:23:34 -04:00
|
|
|
self.write_file(self.rc, PYPIRC_LONG_PASSWORD)
|
2009-03-31 17:53:55 -03:00
|
|
|
|
|
|
|
# lets run it
|
2010-01-23 20:33:32 -04:00
|
|
|
pkg_dir, dist = self.create_dist(dist_files=dist_files, author=u'dédé')
|
2009-03-31 17:53:55 -03:00
|
|
|
cmd = upload(dist)
|
|
|
|
cmd.ensure_finalized()
|
|
|
|
cmd.run()
|
|
|
|
|
|
|
|
# what did we send ?
|
2010-01-23 20:33:32 -04:00
|
|
|
self.assertIn('dédé', self.last_open.req.data)
|
2009-06-15 20:30:13 -03:00
|
|
|
headers = dict(self.last_open.req.headers)
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(headers['Content-length'], '2085')
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(headers['Content-type'].startswith('multipart/form-data'))
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(self.last_open.req.get_method(), 'POST')
|
|
|
|
self.assertEqual(self.last_open.req.get_full_url(),
|
|
|
|
'http://pypi.python.org/pypi')
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue('xxx' in self.last_open.req.data)
|
2009-12-20 19:23:34 -04:00
|
|
|
auth = self.last_open.req.headers['Authorization']
|
|
|
|
self.assertFalse('\n' in auth)
|
2009-03-31 17:53:55 -03:00
|
|
|
|
2008-05-11 11:00:00 -03:00
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(uploadTestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
run_unittest(test_suite())
|