Exemplo n.º 1
0
    def test_uninstall_log_argument_in_resulting_command(self, mock_path):
        pkg = 'pep8'
        log_path = '/tmp/pip-install.log'
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall(pkg, log=log_path)
            mock.assert_called_once_with(
                ['pip', 'uninstall', '-y', '--log', log_path, pkg],
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )

        # 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,
                pkg,
                log=log_path
            )
Exemplo n.º 2
0
    def test_uninstall_timeout_argument_in_resulting_command(self):
        # Passing an int
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall('pep8', timeout=10)
            mock.assert_called_once_with(
                'pip uninstall -y --timeout=10 pep8',
                runas=None,
                cwd=None
            )

        # Passing an int as a string
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall('pep8', timeout='10')
            mock.assert_called_once_with(
                'pip uninstall -y --timeout=10 pep8',
                runas=None,
                cwd=None
            )

        # 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,
                'pep8',
                timeout='a'
            )
Exemplo n.º 3
0
 def test_uninstall_proxy_argument_in_resulting_command(self):
     mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
     with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
         pip.uninstall("pep8", proxy="salt-user:salt-passwd@salt-proxy:3128")
         mock.assert_called_once_with(
             "pip uninstall -y " "--proxy='salt-user:salt-passwd@salt-proxy:3128' pep8", runas=None, cwd=None
         )
Exemplo n.º 4
0
    def test_uninstall_log_argument_in_resulting_command(self, mock_path):
        mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
        with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
            pip.uninstall("pep8", log="/tmp/pip-install.log")
            mock.assert_called_once_with("pip uninstall -y --log=/tmp/pip-install.log pep8", runas=None, cwd=None)

        # 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, "pep8", log="/tmp/pip-install.log")
Exemplo n.º 5
0
 def test_uninstall_proxy_argument_in_resulting_command(self):
     mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
     with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
         pip.uninstall(
             'pep8', proxy='salt-user:salt-passwd@salt-proxy:3128'
         )
         mock.assert_called_once_with(
             'pip uninstall -y '
             '--proxy=\'salt-user:salt-passwd@salt-proxy:3128\' pep8',
             runas=None,
             cwd=None
         )
Exemplo n.º 6
0
    def test_uninstall_deprecated_runas_triggers_warning(self):
        # We *always* want *all* warnings thrown on this module
        warnings.resetwarnings()
        warnings.filterwarnings('always', '', DeprecationWarning, __name__)

        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            with warnings.catch_warnings(record=True) as w:
                pip.uninstall('pep8', runas='me!')
                self.assertEqual(
                    'The \'runas\' argument to pip.install is deprecated, and '
                    'will be removed in Salt Lithium (Unreleased). Please '
                    'use \'user\' instead.', str(w[-1].message))
Exemplo n.º 7
0
 def test_uninstall_proxy_argument_in_resulting_command(self):
     pkg = 'pep8'
     proxy = 'salt-user:salt-passwd@salt-proxy:3128'
     mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
     with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
         pip.uninstall(pkg, proxy=proxy)
         mock.assert_called_once_with(
             ['pip', 'uninstall', '-y', '--proxy', proxy, pkg],
             saltenv='base',
             runas=None,
             cwd=None,
             use_vt=False,
             python_shell=False,
         )
Exemplo n.º 8
0
    def test_uninstall_deprecated_runas_triggers_warning(self):
        # We *always* want *all* warnings thrown on this module
        warnings.resetwarnings()
        warnings.filterwarnings('always', '', DeprecationWarning, __name__)

        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            with warnings.catch_warnings(record=True) as w:
                pip.uninstall('pep8', runas='me!')
                self.assertEqual(
                    'The \'runas\' argument to pip.install is deprecated, and '
                    'will be removed in 0.18.0. Please use \'user\' instead.',
                    str(w[-1].message)
                )
Exemplo n.º 9
0
    def test_uninstall_deprecated_runas_triggers_warning(self):
        # We *always* want *all* warnings thrown on this module
        warnings.resetwarnings()
        warnings.filterwarnings("always", "", DeprecationWarning, __name__)

        mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
        with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
            with warnings.catch_warnings(record=True) as w:
                pip.uninstall("pep8", runas="me!")
                self.assertEqual(
                    "The 'runas' argument to pip.install is deprecated, and "
                    "will be removed in 0.18.0. Please use 'user' instead.",
                    str(w[-1].message),
                )
Exemplo n.º 10
0
 def test_uninstall_proxy_argument_in_resulting_command(self):
     pkg = 'pep8'
     proxy = 'salt-user:salt-passwd@salt-proxy:3128'
     mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
     with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
         pip.uninstall(pkg, proxy=proxy)
         mock.assert_called_once_with(
             ['pip', 'uninstall', '-y', '--proxy', proxy, pkg],
             saltenv='base',
             cwd=None,
             runas=None,
             use_vt=False,
             python_shell=False,
         )
