2015-02-03 06:34:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
|
|
|
'''
|
|
|
|
|
2015-02-03 18:40:27 +00:00
|
|
|
# Import Python Libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2015-02-03 06:34:47 +00:00
|
|
|
# Import Salt Testing Libs
|
2017-02-19 15:35:30 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase, skipIf
|
|
|
|
from tests.support.mock import (
|
2015-02-03 06:34:47 +00:00
|
|
|
MagicMock,
|
|
|
|
patch,
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.keyboard as keyboard
|
2015-02-03 06:34:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-02-19 15:35:30 +00:00
|
|
|
class KeyboardTestCase(TestCase, LoaderModuleMockMixin):
|
2015-02-03 06:34:47 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.modules.keyboard
|
|
|
|
'''
|
2017-03-22 12:12:36 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {keyboard: {}}
|
|
|
|
|
2015-02-03 06:34:47 +00:00
|
|
|
# 'get_sys' function tests: 1
|
|
|
|
|
|
|
|
def test_get_sys(self):
|
|
|
|
'''
|
|
|
|
Test if it get current system keyboard setting
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value='X11 Layout=us')
|
2017-04-04 02:05:59 +00:00
|
|
|
with patch.dict(keyboard.__grains__, {'os_family': 'RedHat'}):
|
|
|
|
with patch.dict(keyboard.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertEqual(keyboard.get_sys(), 'us')
|
2015-02-03 06:34:47 +00:00
|
|
|
|
|
|
|
# 'set_sys' function tests: 1
|
|
|
|
|
|
|
|
def test_set_sys(self):
|
|
|
|
'''
|
|
|
|
Test if it set current system keyboard setting
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value='us')
|
2017-04-04 02:05:59 +00:00
|
|
|
with patch.dict(keyboard.__grains__, {'os_family': 'RedHat'}):
|
|
|
|
with patch.dict(keyboard.__salt__, {'cmd.run': mock}):
|
|
|
|
with patch.dict(keyboard.__salt__, {'file.sed': MagicMock()}):
|
|
|
|
self.assertEqual(keyboard.set_sys('us'), 'us')
|
2015-02-03 06:34:47 +00:00
|
|
|
|
|
|
|
# 'get_x' function tests: 1
|
|
|
|
|
|
|
|
def test_get_x(self):
|
|
|
|
'''
|
|
|
|
Test if it get current X keyboard setting
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value='layout: us')
|
|
|
|
with patch.dict(keyboard.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertEqual(keyboard.get_x(), 'us')
|
|
|
|
|
|
|
|
# 'set_x' function tests: 1
|
|
|
|
|
|
|
|
def test_set_x(self):
|
|
|
|
'''
|
|
|
|
Test if it set current X keyboard setting
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value='us')
|
|
|
|
with patch.dict(keyboard.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertEqual(keyboard.set_x('us'), 'us')
|