mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #23377 from rahulhan/states_xmpp_test
Adding states/xmpp.py unit tests
This commit is contained in:
commit
430f080a3a
1 changed files with 58 additions and 0 deletions
58
tests/unit/states/xmpp_test.py
Normal file
58
tests/unit/states/xmpp_test.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: :email:`Rahul Handay <rahulha@saltstack.com>`
|
||||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from salttesting import TestCase, skipIf
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
from salttesting.mock import (
|
||||
MagicMock,
|
||||
patch,
|
||||
NO_MOCK,
|
||||
NO_MOCK_REASON
|
||||
)
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.states import xmpp
|
||||
|
||||
# Globals
|
||||
xmpp.__salt__ = {}
|
||||
xmpp.__opts__ = {}
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class XmppTestCase(TestCase):
|
||||
'''
|
||||
Validate the xmpp state
|
||||
'''
|
||||
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)
|
||||
with patch.dict(xmpp.__salt__, {"xmpp.send_msg": mock}):
|
||||
ret.update({'result': True,
|
||||
'comment': 'Sent message to myaccount: salt'})
|
||||
self.assertDictEqual(xmpp.send_msg('salt', 'myaccount',
|
||||
'salt@saltstack.com'), ret)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(XmppTestCase, needs_daemon=False)
|
Loading…
Add table
Reference in a new issue