test_rabbitmq_plugin.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.rabbitmq_plugin as rabbitmq_plugin
  16. class RabbitmqPluginTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test cases for salt.states.rabbitmq_plugin
  19. '''
  20. def setup_loader_modules(self):
  21. return {rabbitmq_plugin: {}}
  22. # 'enabled' function tests: 1
  23. def test_enabled(self):
  24. '''
  25. Test to ensure the RabbitMQ plugin is enabled.
  26. '''
  27. name = 'some_plugin'
  28. ret = {'name': name,
  29. 'changes': {},
  30. 'result': True,
  31. 'comment': ''}
  32. mock = MagicMock(side_effect=[True, False])
  33. with patch.dict(rabbitmq_plugin.__salt__,
  34. {'rabbitmq.plugin_is_enabled': mock}):
  35. comment = "Plugin 'some_plugin' is already enabled."
  36. ret.update({'comment': comment})
  37. self.assertDictEqual(rabbitmq_plugin.enabled(name), ret)
  38. with patch.dict(rabbitmq_plugin.__opts__, {'test': True}):
  39. comment = "Plugin 'some_plugin' is set to be enabled."
  40. changes = {'new': 'some_plugin', 'old': ''}
  41. ret.update({'comment': comment, 'result': None, 'changes': changes})
  42. self.assertDictEqual(rabbitmq_plugin.enabled(name), ret)
  43. # 'disabled' function tests: 1
  44. def test_disabled(self):
  45. '''
  46. Test to ensure the RabbitMQ plugin is disabled.
  47. '''
  48. name = 'some_plugin'
  49. ret = {'name': name,
  50. 'changes': {},
  51. 'result': True,
  52. 'comment': ''}
  53. mock = MagicMock(side_effect=[False, True])
  54. with patch.dict(rabbitmq_plugin.__salt__,
  55. {'rabbitmq.plugin_is_enabled': mock}):
  56. comment = "Plugin 'some_plugin' is already disabled."
  57. ret.update({'comment': comment})
  58. self.assertDictEqual(rabbitmq_plugin.disabled(name), ret)
  59. with patch.dict(rabbitmq_plugin.__opts__, {'test': True}):
  60. comment = "Plugin 'some_plugin' is set to be disabled."
  61. changes = {'new': '', 'old': 'some_plugin'}
  62. ret.update({'comment': comment, 'result': None, 'changes': changes})
  63. self.assertDictEqual(rabbitmq_plugin.disabled(name), ret)