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