2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2013-07-27 12:06:36 +00:00
|
|
|
# Import python libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import
|
2015-08-25 04:54:09 +00:00
|
|
|
import os
|
2013-07-27 12:06:36 +00:00
|
|
|
|
2013-06-25 08:24:05 +00:00
|
|
|
# Import Salt Testing libs
|
2013-06-27 13:01:45 +00:00
|
|
|
from salttesting import skipIf, TestCase
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
2013-08-26 09:49:20 +00:00
|
|
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
2013-06-27 13:01:45 +00:00
|
|
|
ensure_in_syspath('../../')
|
2013-06-25 08:24:05 +00:00
|
|
|
|
2013-06-27 13:01:45 +00:00
|
|
|
# Import salt libs
|
|
|
|
from salt.modules import pip
|
2013-07-04 23:57:47 +00:00
|
|
|
from salt.exceptions import CommandExecutionError
|
2013-06-25 08:24:05 +00:00
|
|
|
|
2013-06-27 13:01:45 +00:00
|
|
|
pip.__salt__ = {'cmd.which_bin': lambda _: 'pip'}
|
2013-06-25 08:24:05 +00:00
|
|
|
|
2013-04-03 21:41:17 +00:00
|
|
|
|
2013-08-26 09:49:20 +00:00
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2013-04-03 21:41:17 +00:00
|
|
|
class PipTestCase(TestCase):
|
2013-05-07 09:12:43 +00:00
|
|
|
|
2013-04-03 21:41:17 +00:00
|
|
|
def test_fix4361(self):
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
2013-06-25 08:24:05 +00:00
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2013-06-27 13:01:45 +00:00
|
|
|
pip.install(requirements='requirements.txt')
|
2015-08-25 04:54:09 +00:00
|
|
|
expected_cmd = ['pip', 'install', '--requirement',
|
|
|
|
'requirements.txt']
|
2013-11-06 23:53:45 +00:00
|
|
|
mock.assert_called_once_with(
|
|
|
|
expected_cmd,
|
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-11-06 23:53:45 +00:00
|
|
|
)
|
2013-05-07 09:12:43 +00:00
|
|
|
|
2015-08-25 04:54:09 +00:00
|
|
|
def test_install_editable_without_egg_fails(self):
|
2013-07-04 16:24:24 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2013-07-05 00:21:00 +00:00
|
|
|
self.assertRaises(
|
2013-07-04 23:57:47 +00:00
|
|
|
CommandExecutionError,
|
2013-07-05 00:21:00 +00:00
|
|
|
pip.install,
|
|
|
|
editable='git+https://github.com/saltstack/salt-testing.git'
|
2013-07-04 16:24:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_install_multiple_editable(self):
|
|
|
|
editables = [
|
|
|
|
'git+https://github.com/jek/blinker.git#egg=Blinker',
|
|
|
|
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
|
|
|
]
|
|
|
|
|
2015-08-25 04:54:09 +00:00
|
|
|
expected = ['pip', 'install']
|
|
|
|
for item in editables:
|
|
|
|
expected.extend(['--editable', item])
|
|
|
|
|
2013-07-04 16:24:24 +00:00
|
|
|
# Passing editables as a list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install(editable=editables)
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-04 16:24:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing editables as a comma separated list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install(editable=','.join(editables))
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-04 16:24:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_install_multiple_pkgs_and_editables(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkgs = ['pep8', 'salt']
|
2013-07-04 16:24:24 +00:00
|
|
|
editables = [
|
|
|
|
'git+https://github.com/jek/blinker.git#egg=Blinker',
|
|
|
|
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
|
|
|
]
|
|
|
|
|
2015-08-25 04:54:09 +00:00
|
|
|
expected = ['pip', 'install'] + pkgs
|
|
|
|
for item in editables:
|
|
|
|
expected.extend(['--editable', item])
|
|
|
|
|
2013-07-04 16:24:24 +00:00
|
|
|
# Passing editables as a list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install(pkgs=pkgs, editable=editables)
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-04 16:24:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing editables as a comma separated list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install(pkgs=','.join(pkgs), editable=','.join(editables))
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-04 16:24:24 +00:00
|
|
|
)
|
|
|
|
|
2015-08-25 04:54:09 +00:00
|
|
|
# As single string (just use the first element from pkgs and editables)
|
2013-07-14 13:48:10 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install(pkgs=pkgs[0], editable=editables[0])
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', pkgs[0], '--editable', editables[0]],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 13:48:10 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_issue5940_install_multiple_pip_mirrors(self):
|
2013-07-04 14:01:05 +00:00
|
|
|
mirrors = [
|
|
|
|
'http://g.pypi.python.org',
|
|
|
|
'http://c.pypi.python.org',
|
|
|
|
'http://pypi.crate.io'
|
|
|
|
]
|
|
|
|
|
2015-08-25 04:54:09 +00:00
|
|
|
expected = ['pip', 'install', '--use-mirrors']
|
|
|
|
for item in mirrors:
|
|
|
|
expected.extend(['--mirrors', item])
|
|
|
|
|
2013-07-04 14:01:05 +00:00
|
|
|
# Passing mirrors as a list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install(mirrors=mirrors)
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-04 14:01:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# 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(mirrors=','.join(mirrors))
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-04 14:01:05 +00:00
|
|
|
)
|
|
|
|
|
2015-08-25 04:54:09 +00:00
|
|
|
# As single string (just use the first element from mirrors)
|
2013-07-14 13:48:10 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install(mirrors=mirrors[0])
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--use-mirrors', '--mirrors', mirrors[0]],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 13:48:10 +00:00
|
|
|
)
|
|
|
|
|
2013-07-04 23:54:11 +00:00
|
|
|
def test_install_with_multiple_find_links(self):
|
|
|
|
find_links = [
|
|
|
|
'http://g.pypi.python.org',
|
|
|
|
'http://c.pypi.python.org',
|
|
|
|
'http://pypi.crate.io'
|
|
|
|
]
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
|
|
|
|
expected = ['pip', 'install']
|
|
|
|
for item in find_links:
|
|
|
|
expected.extend(['--find-links', item])
|
|
|
|
expected.append(pkg)
|
2013-07-04 23:54:11 +00:00
|
|
|
|
|
|
|
# Passing mirrors as a list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, find_links=find_links)
|
2013-07-04 23:54:11 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-04 23:54:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing mirrors as a comma separated list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, find_links=','.join(find_links))
|
2013-07-04 23:54:11 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-04 23:54:11 +00:00
|
|
|
)
|
|
|
|
|
2015-08-25 04:54:09 +00:00
|
|
|
# As single string (just use the first element from find_links)
|
2013-07-14 13:48:10 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, find_links=find_links[0])
|
2013-07-14 13:48:10 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--find-links', find_links[0], pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 13:48:10 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 15:15:30 +00:00
|
|
|
# Invalid proto raises exception
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandExecutionError,
|
|
|
|
pip.install,
|
2015-08-25 04:54:09 +00:00
|
|
|
'\'' + pkg + '\'',
|
2013-07-14 15:15:30 +00:00
|
|
|
find_links='sftp://pypi.crate.io'
|
|
|
|
)
|
|
|
|
|
|
|
|
# Valid protos work?
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, find_links=find_links)
|
2013-07-14 15:15:30 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:15:30 +00:00
|
|
|
)
|
|
|
|
|
2013-07-05 00:21:00 +00:00
|
|
|
def test_install_no_index_with_index_url_or_extra_index_url_raises(self):
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandExecutionError,
|
|
|
|
pip.install, no_index=True, index_url='http://foo.tld'
|
|
|
|
)
|
|
|
|
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandExecutionError,
|
|
|
|
pip.install, no_index=True, extra_index_url='http://foo.tld'
|
|
|
|
)
|
|
|
|
|
2013-05-07 09:12:43 +00:00
|
|
|
@patch('salt.modules.pip._get_cached_requirements')
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_failed_cached_requirements(self, get_cached_requirements):
|
2013-05-07 09:12:43 +00:00
|
|
|
get_cached_requirements.return_value = False
|
|
|
|
ret = pip.install(requirements='salt://my_test_reqs')
|
|
|
|
self.assertEqual(False, ret['result'])
|
|
|
|
self.assertIn('my_test_reqs', ret['comment'])
|
|
|
|
|
|
|
|
@patch('salt.modules.pip._get_cached_requirements')
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_cached_requirements_used(self, get_cached_requirements):
|
2013-05-07 09:12:43 +00:00
|
|
|
get_cached_requirements.return_value = 'my_cached_reqs'
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2013-06-27 13:01:45 +00:00
|
|
|
pip.install(requirements='salt://requirements.txt')
|
2015-08-25 04:54:09 +00:00
|
|
|
expected = ['pip', 'install', '--requirement', 'my_cached_reqs']
|
2013-11-06 23:53:45 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-11-06 23:53:45 +00:00
|
|
|
)
|
2013-06-25 08:24:05 +00:00
|
|
|
|
2013-05-17 18:56:09 +00:00
|
|
|
@patch('os.path')
|
2015-01-30 21:58:48 +00:00
|
|
|
def test_install_venv(self, mock_path):
|
2013-05-17 18:56:09 +00:00
|
|
|
mock_path.is_file.return_value = True
|
|
|
|
mock_path.isdir.return_value = True
|
2013-06-25 08:24:05 +00:00
|
|
|
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'mock'
|
|
|
|
venv_path = '/test_env'
|
|
|
|
|
2013-05-17 18:56:09 +00:00
|
|
|
def join(*args):
|
|
|
|
return '/'.join(args)
|
|
|
|
mock_path.join = join
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, bin_env=venv_path)
|
2013-06-25 08:24:05 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
[os.path.join(venv_path, 'bin', 'pip'), 'install', pkg],
|
2013-07-13 17:35:54 +00:00
|
|
|
env={'VIRTUAL_ENV': '/test_env'},
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2015-01-09 18:39:09 +00:00
|
|
|
)
|
2013-06-25 08:24:05 +00:00
|
|
|
|
2013-07-14 13:35:15 +00:00
|
|
|
@patch('os.path')
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_log_argument_in_resulting_command(self, mock_path):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
log_path = '/tmp/pip-install.log'
|
2013-07-14 13:35:15 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, log=log_path)
|
2013-07-14 13:35:15 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--log', log_path, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 13:35:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Let's fake a non-writable log file
|
|
|
|
mock_path.exists.side_effect = IOError('Fooo!')
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
IOError,
|
|
|
|
pip.install,
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg,
|
|
|
|
log=log_path
|
2013-07-14 13:35:15 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_timeout_argument_in_resulting_command(self):
|
2013-07-14 13:38:57 +00:00
|
|
|
# Passing an int
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
expected_prefix = ['pip', 'install', '--timeout']
|
2013-07-14 13:38:57 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, timeout=10)
|
2013-07-14 13:38:57 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected_prefix + [10, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 13:38:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing an int as a string
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, timeout='10')
|
2013-07-14 13:38:57 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected_prefix + ['10', pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 13:38:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing a non-int to timeout
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
ValueError,
|
|
|
|
pip.install,
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg,
|
2013-07-14 13:38:57 +00:00
|
|
|
timeout='a'
|
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_index_url_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
index_url = 'http://foo.tld'
|
2013-07-14 15:19:01 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, index_url=index_url)
|
2013-07-14 15:19:01 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--index-url', index_url, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:19:01 +00:00
|
|
|
)
|
2013-06-25 08:24:05 +00:00
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_extra_index_url_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
extra_index_url = 'http://foo.tld'
|
2013-07-14 15:21:37 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, extra_index_url=extra_index_url)
|
2013-07-14 15:21:37 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--extra-index-url', extra_index_url, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:21:37 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_no_index_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
2013-07-14 15:22:52 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, no_index=True)
|
2013-07-14 15:22:52 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--no-index', pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:22:52 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_build_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
build = '/tmp/foo'
|
2013-07-14 15:31:53 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, build=build)
|
2013-07-14 15:31:53 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--build', build, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:31:53 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_target_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
target = '/tmp/foo'
|
2013-07-14 15:32:52 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, target=target)
|
2013-07-14 15:32:52 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--target', target, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:32:52 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_download_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
download = '/tmp/foo'
|
2013-07-14 15:33:30 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, download=download)
|
2013-07-14 15:33:30 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--download', download, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:33:30 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_no_download_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
2013-07-14 15:36:26 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, no_download=True)
|
2013-07-14 15:36:26 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--no-download', pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:36:26 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_download_cache_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
download_cache = '/tmp/foo'
|
2013-07-14 15:34:47 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, download_cache='/tmp/foo')
|
2013-07-14 15:34:47 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--download-cache', download_cache, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:34:47 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_source_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
source = '/tmp/foo'
|
2013-07-14 15:39:33 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, source=source)
|
2013-07-14 15:39:33 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--source', source, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:39:33 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_exists_action_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
2013-07-14 15:53:09 +00:00
|
|
|
for action in ('s', 'i', 'w', 'b'):
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install('pep8', exists_action=action)
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--exists-action', action, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 15:53:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Test for invalid action
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandExecutionError,
|
|
|
|
pip.install,
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg,
|
2013-07-14 15:53:09 +00:00
|
|
|
exists_action='d'
|
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_install_options_argument_in_resulting_command(self):
|
2013-07-14 16:04:12 +00:00
|
|
|
install_options = [
|
|
|
|
'--exec-prefix=/foo/bar',
|
|
|
|
'--install-scripts=/foo/bar/bin'
|
|
|
|
]
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
|
|
|
|
expected = ['pip', 'install']
|
|
|
|
for item in install_options:
|
|
|
|
expected.extend(['--install-option', item])
|
|
|
|
expected.append(pkg)
|
2013-07-14 16:04:12 +00:00
|
|
|
|
|
|
|
# Passing options as a list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, install_options=install_options)
|
2013-07-14 16:04:12 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:04:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing mirrors as a comma separated list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, install_options=','.join(install_options))
|
2013-07-14 16:04:12 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:04:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing mirrors as a single string entry
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, install_options=install_options[0])
|
2013-07-14 16:04:12 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--install-option',
|
|
|
|
install_options[0], pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:04:12 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_global_options_argument_in_resulting_command(self):
|
2013-07-14 16:14:34 +00:00
|
|
|
global_options = [
|
|
|
|
'--quiet',
|
|
|
|
'--no-user-cfg'
|
|
|
|
]
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
|
|
|
|
expected = ['pip', 'install']
|
|
|
|
for item in global_options:
|
|
|
|
expected.extend(['--global-option', item])
|
|
|
|
expected.append(pkg)
|
2013-07-14 16:14:34 +00:00
|
|
|
|
|
|
|
# Passing options as a list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, global_options=global_options)
|
2013-07-14 16:14:34 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:14:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing mirrors as a comma separated list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, global_options=','.join(global_options))
|
2013-07-14 16:14:34 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:14:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing mirrors as a single string entry
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, global_options=global_options[0])
|
2013-07-14 16:14:34 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--global-option', global_options[0], pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:14:34 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_upgrade_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
2013-07-14 16:16:13 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, upgrade=True)
|
2013-07-14 16:16:13 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--upgrade', pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:16:13 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_force_reinstall_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
2013-07-14 16:17:06 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, force_reinstall=True)
|
2013-07-14 16:17:06 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--force-reinstall', pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:17:06 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_ignore_installed_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
2013-07-14 16:17:45 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, ignore_installed=True)
|
2013-07-14 16:17:45 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--ignore-installed', pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:17:45 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_no_deps_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
2013-07-14 16:19:14 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, no_deps=True)
|
2013-07-14 16:19:14 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--no-deps', pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:19:14 +00:00
|
|
|
)
|
2013-07-14 16:17:45 +00:00
|
|
|
|
2013-07-14 17:00:49 +00:00
|
|
|
def test_install_no_install_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
2013-07-14 16:20:02 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, no_install=True)
|
2013-07-14 16:20:02 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--no-install', pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 16:20:02 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:51:58 +00:00
|
|
|
def test_install_proxy_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
proxy = 'salt-user:salt-passwd@salt-proxy:3128'
|
2013-07-14 17:51:58 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, proxy=proxy)
|
2013-07-14 17:51:58 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--proxy', proxy, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 17:51:58 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:29:56 +00:00
|
|
|
@patch('salt.modules.pip._get_cached_requirements')
|
|
|
|
def test_install_multiple_requirements_arguments_in_resulting_command(self, get_cached_requirements):
|
2015-08-25 04:54:09 +00:00
|
|
|
cached_reqs = [
|
2013-07-14 17:29:56 +00:00
|
|
|
'my_cached_reqs-1', 'my_cached_reqs-2'
|
|
|
|
]
|
2015-08-25 04:54:09 +00:00
|
|
|
get_cached_requirements.side_effect = cached_reqs
|
2013-07-14 17:29:56 +00:00
|
|
|
requirements = [
|
|
|
|
'salt://requirements-1.txt', 'salt://requirements-2.txt'
|
|
|
|
]
|
|
|
|
|
2015-08-25 04:54:09 +00:00
|
|
|
expected = ['pip', 'install']
|
|
|
|
for item in cached_reqs:
|
|
|
|
expected.extend(['--requirement', item])
|
|
|
|
|
2013-07-14 17:29:56 +00:00
|
|
|
# Passing option as a list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install(requirements=requirements)
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 17:29:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing option as a comma separated list
|
2015-08-25 04:54:09 +00:00
|
|
|
get_cached_requirements.side_effect = cached_reqs
|
2013-07-14 17:29:56 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install(requirements=','.join(requirements))
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 17:29:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing option as a single string entry
|
2015-08-25 04:54:09 +00:00
|
|
|
get_cached_requirements.side_effect = [cached_reqs[0]]
|
2013-07-14 17:29:56 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.install(requirements=requirements[0])
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--requirement', cached_reqs[0]],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 17:29:56 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:45:34 +00:00
|
|
|
@patch('salt.modules.pip._get_cached_requirements')
|
|
|
|
def test_uninstall_multiple_requirements_arguments_in_resulting_command(self, get_cached_requirements):
|
2015-08-25 04:54:09 +00:00
|
|
|
cached_reqs = [
|
2013-07-14 17:45:34 +00:00
|
|
|
'my_cached_reqs-1', 'my_cached_reqs-2'
|
|
|
|
]
|
2015-08-25 04:54:09 +00:00
|
|
|
get_cached_requirements.side_effect = cached_reqs
|
2013-07-14 17:45:34 +00:00
|
|
|
requirements = [
|
|
|
|
'salt://requirements-1.txt', 'salt://requirements-2.txt'
|
|
|
|
]
|
|
|
|
|
2015-08-25 04:54:09 +00:00
|
|
|
expected = ['pip', 'uninstall', '-y']
|
|
|
|
for item in cached_reqs:
|
|
|
|
expected.extend(['--requirement', item])
|
|
|
|
|
2013-07-14 17:45:34 +00:00
|
|
|
# Passing option as a list
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.uninstall(requirements=requirements)
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 17:45:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing option as a comma separated list
|
2015-08-25 04:54:09 +00:00
|
|
|
get_cached_requirements.side_effect = cached_reqs
|
2013-07-14 17:45:34 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.uninstall(requirements=','.join(requirements))
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected,
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 17:45:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing option as a single string entry
|
2015-08-25 04:54:09 +00:00
|
|
|
get_cached_requirements.side_effect = [cached_reqs[0]]
|
2013-07-14 17:45:34 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
pip.uninstall(requirements=requirements[0])
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'uninstall', '-y', '--requirement', cached_reqs[0]],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 17:45:34 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 17:54:36 +00:00
|
|
|
def test_uninstall_proxy_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
proxy = 'salt-user:salt-passwd@salt-proxy:3128'
|
2013-07-14 17:54:36 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.uninstall(pkg, proxy=proxy)
|
2013-07-14 17:54:36 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'uninstall', '-y', '--proxy', proxy, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 17:54:36 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 18:01:27 +00:00
|
|
|
@patch('os.path')
|
|
|
|
def test_uninstall_log_argument_in_resulting_command(self, mock_path):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
log_path = '/tmp/pip-install.log'
|
2013-07-14 18:01:27 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.uninstall(pkg, log=log_path)
|
2013-07-14 18:01:27 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'uninstall', '-y', '--log', log_path, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 18:01:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Let's fake a non-writable log file
|
|
|
|
mock_path.exists.side_effect = IOError('Fooo!')
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
IOError,
|
|
|
|
pip.uninstall,
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg,
|
|
|
|
log=log_path
|
2013-07-14 18:01:27 +00:00
|
|
|
)
|
|
|
|
|
2013-07-14 18:02:41 +00:00
|
|
|
def test_uninstall_timeout_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
|
|
|
expected_prefix = ['pip', 'uninstall', '-y', '--timeout']
|
2013-07-14 18:02:41 +00:00
|
|
|
# Passing an int
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.uninstall(pkg, timeout=10)
|
2013-07-14 18:02:41 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected_prefix + [10, pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 18:02:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing an int as a string
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.uninstall(pkg, timeout='10')
|
2013-07-14 18:02:41 +00:00
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
expected_prefix + ['10', pkg],
|
2013-11-06 23:53:45 +00:00
|
|
|
saltenv='base',
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 18:02:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Passing a non-int to timeout
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
ValueError,
|
|
|
|
pip.uninstall,
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg,
|
2013-07-14 18:02:41 +00:00
|
|
|
timeout='a'
|
|
|
|
)
|
|
|
|
|
2013-07-14 18:25:44 +00:00
|
|
|
def test_freeze_command(self):
|
|
|
|
eggs = [
|
|
|
|
'M2Crypto==0.21.1',
|
|
|
|
'-e git+git@github.com:s0undt3ch/salt-testing.git@9ed81aa2f918d59d3706e56b18f0782d1ea43bf8#egg=SaltTesting-dev',
|
|
|
|
'bbfreeze==1.1.0',
|
|
|
|
'bbfreeze-loader==1.1.0',
|
|
|
|
'pycrypto==2.6'
|
|
|
|
]
|
|
|
|
mock = MagicMock(
|
|
|
|
return_value={
|
|
|
|
'retcode': 0,
|
|
|
|
'stdout': '\n'.join(eggs)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
ret = pip.freeze()
|
|
|
|
mock.assert_called_once_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'freeze'],
|
2015-01-23 20:34:50 +00:00
|
|
|
runas=None,
|
2014-10-23 16:47:37 +00:00
|
|
|
cwd=None,
|
2015-01-09 18:39:09 +00:00
|
|
|
use_vt=False,
|
2015-01-07 21:54:36 +00:00
|
|
|
python_shell=False,
|
2013-07-14 18:25:44 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(ret, eggs)
|
|
|
|
|
|
|
|
# Non zero returncode raises exception?
|
|
|
|
mock = MagicMock(return_value={'retcode': 1, 'stderr': 'CABOOOOMMM!'})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandExecutionError,
|
|
|
|
pip.freeze,
|
|
|
|
)
|
|
|
|
|
2013-07-14 18:30:08 +00:00
|
|
|
def test_list_command(self):
|
|
|
|
eggs = [
|
|
|
|
'M2Crypto==0.21.1',
|
|
|
|
'-e git+git@github.com:s0undt3ch/salt-testing.git@9ed81aa2f918d59d3706e56b18f0782d1ea43bf8#egg=SaltTesting-dev',
|
|
|
|
'bbfreeze==1.1.0',
|
|
|
|
'bbfreeze-loader==1.1.0',
|
|
|
|
'pycrypto==2.6'
|
|
|
|
]
|
2015-05-15 06:00:22 +00:00
|
|
|
mock_version = '6.1.1'
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': '\n'.join(eggs)})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
with patch('salt.modules.pip.version',
|
|
|
|
MagicMock(return_value=mock_version)):
|
|
|
|
ret = pip.list_()
|
|
|
|
mock.assert_called_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'freeze'],
|
2015-05-15 06:00:22 +00:00
|
|
|
runas=None,
|
|
|
|
cwd=None,
|
|
|
|
python_shell=False,
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
ret, {
|
|
|
|
'SaltTesting-dev': 'git+git@github.com:s0undt3ch/salt-testing.git@9ed81aa2f918d59d3706e56b18f0782d1ea43bf8',
|
|
|
|
'M2Crypto': '0.21.1',
|
|
|
|
'bbfreeze-loader': '1.1.0',
|
|
|
|
'bbfreeze': '1.1.0',
|
|
|
|
'pip': mock_version,
|
|
|
|
'pycrypto': '2.6'
|
|
|
|
}
|
|
|
|
)
|
2013-07-14 18:25:44 +00:00
|
|
|
|
2013-07-14 18:30:08 +00:00
|
|
|
# Non zero returncode raises exception?
|
|
|
|
mock = MagicMock(return_value={'retcode': 1, 'stderr': 'CABOOOOMMM!'})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-05-15 06:00:22 +00:00
|
|
|
with patch('salt.modules.pip.version',
|
|
|
|
MagicMock(return_value='6.1.1')):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandExecutionError,
|
|
|
|
pip.list_,
|
|
|
|
)
|
2013-07-14 18:25:44 +00:00
|
|
|
|
2013-07-14 19:53:36 +00:00
|
|
|
def test_list_command_with_prefix(self):
|
|
|
|
eggs = [
|
|
|
|
'M2Crypto==0.21.1',
|
|
|
|
'-e git+git@github.com:s0undt3ch/salt-testing.git@9ed81aa2f918d59d3706e56b18f0782d1ea43bf8#egg=SaltTesting-dev',
|
|
|
|
'bbfreeze==1.1.0',
|
|
|
|
'bbfreeze-loader==1.1.0',
|
|
|
|
'pycrypto==2.6'
|
|
|
|
]
|
|
|
|
mock = MagicMock(
|
|
|
|
return_value={
|
|
|
|
'retcode': 0,
|
|
|
|
'stdout': '\n'.join(eggs)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
|
|
|
ret = pip.list_(prefix='bb')
|
2013-09-10 10:13:16 +00:00
|
|
|
mock.assert_called_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'freeze'],
|
2013-07-14 19:53:36 +00:00
|
|
|
runas=None,
|
2015-01-07 21:54:36 +00:00
|
|
|
cwd=None,
|
|
|
|
python_shell=False,
|
2013-07-14 19:53:36 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
ret, {
|
|
|
|
'bbfreeze-loader': '1.1.0',
|
|
|
|
'bbfreeze': '1.1.0',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2013-07-24 07:03:50 +00:00
|
|
|
def test_install_pre_argument_in_resulting_command(self):
|
2015-08-25 04:54:09 +00:00
|
|
|
pkg = 'pep8'
|
2013-08-09 11:14:56 +00:00
|
|
|
# Lower than 1.4 versions don't end-up with `--pre` in the resulting
|
|
|
|
# output
|
|
|
|
mock = MagicMock(side_effect=[
|
|
|
|
{'retcode': 0, 'stdout': 'pip 1.2.0 /path/to/site-packages/pip'},
|
|
|
|
{'retcode': 0, 'stdout': ''}
|
|
|
|
])
|
2013-07-24 07:03:50 +00:00
|
|
|
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
2015-05-15 06:00:22 +00:00
|
|
|
with patch('salt.modules.pip.version',
|
|
|
|
MagicMock(return_value='1.3')):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, pre_releases=True)
|
2015-05-15 06:00:22 +00:00
|
|
|
mock.assert_called_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', pkg],
|
2015-05-15 06:00:22 +00:00
|
|
|
saltenv='base',
|
|
|
|
runas=None,
|
|
|
|
cwd=None,
|
|
|
|
use_vt=False,
|
|
|
|
python_shell=False,
|
|
|
|
)
|
2013-08-09 11:14:56 +00:00
|
|
|
|
2015-05-15 06:00:22 +00:00
|
|
|
mock_run = MagicMock(return_value='pip 1.4.1 /path/to/site-packages/pip')
|
|
|
|
mock_run_all = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(pip.__salt__, {'cmd.run': mock_run,
|
|
|
|
'cmd.run_all': mock_run_all}):
|
|
|
|
with patch('salt.modules.pip._get_pip_bin',
|
|
|
|
MagicMock(return_value='pip')):
|
2015-08-25 04:54:09 +00:00
|
|
|
pip.install(pkg, pre_releases=True)
|
2015-05-15 06:00:22 +00:00
|
|
|
mock_run_all.assert_called_with(
|
2015-08-25 04:54:09 +00:00
|
|
|
['pip', 'install', '--pre', pkg],
|
2015-05-15 06:00:22 +00:00
|
|
|
saltenv='base',
|
|
|
|
runas=None,
|
|
|
|
cwd=None,
|
|
|
|
use_vt=False,
|
|
|
|
python_shell=False,
|
|
|
|
)
|
2013-07-24 07:03:50 +00:00
|
|
|
|
2013-07-27 12:34:58 +00:00
|
|
|
|
2013-06-25 08:24:05 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(PipTestCase, needs_daemon=False)
|