2015-05-05 15:20:20 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Rahul Handay <rahulha@saltstack.com>`
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-03-22 16:42:17 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase, skipIf
|
|
|
|
from tests.support.mock import (
|
2015-05-05 15:20:20 +00:00
|
|
|
MagicMock,
|
|
|
|
patch,
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.states.xmpp as xmpp
|
2015-05-05 15:20:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-03-22 16:42:17 +00:00
|
|
|
class XmppTestCase(TestCase, LoaderModuleMockMixin):
|
2015-05-05 15:20:20 +00:00
|
|
|
'''
|
|
|
|
Validate the xmpp state
|
|
|
|
'''
|
2017-03-22 16:42:17 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {xmpp: {}}
|
|
|
|
|
2015-05-05 15:20:20 +00:00
|
|
|
def test_send_msg(self):
|
|
|
|
'''
|
|
|
|
Test to send a message to an XMPP user
|
|
|
|
'''
|
|
|
|
ret = {'name': 'salt',
|
|
|
|
'changes': {},
|
|
|
|
'result': None,
|
|
|
|
'comment': ''}
|
|
|
|
with patch.dict(xmpp.__opts__, {"test": True}):
|
|
|
|
ret.update({'comment': 'Need to send message to myaccount: salt'})
|
|
|
|
self.assertDictEqual(xmpp.send_msg('salt', 'myaccount',
|
|
|
|
'salt@saltstack.com'), ret)
|
|
|
|
|
|
|
|
with patch.dict(xmpp.__opts__, {"test": False}):
|
|
|
|
mock = MagicMock(return_value=True)
|
2015-05-06 20:40:46 +00:00
|
|
|
with patch.dict(xmpp.__salt__, {'xmpp.send_msg': mock,
|
|
|
|
'xmpp.send_msg_multi': mock}):
|
2015-05-05 15:20:20 +00:00
|
|
|
ret.update({'result': True,
|
|
|
|
'comment': 'Sent message to myaccount: salt'})
|
|
|
|
self.assertDictEqual(xmpp.send_msg('salt', 'myaccount',
|
|
|
|
'salt@saltstack.com'), ret)
|