Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cp.push test #39362

Merged
merged 1 commit into from
Feb 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/unit/modules/cp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from salttesting import skipIf, TestCase
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import (
Mock,
MagicMock,
mock_open,
patch,
Expand Down Expand Up @@ -130,6 +131,34 @@ def test_push_dir_non_absolute_path(self):

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
Expand Down