Exemplo n.º 1
0
    def test_issue_6030_deprecated_never_download(self):
        mock = MagicMock(return_value={"retcode": 0, "stdout": ""})

        with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
            virtualenv_mod.create("/tmp/foo", never_download=True)
            mock.assert_called_once_with(
                ["virtualenv", "--never-download", "/tmp/foo"],
                runas=None,
                python_shell=False,
            )

        with TstSuiteLoggingHandler() as handler:
            mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
            # Let's fake a higher virtualenv version
            virtualenv_mock = MagicMock()
            virtualenv_mock.__version__ = "1.10rc1"
            with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
                with patch.dict("sys.modules",
                                {"virtualenv": virtualenv_mock}):
                    virtualenv_mod.create("/tmp/foo", never_download=True)
                    mock.assert_called_once_with(["virtualenv", "/tmp/foo"],
                                                 runas=None,
                                                 python_shell=False)

                # Are we logging the deprecation information?
                self.assertIn(
                    "INFO:--never-download was deprecated in 1.10.0, "
                    "but reimplemented in 14.0.0. If this feature is needed, "
                    "please install a supported virtualenv version.",
                    handler.messages,
                )
Exemplo n.º 2
0
    def test_issue_6030_deprecated_never_download(self):
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})

        with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
            virtualenv_mod.create('/tmp/foo', never_download=True)
            mock.assert_called_once_with(
                ['virtualenv', '--never-download', '/tmp/foo'],
                runas=None,
                python_shell=False)

        with TestsLoggingHandler() as handler:
            mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
            # Let's fake a higher virtualenv version
            virtualenv_mock = MagicMock()
            virtualenv_mock.__version__ = '1.10rc1'
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                with patch.dict('sys.modules',
                                {'virtualenv': virtualenv_mock}):
                    virtualenv_mod.create('/tmp/foo', never_download=True)
                    mock.assert_called_once_with(['virtualenv', '/tmp/foo'],
                                                 runas=None,
                                                 python_shell=False)

                # Are we logging the deprecation information?
                self.assertIn(
                    'INFO:--never-download was deprecated in 1.10.0, '
                    'but reimplemented in 14.0.0. If this feature is needed, '
                    'please install a supported virtualenv version.',
                    handler.messages)
Exemplo n.º 3
0
    def test_issue_6030_deprecated_never_download(self):
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})

        with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
            virtualenv_mod.create('/tmp/foo', never_download=True)
            mock.assert_called_once_with(
                ['virtualenv', '--never-download', '/tmp/foo'],
                runas=None,
                python_shell=False)

        with TestsLoggingHandler() as handler:
            mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
            # Let's fake a higher virtualenv version
            virtualenv_mock = MagicMock()
            virtualenv_mock.__version__ = '1.10rc1'
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                with patch.dict('sys.modules',
                                {'virtualenv': virtualenv_mock}):
                    virtualenv_mod.create('/tmp/foo', never_download=True)
                    mock.assert_called_once_with(['virtualenv', '/tmp/foo'],
                                                 runas=None,
                                                 python_shell=False)

                # Are we logging the deprecation information?
                self.assertIn(
                    'INFO:The virtualenv \'--never-download\' option has been '
                    'deprecated in virtualenv(>=1.10), as such, the '
                    '\'never_download\' option to `virtualenv.create()` has '
                    'also been deprecated and it\'s not necessary anymore.',
                    handler.messages)
Exemplo n.º 4
0
 def setup_loader_modules(self):
     base_virtualenv_mock = MagicMock()
     base_virtualenv_mock.__version__ = '1.9.1'
     sys_modules_patcher = patch.dict('sys.modules',
                                      {'virtualenv': base_virtualenv_mock})
     sys_modules_patcher.start()
     self.addCleanup(sys_modules_patcher.stop)
     return {virtualenv_mod: {'__opts__': {'venv_bin': 'virtualenv'}}}
Exemplo n.º 5
0
 def setup_loader_modules(self):
     base_virtualenv_mock = MagicMock()
     base_virtualenv_mock.__version__ = '1.9.1'
     patcher = patch('salt.utils.path.which', lambda exe: exe)
     patcher.start()
     self.addCleanup(patcher.stop)
     return {
         virtualenv_mod: {
             '__opts__': {'venv_bin': 'virtualenv'},
             '_install_script': MagicMock(return_value={'retcode': 0,
                                                        'stdout': 'Installed script!',
                                                        'stderr': ''}),
             'sys.modules': {'virtualenv': base_virtualenv_mock}
         }
     }
