2012-09-27 11:06:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-11 10:23:37 +00:00
|
|
|
'''
|
2012-09-27 11:06:09 +00:00
|
|
|
tests.integration.modules.pip
|
2012-12-11 10:23:37 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2012-09-27 11:06:09 +00:00
|
|
|
|
2012-12-11 10:23:37 +00:00
|
|
|
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
2013-06-25 07:57:26 +00:00
|
|
|
:copyright: © 2012-2013 by the SaltStack Team, see AUTHORS for more details
|
2012-12-11 10:23:37 +00:00
|
|
|
:license: Apache 2.0, see LICENSE for more details.
|
|
|
|
'''
|
2012-09-27 11:06:09 +00:00
|
|
|
|
2012-12-11 10:23:37 +00:00
|
|
|
# Import python libs
|
2012-09-27 11:06:09 +00:00
|
|
|
import os
|
2013-05-05 03:09:50 +00:00
|
|
|
import pwd
|
2012-09-27 11:06:09 +00:00
|
|
|
import shutil
|
|
|
|
import tempfile
|
|
|
|
|
2013-06-27 11:36:37 +00:00
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
2012-09-27 11:06:09 +00:00
|
|
|
# Import salt libs
|
2013-06-27 11:36:37 +00:00
|
|
|
import integration
|
2012-09-27 11:06:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PipModuleTest(integration.ModuleCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(PipModuleTest, self).setUp()
|
|
|
|
ret = self.run_function('cmd.has_exec', ['virtualenv'])
|
|
|
|
if not ret:
|
|
|
|
self.skipTest('virtualenv not installed')
|
|
|
|
|
|
|
|
self.venv_test_dir = tempfile.mkdtemp()
|
|
|
|
self.venv_dir = os.path.join(self.venv_test_dir, 'venv')
|
|
|
|
|
|
|
|
def test_issue_2087_missing_pip(self):
|
|
|
|
# Let's create the testing virtualenv
|
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
|
|
|
|
# Let's remove the pip binary
|
|
|
|
pip_bin = os.path.join(self.venv_dir, 'bin', 'pip')
|
|
|
|
if not os.path.isfile(pip_bin):
|
|
|
|
self.skipTest(
|
|
|
|
'Failed to find the pip binary to the test virtualenv'
|
|
|
|
)
|
|
|
|
os.remove(pip_bin)
|
|
|
|
|
|
|
|
# Let's run a pip depending functions
|
|
|
|
for func in ('pip.freeze', 'pip.list'):
|
|
|
|
ret = self.run_function(func, bin_env=self.venv_dir)
|
|
|
|
self.assertEqual(
|
|
|
|
ret,
|
|
|
|
'Command required for \'{0}\' not found: Could not find '
|
|
|
|
'a `pip` binary'.format(func)
|
|
|
|
)
|
|
|
|
|
2013-05-05 03:09:50 +00:00
|
|
|
def test_issue_4805_nested_requirements_runas_no_chown(self):
|
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
|
|
|
|
# Create a requirements file that depends on another one.
|
|
|
|
req1_filename = os.path.join(self.venv_dir, 'requirements.txt')
|
|
|
|
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
|
|
|
|
with open(req1_filename, 'wb') as f:
|
|
|
|
f.write('-r requirements2.txt')
|
|
|
|
with open(req2_filename, 'wb') as f:
|
|
|
|
f.write('pep8')
|
|
|
|
|
|
|
|
this_user = pwd.getpwuid(os.getuid())[0]
|
|
|
|
ret = self.run_function('pip.install', requirements=req1_filename,
|
|
|
|
runas=this_user, no_chown=True)
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('installed pep8', ret['stdout'])
|
|
|
|
|
2012-09-27 17:33:50 +00:00
|
|
|
def test_pip_uninstall(self):
|
|
|
|
# Let's create the testing virtualenv
|
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
ret = self.run_function('pip.install', ['pep8'], bin_env=self.venv_dir)
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('installed pep8', ret['stdout'])
|
2012-12-11 10:23:37 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'pip.uninstall', ['pep8'], bin_env=self.venv_dir
|
|
|
|
)
|
2012-09-27 17:33:50 +00:00
|
|
|
self.assertEqual(ret['retcode'], 0)
|
2012-09-27 17:43:15 +00:00
|
|
|
self.assertIn('uninstalled pep8', ret['stdout'])
|
2012-09-27 17:33:50 +00:00
|
|
|
|
2013-02-07 23:51:05 +00:00
|
|
|
def test_pip_install_upgrade(self):
|
|
|
|
# Create the testing virtualenv
|
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
ret = self.run_function(
|
2013-02-08 00:30:40 +00:00
|
|
|
'pip.install', ['pep8==1.3.4'], bin_env=self.venv_dir
|
2013-02-07 23:51:05 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('installed pep8', ret['stdout'])
|
|
|
|
ret = self.run_function(
|
|
|
|
'pip.install',
|
|
|
|
['pep8'],
|
|
|
|
bin_env=self.venv_dir,
|
|
|
|
upgrade=True
|
|
|
|
)
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('installed pep8', ret['stdout'])
|
|
|
|
ret = self.run_function(
|
|
|
|
'pip.uninstall', ['pep8'], bin_env=self.venv_dir
|
|
|
|
)
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('uninstalled pep8', ret['stdout'])
|
|
|
|
|
2012-09-27 11:06:09 +00:00
|
|
|
def tearDown(self):
|
|
|
|
super(PipModuleTest, self).tearDown()
|
|
|
|
if os.path.isdir(self.venv_test_dir):
|
|
|
|
shutil.rmtree(self.venv_test_dir)
|
2013-06-25 08:24:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(PipModuleTest)
|