diff options
author | Tarek Ziadé <ziade.tarek@gmail.com> | 2009-01-09 00:15:45 (GMT) |
---|---|---|
committer | Tarek Ziadé <ziade.tarek@gmail.com> | 2009-01-09 00:15:45 (GMT) |
commit | 13f7c3b6cad28ee57390c7650e1bf644f0b3943f (patch) | |
tree | f74d6310917922466929bc468f2d9ee64300d2be /Lib/distutils/tests | |
parent | bcd5cbe01ef4306a82f85d0500f9a9f04113f804 (diff) | |
download | cpython-13f7c3b6cad28ee57390c7650e1bf644f0b3943f.zip cpython-13f7c3b6cad28ee57390c7650e1bf644f0b3943f.tar.gz cpython-13f7c3b6cad28ee57390c7650e1bf644f0b3943f.tar.bz2 |
Merged revisions 68415 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68415 | tarek.ziade | 2009-01-09 00:56:31 +0100 (Fri, 09 Jan 2009) | 1 line
fixed #4394 make the storage of the password optional in .pypirc
........
Diffstat (limited to 'Lib/distutils/tests')
-rw-r--r-- | Lib/distutils/tests/test_register.py | 91 | ||||
-rw-r--r-- | Lib/distutils/tests/test_upload.py | 29 |
2 files changed, 95 insertions, 25 deletions
diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py index 021b3ea..8826e90 100644 --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -2,6 +2,7 @@ import sys import os import unittest +import getpass from distutils.command.register import register from distutils.core import Distribution @@ -9,7 +10,27 @@ from distutils.core import Distribution from distutils.tests import support from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase -class RawInputs(object): +PYPIRC_NOPASSWORD = """\ +[distutils] + +index-servers = + server1 + +[server1] +username:me +""" + +WANTED_PYPIRC = """\ +[distutils] +index-servers = + pypi + +[pypi] +username:tarek +password:password +""" + +class Inputs(object): """Fakes user inputs.""" def __init__(self, *answers): self.answers = answers @@ -21,18 +42,33 @@ class RawInputs(object): finally: self.index += 1 -WANTED_PYPIRC = """\ -[distutils] -index-servers = - pypi +class FakeServer(object): + """Fakes a PyPI server""" + def __init__(self): + self.calls = [] -[pypi] -username:tarek -password:xxx -""" + def __call__(self, *args): + # we want to compare them, so let's store + # something comparable + els = list(args[0].items()) + els.sort() + self.calls.append(tuple(els)) + return 200, 'OK' class registerTestCase(PyPIRCCommandTestCase): + def setUp(self): + PyPIRCCommandTestCase.setUp(self) + # patching the password prompt + self._old_getpass = getpass.getpass + def _getpass(prompt): + return 'password' + getpass.getpass = _getpass + + def tearDown(self): + getpass.getpass = self._old_getpass + PyPIRCCommandTestCase.tearDown(self) + def test_create_pypirc(self): # this test makes sure a .pypirc file # is created when requested. @@ -50,30 +86,17 @@ class registerTestCase(PyPIRCCommandTestCase): # we shouldn't have a .pypirc file yet self.assert_(not os.path.exists(self.rc)) - # patching raw_input and getpass.getpass + # patching input and getpass.getpass # so register gets happy # # Here's what we are faking : # use your existing login (choice 1.) # Username : 'tarek' - # Password : 'xxx' + # Password : 'password' # Save your login (y/N)? : 'y' - inputs = RawInputs('1', 'tarek', 'y') + inputs = Inputs('1', 'tarek', 'y') from distutils.command import register as register_module register_module.input = inputs.__call__ - def _getpass(prompt): - return 'xxx' - register_module.getpass.getpass = _getpass - class FakeServer(object): - def __init__(self): - self.calls = [] - - def __call__(self, *args): - # we want to compare them, so let's store - # something comparable - els = sorted(args[0].items()) - self.calls.append(tuple(els)) - return 200, 'OK' cmd.post_to_server = pypi_server = FakeServer() @@ -101,6 +124,24 @@ class registerTestCase(PyPIRCCommandTestCase): self.assert_(len(pypi_server.calls), 2) self.assert_(pypi_server.calls[0], pypi_server.calls[1]) + def test_password_not_in_file(self): + + f = open(self.rc, 'w') + f.write(PYPIRC_NOPASSWORD) + f.close() + + dist = Distribution() + cmd = register(dist) + cmd.post_to_server = FakeServer() + + cmd._set_config() + cmd.finalize_options() + cmd.send_metadata() + + # dist.password should be set + # therefore used afterwards by other commands + self.assertEquals(dist.password, 'password') + def test_suite(): return unittest.makeSuite(registerTestCase) diff --git a/Lib/distutils/tests/test_upload.py b/Lib/distutils/tests/test_upload.py index b05ab1f..3f8ca6d 100644 --- a/Lib/distutils/tests/test_upload.py +++ b/Lib/distutils/tests/test_upload.py @@ -9,6 +9,17 @@ from distutils.core import Distribution from distutils.tests import support from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase +PYPIRC_NOPASSWORD = """\ +[distutils] + +index-servers = + server1 + +[server1] +username:me +""" + + class uploadTestCase(PyPIRCCommandTestCase): def test_finalize_options(self): @@ -26,6 +37,24 @@ class uploadTestCase(PyPIRCCommandTestCase): ('repository', 'http://pypi.python.org/pypi')): self.assertEquals(getattr(cmd, attr), waited) + 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') def test_suite(): return unittest.makeSuite(uploadTestCase) |