Exemplo n.º 11
0
    def test_uninstall_timeout_argument_in_resulting_command(self):
        # Passing an int
        mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
        with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
            pip.uninstall("pep8", timeout=10)
            mock.assert_called_once_with("pip uninstall -y --timeout=10 pep8", runas=None, cwd=None)

        # Passing an int as a string
        mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
        with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
            pip.uninstall("pep8", timeout="10")
            mock.assert_called_once_with("pip uninstall -y --timeout=10 pep8", runas=None, cwd=None)

        # 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, "pep8", timeout="a")
Exemplo n.º 12
0
    def test_uninstall_log_argument_in_resulting_command(self, mock_path):
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall('pep8', log='/tmp/pip-install.log')
            mock.assert_called_once_with(
                'pip uninstall -y --log=/tmp/pip-install.log pep8',
                saltenv='base',
                runas=None,
                cwd=None)

        # 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,
                              'pep8',
                              log='/tmp/pip-install.log')
Exemplo n.º 13
0
    def test_uninstall_log_argument_in_resulting_command(self, mock_path):
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall('pep8', log='/tmp/pip-install.log')
            mock.assert_called_once_with(
                'pip uninstall -y --log=/tmp/pip-install.log pep8',
                runas=None,
                cwd=None
            )

        # 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,
                'pep8',
                log='/tmp/pip-install.log'
            )
Exemplo n.º 14
0
    def test_uninstall_log_argument_in_resulting_command(self, mock_path):
        pkg = 'pep8'
        log_path = '/tmp/pip-install.log'
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall(pkg, log=log_path)
            mock.assert_called_once_with(
                ['pip', 'uninstall', '-y', '--log', log_path, pkg],
                saltenv='base',
                cwd=None,
                runas=None,
                use_vt=False,
                python_shell=False,
            )

        # 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, pkg, log=log_path)
Exemplo n.º 15
0
    def test_uninstall_multiple_requirements_arguments_in_resulting_command(self, get_cached_requirements):
        get_cached_requirements.side_effect = ["my_cached_reqs-1", "my_cached_reqs-2"]
        requirements = ["salt://requirements-1.txt", "salt://requirements-2.txt"]

        # 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(
                "pip uninstall -y " "--requirement='my_cached_reqs-1' " "--requirement='my_cached_reqs-2'",
                runas=None,
                cwd=None,
            )

        # Passing option as a comma separated list
        get_cached_requirements.side_effect = ["my_cached_reqs-1", "my_cached_reqs-2"]
        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(
                "pip uninstall -y " "--requirement='my_cached_reqs-1' " "--requirement='my_cached_reqs-2'",
                runas=None,
                cwd=None,
            )

        # Passing option as a single string entry
        get_cached_requirements.side_effect = ["my_cached_reqs-1"]
        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("pip uninstall -y --requirement='my_cached_reqs-1'", runas=None, cwd=None)
Exemplo n.º 16
0
    def test_uninstall_timeout_argument_in_resulting_command(self):
        pkg = 'pep8'
        expected_prefix = ['pip', 'uninstall', '-y', '--timeout']
        # Passing an int
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall(pkg, timeout=10)
            mock.assert_called_once_with(
                expected_prefix + [10, pkg],
                cwd=None,
                saltenv='base',
                runas=None,
                use_vt=False,
                python_shell=False,
            )

        # Passing an int as a string
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall(pkg, timeout='10')
            mock.assert_called_once_with(
                expected_prefix + ['10', pkg],
                cwd=None,
                saltenv='base',
                runas=None,
                use_vt=False,
                python_shell=False,
            )

        # 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,
                pkg,
                timeout='a'
            )
Exemplo n.º 17
0
    def test_uninstall_timeout_argument_in_resulting_command(self):
        pkg = 'pep8'
        expected_prefix = ['pip', 'uninstall', '-y', '--timeout']
        # Passing an int
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall(pkg, timeout=10)
            mock.assert_called_once_with(
                expected_prefix + [10, pkg],
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )

        # Passing an int as a string
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall(pkg, timeout='10')
            mock.assert_called_once_with(
                expected_prefix + ['10', pkg],
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )

        # 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,
                pkg,
                timeout='a'
            )
