salt/tests/unit/states/test_vbox_guest.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

124 lines
5.0 KiB
Python

# -*- coding: utf-8 -*-
'''
:codeauthor: Rahul Handay <rahulha@saltstack.com>
'''
# Import Python Libs
from __future__ import absolute_import, unicode_literals, print_function
# 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.vbox_guest as vbox_guest
@skipIf(NO_MOCK, NO_MOCK_REASON)
class VboxGuestTestCase(TestCase, LoaderModuleMockMixin):
'''
Validate the vbox_guest state
'''
def setup_loader_modules(self):
return {vbox_guest: {}}
def test_additions_installed(self):
'''
Test to ensure that the VirtualBox Guest Additions are installed
'''
ret = {'name': 'salt',
'changes': {},
'result': True,
'comment': ''}
mock = MagicMock(side_effect=[True, False, False, False])
with patch.dict(vbox_guest.__salt__,
{"vbox_guest.additions_version": mock,
"vbox_guest.additions_install": mock}):
ret.update({'comment': 'System already in the correct state'})
self.assertDictEqual(vbox_guest.additions_installed('salt'), ret)
with patch.dict(vbox_guest.__opts__, {"test": True}):
ret.update({'changes': {'new': True, 'old': False},
'comment': 'The state of VirtualBox Guest'
' Additions will be changed.', 'result': None})
self.assertDictEqual(vbox_guest.additions_installed('salt'),
ret)
with patch.dict(vbox_guest.__opts__, {"test": False}):
ret.update({'changes': {'new': False, 'old': False},
'comment': 'The state of VirtualBox Guest'
' Additions was changed!', 'result': False})
self.assertDictEqual(vbox_guest.additions_installed('salt'),
ret)
def test_additions_removed(self):
'''
Test to ensure that the VirtualBox Guest Additions are removed.
'''
ret = {'name': 'salt',
'changes': {},
'result': True,
'comment': ''}
mock = MagicMock(side_effect=[False, True, True, True])
with patch.dict(vbox_guest.__salt__,
{"vbox_guest.additions_version": mock,
"vbox_guest.additions_remove": mock}):
ret.update({'comment': 'System already in the correct state'})
self.assertDictEqual(vbox_guest.additions_removed('salt'), ret)
with patch.dict(vbox_guest.__opts__, {"test": True}):
ret.update({'changes': {'new': True, 'old': True},
'comment': 'The state of VirtualBox Guest'
' Additions will be changed.', 'result': None})
self.assertDictEqual(vbox_guest.additions_removed('salt'),
ret)
with patch.dict(vbox_guest.__opts__, {"test": False}):
ret.update({'comment': 'The state of VirtualBox Guest'
' Additions was changed!', 'result': True})
self.assertDictEqual(vbox_guest.additions_removed('salt'),
ret)
def test_grantaccess_to_sharedfolders(self):
'''
Test to grant access to auto-mounted shared folders to the users.
'''
ret = {'name': 'AB',
'changes': {},
'result': True,
'comment': ''}
mock = MagicMock(side_effect=[['AB'], 'salt', 'salt', 'salt'])
with patch.dict(vbox_guest.__salt__,
{"vbox_guest.list_shared_folders_users": mock,
"vbox_guest.grant_access_to_shared_folders_to": mock}
):
ret.update({'comment': 'System already in the correct state'})
self.assert_method(ret)
with patch.dict(vbox_guest.__opts__, {"test": True}):
ret.update({'changes': {'new': ['AB'], 'old': 'salt'},
'comment': 'List of users who have access to'
' auto-mounted shared folders will be changed',
'result': None})
self.assert_method(ret)
with patch.dict(vbox_guest.__opts__, {"test": False}):
ret.update({'changes': {'new': 'salt', 'old': 'salt'},
'comment': 'List of users who have access to'
' auto-mounted shared folders was changed',
'result': True})
self.assert_method(ret)
def assert_method(self, ret):
'''
Method call for assert statements
'''
self.assertDictEqual(vbox_guest.grant_access_to_shared_folders_to('AB'),
ret)