4 from mozharness
.base
.transfer
import TransferMixin
7 class GoodMockMixin(object):
8 def query_abs_dirs(self
):
9 return {'abs_work_dir': ''}
11 def query_exe(self
, exe
):
17 def log(self
, msg
, level
):
20 def run_command(*args
, **kwargs
):
24 class BadMockMixin(GoodMockMixin
):
25 def run_command(*args
, **kwargs
):
29 class GoodTransferMixin(TransferMixin
, GoodMockMixin
):
33 class BadTransferMixin(TransferMixin
, BadMockMixin
):
37 class TestTranferMixin(unittest
.TestCase
):
38 @mock.patch('mozharness.base.transfer.os')
39 def test_rsync_upload_dir_not_a_dir(self
, os_mock
):
40 # simulates upload dir but dir is a file
41 os_mock
.path
.isdir
.return_value
= False
42 tm
= GoodTransferMixin()
43 self
.assertEqual(tm
.rsync_upload_directory(
46 ssh_user
='my ssh user',
47 remote_host
='remote host',
48 remote_path
='remote path',), -1)
50 @mock.patch('mozharness.base.transfer.os')
51 def test_rsync_upload_fails_create_remote_dir(self
, os_mock
):
52 # we cannot create the remote directory
53 os_mock
.path
.isdir
.return_value
= True
54 tm
= BadTransferMixin()
55 self
.assertEqual(tm
.rsync_upload_directory(
58 ssh_user
='my ssh user',
59 remote_host
='remote host',
60 remote_path
='remote path',
61 create_remote_directory
=True), -2)
63 @mock.patch('mozharness.base.transfer.os')
64 def test_rsync_upload_fails_do_not_create_remote_dir(self
, os_mock
):
65 # upload fails, remote directory is not created
66 os_mock
.path
.isdir
.return_value
= True
67 tm
= BadTransferMixin()
68 self
.assertEqual(tm
.rsync_upload_directory(
71 ssh_user
='my ssh user',
72 remote_host
='remote host',
73 remote_path
='remote path',
74 create_remote_directory
=False), -3)
76 @mock.patch('mozharness.base.transfer.os')
77 def test_rsync_upload(self
, os_mock
):
78 # simulates an upload with no errors
79 os_mock
.path
.isdir
.return_value
= True
80 tm
= GoodTransferMixin()
81 self
.assertEqual(tm
.rsync_upload_directory(
84 ssh_user
='my ssh user',
85 remote_host
='remote host',
86 remote_path
='remote path',
87 create_remote_directory
=False), None)
89 @mock.patch('mozharness.base.transfer.os')
90 def test_rsync_download_in_not_a_dir(self
, os_mock
):
91 # local path is not a directory
92 os_mock
.path
.isdir
.return_value
= False
93 tm
= GoodTransferMixin()
94 self
.assertEqual(tm
.rsync_download_directory(
97 ssh_user
='my ssh user',
98 remote_host
='remote host',
99 remote_path
='remote path',), -1)
101 @mock.patch('mozharness.base.transfer.os')
102 def test_rsync_download(self
, os_mock
):
104 os_mock
.path
.isdir
.return_value
= True
105 tm
= GoodTransferMixin()
106 self
.assertEqual(tm
.rsync_download_directory(
108 ssh_key
='my ssh key',
109 ssh_user
='my ssh user',
110 remote_host
='remote host',
111 remote_path
='remote path',), None)
113 @mock.patch('mozharness.base.transfer.os')
114 def test_rsync_download_fail(self
, os_mock
):
115 # ops download has failed
116 os_mock
.path
.isdir
.return_value
= True
117 tm
= BadTransferMixin()
118 self
.assertEqual(tm
.rsync_download_directory(
120 ssh_key
='my ssh key',
121 ssh_user
='my ssh user',
122 remote_host
='remote host',
123 remote_path
='remote path',), -3)
126 if __name__
== '__main__':