test_rabbitmq_vhost.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_vhost as rabbitmq_vhost
  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 RabbitmqVhostTestCase(TestCase, LoaderModuleMockMixin):
  14. """
  15. Test cases for salt.states.rabbitmq_vhost
  16. """
  17. def setup_loader_modules(self):
  18. return {rabbitmq_vhost: {}}
  19. # 'present' function tests: 1
  20. def test_present(self):
  21. """
  22. Test to ensure the RabbitMQ VHost exists.
  23. """
  24. name = "virtual_host"
  25. ret = {
  26. "name": name,
  27. "changes": {"new": "virtual_host", "old": ""},
  28. "result": None,
  29. "comment": "Virtual Host 'virtual_host' will be created.",
  30. }
  31. mock = MagicMock(return_value=False)
  32. with patch.dict(rabbitmq_vhost.__salt__, {"rabbitmq.vhost_exists": mock}):
  33. with patch.dict(rabbitmq_vhost.__opts__, {"test": True}):
  34. self.assertDictEqual(rabbitmq_vhost.present(name), ret)
  35. # 'absent' function tests: 1
  36. def test_absent(self):
  37. """
  38. Test to ensure the named user is absent.
  39. """
  40. name = "myqueue"
  41. ret = {
  42. "name": name,
  43. "changes": {},
  44. "result": True,
  45. "comment": "Virtual Host '{0}' is not present.".format(name),
  46. }
  47. mock = MagicMock(return_value=False)
  48. with patch.dict(rabbitmq_vhost.__salt__, {"rabbitmq.vhost_exists": mock}):
  49. self.assertDictEqual(rabbitmq_vhost.absent(name), ret)