test_rdp.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  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.states.rdp as rdp
  16. class RdpTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test cases for salt.states.rdp
  19. '''
  20. def setup_loader_modules(self):
  21. return {rdp: {}}
  22. # 'enabled' function tests: 1
  23. def test_enabled(self):
  24. '''
  25. Test to enable the RDP service and make sure access
  26. to the RDP port is allowed in the firewall configuration.
  27. '''
  28. name = 'my_service'
  29. ret = {'name': name,
  30. 'changes': {},
  31. 'result': True,
  32. 'comment': ''}
  33. mock_t = MagicMock(side_effect=[False, False, True])
  34. mock_f = MagicMock(return_value=False)
  35. with patch.dict(rdp.__salt__,
  36. {'rdp.status': mock_t,
  37. 'rdp.enable': mock_f}):
  38. with patch.dict(rdp.__opts__, {'test': True}):
  39. comt = ('RDP will be enabled')
  40. ret.update({'comment': comt, 'result': None})
  41. self.assertDictEqual(rdp.enabled(name), ret)
  42. with patch.dict(rdp.__opts__, {'test': False}):
  43. ret.update({'comment': '', 'result': False,
  44. 'changes': {'RDP was enabled': True}})
  45. self.assertDictEqual(rdp.enabled(name), ret)
  46. comt = ('RDP is enabled')
  47. ret.update({'comment': comt, 'result': True,
  48. 'changes': {}})
  49. self.assertDictEqual(rdp.enabled(name), ret)
  50. # 'disabled' function tests: 1
  51. def test_disabled(self):
  52. '''
  53. Test to disable the RDP service.
  54. '''
  55. name = 'my_service'
  56. ret = {'name': name,
  57. 'changes': {},
  58. 'result': True,
  59. 'comment': ''}
  60. mock = MagicMock(side_effect=[True, True, False])
  61. mock_t = MagicMock(return_value=True)
  62. with patch.dict(rdp.__salt__,
  63. {'rdp.status': mock,
  64. 'rdp.disable': mock_t}):
  65. with patch.dict(rdp.__opts__, {'test': True}):
  66. comt = ('RDP will be disabled')
  67. ret.update({'comment': comt, 'result': None})
  68. self.assertDictEqual(rdp.disabled(name), ret)
  69. with patch.dict(rdp.__opts__, {'test': False}):
  70. ret.update({'comment': '', 'result': True,
  71. 'changes': {'RDP was disabled': True}})
  72. self.assertDictEqual(rdp.disabled(name), ret)
  73. comt = ('RDP is disabled')
  74. ret.update({'comment': comt, 'result': True, 'changes': {}})
  75. self.assertDictEqual(rdp.disabled(name), ret)