test_rdp.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.rdp as rdp
  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 RdpTestCase(TestCase, LoaderModuleMockMixin):
  14. """
  15. Test cases for salt.modules.rdp
  16. """
  17. def setup_loader_modules(self):
  18. return {rdp: {}}
  19. # 'enable' function tests: 1
  20. def test_enable(self):
  21. """
  22. Test if it enables RDP the service on the server
  23. """
  24. mock = MagicMock(return_value=True)
  25. with patch.dict(rdp.__salt__, {"cmd.run": mock}), patch(
  26. "salt.modules.rdp._parse_return_code_powershell", MagicMock(return_value=0)
  27. ):
  28. self.assertTrue(rdp.enable())
  29. # 'disable' function tests: 1
  30. def test_disable(self):
  31. """
  32. Test if it disables RDP the service on the server
  33. """
  34. mock = MagicMock(return_value=True)
  35. with patch.dict(rdp.__salt__, {"cmd.run": mock}), patch(
  36. "salt.modules.rdp._parse_return_code_powershell", MagicMock(return_value=0)
  37. ):
  38. self.assertTrue(rdp.disable())
  39. # 'status' function tests: 1
  40. def test_status(self):
  41. """
  42. Test if it shows rdp is enabled on the server
  43. """
  44. mock = MagicMock(return_value="1")
  45. with patch.dict(rdp.__salt__, {"cmd.run": mock}):
  46. self.assertTrue(rdp.status())