salt/tests/unit/states/test_virtualenv_mod.py
rallytime 3273bbdab7
Merge branch '2017.7' into '2018.3'
Conflicts:
  - doc/ref/configuration/master.rst
  - doc/ref/modules/all/index.rst
  - doc/topics/grains/index.rst
  - doc/topics/releases/2016.3.4.rst
  - doc/topics/spm/spm_formula.rst
  - doc/topics/tutorials/cron.rst
  - doc/topics/tutorials/index.rst
  - doc/topics/tutorials/stormpath.rst
  - salt/engines/slack.py
  - salt/log/handlers/fluent_mod.py
  - salt/modules/cyg.py
  - salt/modules/junos.py
  - salt/modules/namecheap_dns.py
  - salt/modules/namecheap_domains.py
  - salt/modules/namecheap_ns.py
  - salt/modules/namecheap_ssl.py
  - salt/modules/namecheap_users.py
  - salt/modules/reg.py
  - salt/modules/tomcat.py
  - salt/modules/vault.py
  - salt/modules/win_file.py
  - salt/modules/zpool.py
  - salt/output/highstate.py
  - salt/renderers/pass.py
  - salt/runners/cache.py
  - salt/states/boto_apigateway.py
  - salt/states/boto_iam.py
  - salt/states/boto_route53.py
  - salt/states/msteams.py
  - salt/states/reg.py
  - salt/states/win_iis.py
  - tests/integration/modules/test_cmdmod.py
  - tests/integration/states/test_user.py
  - tests/support/helpers.py
  - tests/unit/cloud/clouds/test_openstack.py
  - tests/unit/fileserver/test_gitfs.py
  - tests/unit/modules/test_junos.py
  - tests/unit/pillar/test_git.py
  - tests/unit/states/test_win_path.py
  - tests/unit/test_pillar.py
  - tests/unit/utils/test_format_call.py
  - tests/unit/utils/test_utils.py
  - tests/unit/utils/test_warnings.py
2018-06-01 14:54:12 -04:00

88 lines
3.8 KiB
Python

# -*- coding: utf-8 -*-
'''
:codeauthor: Rahul Handay <rahulha@saltstack.com>
'''
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
import os
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
# Import Salt Libs
import salt.states.virtualenv_mod as virtualenv_mod
@skipIf(NO_MOCK, NO_MOCK_REASON)
class VirtualenvModTestCase(TestCase, LoaderModuleMockMixin):
'''
Validate the virtualenv_mod state
'''
def setup_loader_modules(self):
return {virtualenv_mod: {'__env__': 'base'}}
def test_managed(self):
'''
Test to create a virtualenv and optionally manage it with pip
'''
ret = {'name': 'salt',
'changes': {},
'result': False,
'comment': ''}
ret.update({'comment': 'Virtualenv was not detected on this system'})
self.assertDictEqual(virtualenv_mod.managed('salt'), ret)
mock1 = MagicMock(return_value='True')
mock = MagicMock(return_value=False)
mock2 = MagicMock(return_value='1.1')
with patch.dict(virtualenv_mod.__salt__, {"virtualenv.create": True,
"cp.is_cached": mock,
"cp.cache_file": mock,
"cp.hash_file": mock,
"pip.freeze": mock1,
"cmd.run_stderr": mock1,
"pip.version": mock2}):
mock = MagicMock(side_effect=[True, True, True, False, True, True])
with patch.object(os.path, 'exists', mock):
ret.update({'comment': "pip requirements file"
" 'salt://a' not found"})
self.assertDictEqual(virtualenv_mod.managed('salt', None,
'salt://a'), ret)
with patch.dict(virtualenv_mod.__opts__, {"test": True}):
ret.update({'changes': {'cleared_packages': 'True',
'old': 'True'},
'comment': 'Virtualenv salt is set to'
' be cleared', 'result': None})
self.assertDictEqual(virtualenv_mod.managed('salt',
clear=1), ret)
ret.update({'comment': 'Virtualenv salt is already'
' created', 'changes': {},
'result': True})
self.assertDictEqual(virtualenv_mod.managed('salt'), ret)
ret.update({'comment': 'Virtualenv salt is set to'
' be created', 'result': None})
self.assertDictEqual(virtualenv_mod.managed('salt'), ret)
with patch.dict(virtualenv_mod.__opts__, {"test": False}):
ret.update({'comment': "The 'use_wheel' option is"
" only supported in pip between 1.4 and 9.0.3."
" The version of pip detected was 1.1.",
'result': False})
self.assertDictEqual(virtualenv_mod.managed('salt',
use_wheel=1),
ret)
ret.update({'comment': 'virtualenv exists',
'result': True})
self.assertDictEqual(virtualenv_mod.managed('salt'), ret)