2015-05-12 12:35:35 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2018-05-28 21:13:12 +00:00
|
|
|
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
|
2015-05-12 12:35:35 +00:00
|
|
|
'''
|
|
|
|
# Import Python libs
|
2018-01-26 13:09:58 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2015-05-12 12:35:35 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-03-22 16:42:17 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf, TestCase
|
|
|
|
from tests.support.mock import (
|
2015-05-12 12:35:35 +00:00
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON,
|
|
|
|
MagicMock,
|
|
|
|
patch)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.states.layman as layman
|
2015-05-12 12:35:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-03-22 16:42:17 +00:00
|
|
|
class LaymanTestCase(TestCase, LoaderModuleMockMixin):
|
2015-05-12 12:35:35 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.states.layman
|
|
|
|
'''
|
2017-03-22 16:42:17 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {layman: {}}
|
|
|
|
|
2015-05-12 12:35:35 +00:00
|
|
|
# 'present' function tests: 1
|
|
|
|
|
|
|
|
def test_present(self):
|
|
|
|
'''
|
|
|
|
Test to verify that the overlay is present.
|
|
|
|
'''
|
|
|
|
name = 'sunrise'
|
|
|
|
|
|
|
|
ret = {'name': name,
|
|
|
|
'result': True,
|
|
|
|
'comment': '',
|
|
|
|
'changes': {}}
|
|
|
|
|
|
|
|
mock = MagicMock(side_effect=[[name], []])
|
|
|
|
with patch.dict(layman.__salt__, {'layman.list_local': mock}):
|
|
|
|
comt = ('Overlay {0} already present'.format(name))
|
|
|
|
ret.update({'comment': comt})
|
|
|
|
self.assertDictEqual(layman.present(name), ret)
|
|
|
|
|
|
|
|
with patch.dict(layman.__opts__, {'test': True}):
|
|
|
|
comt = ('Overlay {0} is set to be added'.format(name))
|
|
|
|
ret.update({'comment': comt, 'result': None})
|
|
|
|
self.assertDictEqual(layman.present(name), ret)
|
|
|
|
|
|
|
|
# 'absent' function tests: 1
|
|
|
|
|
|
|
|
def test_absent(self):
|
|
|
|
'''
|
|
|
|
Test to verify that the overlay is absent.
|
|
|
|
'''
|
|
|
|
name = 'sunrise'
|
|
|
|
|
|
|
|
ret = {'name': name,
|
|
|
|
'result': True,
|
|
|
|
'comment': '',
|
|
|
|
'changes': {}}
|
|
|
|
|
|
|
|
mock = MagicMock(side_effect=[[], [name]])
|
|
|
|
with patch.dict(layman.__salt__, {'layman.list_local': mock}):
|
|
|
|
comt = ('Overlay {0} already absent'.format(name))
|
|
|
|
ret.update({'comment': comt})
|
|
|
|
self.assertDictEqual(layman.absent(name), ret)
|
|
|
|
|
|
|
|
with patch.dict(layman.__opts__, {'test': True}):
|
|
|
|
comt = ('Overlay {0} is set to be deleted'.format(name))
|
|
|
|
ret.update({'comment': comt, 'result': None})
|
|
|
|
self.assertDictEqual(layman.absent(name), ret)
|