salt/tests/unit/states/test_eselect.py

49 lines
1.3 KiB
Python
Raw Normal View History

2015-04-30 10:19:02 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
'''
# Import Python libs
from __future__ import absolute_import
# Import Salt Testing Libs
2017-03-22 16:42:17 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.mock import (
2015-04-30 10:19:02 +00:00
NO_MOCK,
NO_MOCK_REASON,
MagicMock,
patch)
# Import Salt Libs
import salt.states.eselect as eselect
2015-04-30 10:19:02 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-03-22 16:42:17 +00:00
class EselectTestCase(TestCase, LoaderModuleMockMixin):
2015-04-30 10:19:02 +00:00
'''
Test cases for salt.states.eselect
'''
2017-03-22 16:42:17 +00:00
def setup_loader_modules(self):
return {eselect: {}}
2015-04-30 10:19:02 +00:00
# 'set_' function tests: 1
def test_set_(self):
'''
Test to verify that the given module is set to the given target
'''
name = 'myeselect'
target = 'hardened/linux/amd64'
ret = {'name': name,
'result': True,
'comment': '',
'changes': {}}
mock = MagicMock(return_value=target)
with patch.dict(eselect.__salt__, {'eselect.get_current_target': mock}):
comt = ('Target \'{0}\' is already set on \'{1}\' module.'
2015-04-30 10:19:02 +00:00
.format(target, name))
ret.update({'comment': comt})
self.assertDictEqual(eselect.set_(name, target), ret)