mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #39362 from dincamihai/cp-push-test-2016.3
Add cp.push test
This commit is contained in:
commit
8b8ab8ef8e
1 changed files with 29 additions and 0 deletions
|
@ -15,6 +15,7 @@ from salt.exceptions import CommandExecutionError
|
|||
from salttesting import skipIf, TestCase
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
from salttesting.mock import (
|
||||
Mock,
|
||||
MagicMock,
|
||||
mock_open,
|
||||
patch,
|
||||
|
@ -130,6 +131,34 @@ class CpTestCase(TestCase):
|
|||
|
||||
self.assertEqual(cp.push_dir(path), ret)
|
||||
|
||||
@patch(
|
||||
'salt.modules.cp.os.path',
|
||||
MagicMock(isfile=Mock(return_value=True), wraps=cp.os.path))
|
||||
@patch.multiple(
|
||||
'salt.modules.cp',
|
||||
_auth=MagicMock(**{'return_value.gen_token.return_value': 'token'}),
|
||||
__opts__={'id': 'abc', 'file_buffer_size': 10})
|
||||
@patch('salt.utils.fopen', mock_open(read_data='content'))
|
||||
@patch('salt.transport.Channel.factory', MagicMock())
|
||||
def test_push(self):
|
||||
'''
|
||||
Test if push works with good posix path.
|
||||
'''
|
||||
import salt
|
||||
response = cp.push('/saltines/test.file')
|
||||
self.assertEqual(response, True)
|
||||
self.assertEqual(salt.utils.fopen().read.call_count, 2)
|
||||
salt.transport.Channel.factory({}).send.assert_called_once_with(
|
||||
dict(
|
||||
loc=salt.utils.fopen().tell(),
|
||||
cmd='_file_recv',
|
||||
tok='token',
|
||||
path=('saltines', 'test.file'),
|
||||
data='', # data is empty here because load['data'] is overwritten
|
||||
id='abc'
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
|
Loading…
Add table
Reference in a new issue