Exemplo n.º 18
0
    def test_uninstall_multiple_requirements_arguments_in_resulting_command(
            self):
        with patch('salt.modules.pip._get_cached_requirements'
                   ) as get_cached_requirements:
            cached_reqs = ['my_cached_reqs-1', 'my_cached_reqs-2']
            get_cached_requirements.side_effect = cached_reqs
            requirements = [
                'salt://requirements-1.txt', 'salt://requirements-2.txt'
            ]

            expected = [sys.executable, '-m', 'pip', 'uninstall', '-y']
            for item in cached_reqs:
                expected.extend(['--requirement', item])

            # 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_with(
                    expected,
                    cwd=None,
                    saltenv='base',
                    runas=None,
                    use_vt=False,
                    python_shell=False,
                )

            # Passing option as a comma separated list
            get_cached_requirements.side_effect = cached_reqs
            mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
            with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
                pip.uninstall(requirements=','.join(requirements))
                mock.assert_called_with(
                    expected,
                    cwd=None,
                    saltenv='base',
                    runas=None,
                    use_vt=False,
                    python_shell=False,
                )

            # Passing option as a single string entry
            get_cached_requirements.side_effect = [cached_reqs[0]]
            mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
            with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
                pip.uninstall(requirements=requirements[0])
                expected = [
                    sys.executable, '-m', 'pip', 'uninstall', '-y',
                    '--requirement', cached_reqs[0]
                ]
                mock.assert_called_with(
                    expected,
                    cwd=None,
                    saltenv='base',
                    runas=None,
                    use_vt=False,
                    python_shell=False,
                )
Exemplo n.º 19
0
    def test_uninstall_timeout_argument_in_resulting_command(self):
        # Passing an int
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall('pep8', timeout=10)
            mock.assert_called_once_with('pip uninstall -y --timeout=10 pep8',
                                         saltenv='base',
                                         runas=None,
                                         cwd=None)

        # Passing an int as a string
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.uninstall('pep8', timeout='10')
            mock.assert_called_once_with('pip uninstall -y --timeout=10 pep8',
                                         saltenv='base',
                                         runas=None,
                                         cwd=None)

        # 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, 'pep8', timeout='a')
Exemplo n.º 20
0
    def test_uninstall_multiple_requirements_arguments_in_resulting_command(
            self, get_cached_requirements):
        get_cached_requirements.side_effect = [
            'my_cached_reqs-1', 'my_cached_reqs-2'
        ]
        requirements = [
            'salt://requirements-1.txt', 'salt://requirements-2.txt'
        ]

        # 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(
                'pip uninstall -y '
                '--requirement=\'my_cached_reqs-1\' '
                '--requirement=\'my_cached_reqs-2\'',
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )

        # Passing option as a comma separated list
        get_cached_requirements.side_effect = [
            'my_cached_reqs-1', 'my_cached_reqs-2'
        ]
        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(
                'pip uninstall -y '
                '--requirement=\'my_cached_reqs-1\' '
                '--requirement=\'my_cached_reqs-2\'',
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )

        # Passing option as a single string entry
        get_cached_requirements.side_effect = ['my_cached_reqs-1']
        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(
                'pip uninstall -y --requirement=\'my_cached_reqs-1\'',
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )
Exemplo n.º 21
0
    def test_uninstall_multiple_requirements_arguments_in_resulting_command(self, get_cached_requirements):
        get_cached_requirements.side_effect = [
            'my_cached_reqs-1', 'my_cached_reqs-2'
        ]
        requirements = [
            'salt://requirements-1.txt', 'salt://requirements-2.txt'
        ]

        # 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(
                'pip uninstall -y '
                '--requirement="my_cached_reqs-1" '
                '--requirement="my_cached_reqs-2"',
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )

        # Passing option as a comma separated list
        get_cached_requirements.side_effect = [
            'my_cached_reqs-1', 'my_cached_reqs-2'
        ]
        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(
                'pip uninstall -y '
                '--requirement="my_cached_reqs-1" '
                '--requirement="my_cached_reqs-2"',
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )

        # Passing option as a single string entry
        get_cached_requirements.side_effect = ['my_cached_reqs-1']
        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(
                'pip uninstall -y --requirement="my_cached_reqs-1"',
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )
Exemplo n.º 22
0
    def test_uninstall_multiple_requirements_arguments_in_resulting_command(self, get_cached_requirements):
        cached_reqs = [
            'my_cached_reqs-1', 'my_cached_reqs-2'
        ]
        get_cached_requirements.side_effect = cached_reqs
        requirements = [
            'salt://requirements-1.txt', 'salt://requirements-2.txt'
        ]

        expected = ['pip', 'uninstall', '-y']
        for item in cached_reqs:
            expected.extend(['--requirement', item])

        # 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(
                expected,
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )

        # Passing option as a comma separated list
        get_cached_requirements.side_effect = cached_reqs
        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(
                expected,
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )

        # Passing option as a single string entry
        get_cached_requirements.side_effect = [cached_reqs[0]]
        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(
                ['pip', 'uninstall', '-y', '--requirement', cached_reqs[0]],
                saltenv='base',
                runas=None,
                cwd=None,
                use_vt=False,
                python_shell=False,
            )