test_xmpp.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Rahul Handay <rahulha@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.xmpp as xmpp
  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 XmppTestCase(TestCase, LoaderModuleMockMixin):
  14. """
  15. Validate the xmpp state
  16. """
  17. def setup_loader_modules(self):
  18. return {xmpp: {}}
  19. def test_send_msg(self):
  20. """
  21. Test to send a message to an XMPP user
  22. """
  23. ret = {"name": "salt", "changes": {}, "result": None, "comment": ""}
  24. with patch.dict(xmpp.__opts__, {"test": True}):
  25. ret.update({"comment": "Need to send message to myaccount: salt"})
  26. self.assertDictEqual(
  27. xmpp.send_msg("salt", "myaccount", "salt@saltstack.com"), ret
  28. )
  29. with patch.dict(xmpp.__opts__, {"test": False}):
  30. mock = MagicMock(return_value=True)
  31. with patch.dict(
  32. xmpp.__salt__, {"xmpp.send_msg": mock, "xmpp.send_msg_multi": mock}
  33. ):
  34. ret.update(
  35. {"result": True, "comment": "Sent message to myaccount: salt"}
  36. )
  37. self.assertDictEqual(
  38. xmpp.send_msg("salt", "myaccount", "salt@saltstack.com"), ret
  39. )