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