pip allows multiple --find-links to be passed. Added mocked tests too.

This commit is contained in:
Pedro Algarvio 2013-07-05 00:54:11 +01:00
parent 94575cbb63
commit edf66fd3fe
2 changed files with 45 additions and 5 deletions

View File

@ -319,11 +319,18 @@ def install(pkgs=None,
cmd.append('--timeout={0}'.format(timeout))
if find_links:
if not salt.utils.valid_url(find_links, VALID_PROTOS):
raise CommandExecutionError(
'{0!r} must be a valid URL'.format(find_links)
)
cmd.append('--find-links={0}'.format(find_links))
if isinstance(find_links, basestring):
if ',' in find_links:
find_links = [l.strip() for l in find_links.split(',')]
else:
find_links = [find_links]
for link in find_links:
if not salt.utils.valid_url(link, VALID_PROTOS):
raise CommandExecutionError(
'{0!r} must be a valid URL'.format(link)
)
cmd.append('--find-links={0}'.format(link))
if no_index and (index_url or extra_index_url):
raise CommandExecutionError(

View File

@ -135,6 +135,39 @@ class PipTestCase(TestCase):
cwd=None
)
def test_install_with_multiple_find_links(self):
find_links = [
'http://g.pypi.python.org',
'http://c.pypi.python.org',
'http://pypi.crate.io'
]
# Passing mirrors as a list
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
pip.install('pep8', find_links=find_links)
mock.assert_called_once_with(
'pip install pep8 '
'--find-links=http://g.pypi.python.org '
'--find-links=http://c.pypi.python.org '
'--find-links=http://pypi.crate.io',
runas=None,
cwd=None
)
# Passing mirrors as a comma separated list
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
pip.install('pep8', find_links=','.join(find_links))
mock.assert_called_once_with(
'pip install pep8 1'
'--find-links=http://g.pypi.python.org '
'--find-links=http://c.pypi.python.org '
'--find-links=http://pypi.crate.io',
runas=None,
cwd=None
)
@patch('salt.modules.pip._get_cached_requirements')
def test_failed_cached_requirements(self, get_cached_requirements):
get_cached_requirements.return_value = False