1
0

test_keyboard.py 2.0 KB

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