Exemplo n.º 6
0
    def test_issue_6029_deprecated_distribute(self):
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})

        with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
            virtualenv_mod._install_script = MagicMock(
                return_value={
                    'retcode': 0,
                    'stdout': 'Installed script!',
                    'stderr': ''
                }
            )
            virtualenv_mod.create(
                '/tmp/foo', system_site_packages=True, distribute=True
            )
            mock.assert_called_once_with(
                ['virtualenv', '--distribute', '--system-site-packages', '/tmp/foo'],
                runas=None,
                python_shell=False
            )

        with TestsLoggingHandler() as handler:
            # Let's fake a higher virtualenv version
            virtualenv_mock = MagicMock()
            virtualenv_mock.__version__ = '1.10rc1'
            mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                with patch.dict('sys.modules',
                                {'virtualenv': virtualenv_mock}):
                    virtualenv_mod.create(
                        '/tmp/foo', system_site_packages=True, distribute=True
                    )
                    mock.assert_called_once_with(
                        ['virtualenv', '--system-site-packages', '/tmp/foo'],
                        runas=None,
                        python_shell=False
                    )

                # Are we logging the deprecation information?
                self.assertIn(
                    'INFO:The virtualenv \'--distribute\' option has been '
                    'deprecated in virtualenv(>=1.10), as such, the '
                    '\'distribute\' option to `virtualenv.create()` has '
                    'also been deprecated and it\'s not necessary anymore.',
                    handler.messages
                )
Exemplo n.º 7
0
    def test_issue_6029_deprecated_distribute(self):
        mock = MagicMock(return_value={"retcode": 0, "stdout": ""})

        with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
            virtualenv_mod.create("/tmp/foo",
                                  system_site_packages=True,
                                  distribute=True)
            mock.assert_called_once_with(
                [
                    "virtualenv", "--distribute", "--system-site-packages",
                    "/tmp/foo"
                ],
                runas=None,
                python_shell=False,
            )

        with TstSuiteLoggingHandler() as handler:
            # Let's fake a higher virtualenv version
            virtualenv_mock = MagicMock()
            virtualenv_mock.__version__ = "1.10rc1"
            mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
            with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
                with patch.dict("sys.modules",
                                {"virtualenv": virtualenv_mock}):
                    virtualenv_mod.create("/tmp/foo",
                                          system_site_packages=True,
                                          distribute=True)
                    mock.assert_called_once_with(
                        ["virtualenv", "--system-site-packages", "/tmp/foo"],
                        runas=None,
                        python_shell=False,
                    )

                # Are we logging the deprecation information?
                self.assertIn(
                    "INFO:The virtualenv '--distribute' option has been "
                    "deprecated in virtualenv(>=1.10), as such, the "
                    "'distribute' option to `virtualenv.create()` has "
                    "also been deprecated and it's not necessary anymore.",
                    handler.messages,
                )
Exemplo n.º 8
0
 def setup_loader_modules(self):
     base_virtualenv_mock = MagicMock()
     base_virtualenv_mock.__version__ = "1.9.1"
     patcher = patch("salt.utils.path.which", lambda exe: exe)
     patcher.start()
     self.addCleanup(patcher.stop)
     return {
         virtualenv_mod: {
             "__opts__": {
                 "venv_bin": "virtualenv"
             },
             "_install_script":
             MagicMock(return_value={
                 "retcode": 0,
                 "stdout": "Installed script!",
                 "stderr": "",
             }),
             "sys.modules": {
                 "virtualenv": base_virtualenv_mock
             },
         }
     }
Exemplo n.º 9
0
from __future__ import absolute_import
import sys

# Import Salt Testing libs
from tests.support.unit import skipIf, TestCase
from tests.support.helpers import TestsLoggingHandler, ForceImportErrorOn
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch

# Import salt libs
from salt.modules import virtualenv_mod
from salt.exceptions import CommandExecutionError

virtualenv_mod.__salt__ = {}
virtualenv_mod.__opts__['venv_bin'] = 'virtualenv'
base_virtualenv_mock = MagicMock()
base_virtualenv_mock.__version__ = '1.9.1'


@skipIf(NO_MOCK, NO_MOCK_REASON)
@patch('salt.utils.which', lambda bin_name: bin_name)
@patch.dict('sys.modules', {'virtualenv': base_virtualenv_mock})
class VirtualenvTestCase(TestCase):

    def test_issue_6029_deprecated_distribute(self):
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})

        with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
            virtualenv_mod._install_script = MagicMock(
                return_value={
                    'retcode': 0,
                    'stdout': 'Installed script!',
 def test_issue_57734_debian_package(self):
     virtualenv_mock = MagicMock()
     virtualenv_mock.__version__ = "20.0.23+ds"
     with patch.dict("sys.modules", {"virtualenv": virtualenv_mock}):
         ret = virtualenv_mod.virtualenv_ver(venv_bin="pyenv")
     self.assertEqual(ret, (20, 0, 23))