2008-05-11 11:00:00 -03:00
|
|
|
"""Tests for distutils.command.upload."""
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from distutils.command.upload import upload
|
|
|
|
from distutils.core import Distribution
|
|
|
|
|
|
|
|
from distutils.tests import support
|
|
|
|
from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
|
|
|
|
|
2009-01-08 19:56:31 -04:00
|
|
|
PYPIRC_NOPASSWORD = """\
|
|
|
|
[distutils]
|
|
|
|
|
|
|
|
index-servers =
|
|
|
|
server1
|
|
|
|
|
|
|
|
[server1]
|
|
|
|
username:me
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2008-05-11 11:00:00 -03:00
|
|
|
class uploadTestCase(PyPIRCCommandTestCase):
|
|
|
|
|
|
|
|
def test_finalize_options(self):
|
|
|
|
|
|
|
|
# new format
|
|
|
|
f = open(self.rc, 'w')
|
|
|
|
f.write(PYPIRC)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
dist = Distribution()
|
|
|
|
cmd = upload(dist)
|
|
|
|
cmd.finalize_options()
|
|
|
|
for attr, waited in (('username', 'me'), ('password', 'secret'),
|
|
|
|
('realm', 'pypi'),
|
|
|
|
('repository', 'http://pypi.python.org/pypi')):
|
|
|
|
self.assertEquals(getattr(cmd, attr), waited)
|
|
|
|
|
2009-01-08 19:56:31 -04:00
|
|
|
def test_saved_password(self):
|
|
|
|
# file with no password
|
|
|
|
f = open(self.rc, 'w')
|
|
|
|
f.write(PYPIRC_NOPASSWORD)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
# make sure it passes
|
|
|
|
dist = Distribution()
|
|
|
|
cmd = upload(dist)
|
|
|
|
cmd.finalize_options()
|
|
|
|
self.assertEquals(cmd.password, None)
|
|
|
|
|
|
|
|
# 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()
|
|
|
|
self.assertEquals(cmd.password, 'xxx')
|
2008-05-11 11:00:00 -03:00
|
|
|
|
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(uploadTestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main(defaultTest="test_suite")
|