Bug 1383996 - Make most calls to `mach artifact toolchain` output a manifest. r=gps
[gecko.git] / testing / mozharness / test / test_base_transfer.py
blobf3f907254d4e35caabb4cf640d46b3e1203eb949
1 import unittest
2 import mock
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):
12 return exe
14 def info(self, msg):
15 pass
17 def log(self, msg, level):
18 pass
20 def run_command(*args, **kwargs):
21 return 0
24 class BadMockMixin(GoodMockMixin):
25 def run_command(*args, **kwargs):
26 return 1
29 class GoodTransferMixin(TransferMixin, GoodMockMixin):
30 pass
33 class BadTransferMixin(TransferMixin, BadMockMixin):
34 pass
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(
44 local_path='',
45 ssh_key='my ssh key',
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(
56 local_path='',
57 ssh_key='my ssh key',
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(
69 local_path='',
70 ssh_key='my ssh key',
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(
82 local_path='',
83 ssh_key='my ssh key',
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(
95 local_path='',
96 ssh_key='my ssh key',
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):
103 # successful rsync
104 os_mock.path.isdir.return_value = True
105 tm = GoodTransferMixin()
106 self.assertEqual(tm.rsync_download_directory(
107 local_path='',
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(
119 local_path='',
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__':
127 unittest.main()