test_keyboard.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase
  10. from tests.support.mock import (
  11. MagicMock,
  12. patch,
  13. )
  14. # Import Salt Libs
  15. import salt.modules.keyboard as keyboard
  16. class KeyboardTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test cases for salt.modules.keyboard
  19. '''
  20. def setup_loader_modules(self):
  21. return {keyboard: {}}
  22. # 'get_sys' function tests: 1
  23. def test_get_sys(self):
  24. '''
  25. Test if it get current system keyboard setting
  26. '''
  27. mock = MagicMock(return_value='X11 Layout=us')
  28. with patch.dict(keyboard.__grains__, {'os_family': 'RedHat'}):
  29. with patch.dict(keyboard.__salt__, {'cmd.run': mock}):
  30. self.assertEqual(keyboard.get_sys(), 'us')
  31. # 'set_sys' function tests: 1
  32. def test_set_sys(self):
  33. '''
  34. Test if it set current system keyboard setting
  35. '''
  36. mock = MagicMock(return_value='us')
  37. with patch.dict(keyboard.__grains__, {'os_family': 'RedHat'}):
  38. with patch.dict(keyboard.__salt__, {'cmd.run': mock}):
  39. with patch.dict(keyboard.__salt__, {'file.sed': MagicMock()}):
  40. self.assertEqual(keyboard.set_sys('us'), 'us')
  41. # 'get_x' function tests: 1
  42. def test_get_x(self):
  43. '''
  44. Test if it get current X keyboard setting
  45. '''
  46. mock = MagicMock(return_value='layout: us')
  47. with patch.dict(keyboard.__salt__, {'cmd.run': mock}):
  48. self.assertEqual(keyboard.get_x(), 'us')
  49. # 'set_x' function tests: 1
  50. def test_set_x(self):
  51. '''
  52. Test if it set current X keyboard setting
  53. '''
  54. mock = MagicMock(return_value='us')
  55. with patch.dict(keyboard.__salt__, {'cmd.run': mock}):
  56. self.assertEqual(keyboard.set_x('us'), 'us')