salt/tests/unit/modules/test_rsync.py

56 lines
1.8 KiB
Python
Raw Normal View History

2015-05-06 12:01:04 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
'''
# Import Python libs
from __future__ import absolute_import, unicode_literals
2015-05-06 12:01:04 +00:00
# Import Salt Testing Libs
2017-03-21 17:57:27 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.mock import (
2015-05-06 12:01:04 +00:00
NO_MOCK,
NO_MOCK_REASON,
MagicMock,
patch)
# Import Salt Libs
import salt.modules.rsync as rsync
from salt.exceptions import CommandExecutionError, SaltInvocationError
2015-05-06 12:01:04 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-03-21 17:57:27 +00:00
class RsyncTestCase(TestCase, LoaderModuleMockMixin):
2015-05-06 12:01:04 +00:00
'''
Test cases for salt.modules.rsync
'''
def setup_loader_modules(self):
return {rsync: {}}
2017-03-21 17:57:27 +00:00
2015-05-06 12:01:04 +00:00
def test_rsync(self):
'''
Test for rsync files from src to dst
'''
with patch.dict(rsync.__salt__, {'config.option':
MagicMock(return_value=False)}):
self.assertRaises(SaltInvocationError, rsync.rsync, '', '')
2015-05-06 12:01:04 +00:00
with patch.dict(rsync.__salt__,
{'config.option': MagicMock(return_value='A'),
'cmd.run_all': MagicMock(side_effect=[OSError(1, 'f'),
2015-05-06 12:01:04 +00:00
'A'])}):
with patch.object(rsync, '_check', return_value=['A']):
2015-05-06 12:01:04 +00:00
self.assertRaises(CommandExecutionError, rsync.rsync, 'a', 'b')
self.assertEqual(rsync.rsync('src', 'dst'), 'A')
def test_version(self):
'''
Test for return rsync version
'''
mock = MagicMock(side_effect=[OSError(1, 'f'), 'A B C\n'])
with patch.dict(rsync.__salt__, {'cmd.run_stdout': mock}):
2015-05-06 12:01:04 +00:00
self.assertRaises(CommandExecutionError, rsync.version)
self.assertEqual(rsync.version(), 'C')