diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/mozharness/test/test_base_transfer.py | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mozharness/test/test_base_transfer.py')
-rw-r--r-- | testing/mozharness/test/test_base_transfer.py | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/testing/mozharness/test/test_base_transfer.py b/testing/mozharness/test/test_base_transfer.py new file mode 100644 index 000000000..f3f907254 --- /dev/null +++ b/testing/mozharness/test/test_base_transfer.py @@ -0,0 +1,127 @@ +import unittest +import mock + +from mozharness.base.transfer import TransferMixin + + +class GoodMockMixin(object): + def query_abs_dirs(self): + return {'abs_work_dir': ''} + + def query_exe(self, exe): + return exe + + def info(self, msg): + pass + + def log(self, msg, level): + pass + + def run_command(*args, **kwargs): + return 0 + + +class BadMockMixin(GoodMockMixin): + def run_command(*args, **kwargs): + return 1 + + +class GoodTransferMixin(TransferMixin, GoodMockMixin): + pass + + +class BadTransferMixin(TransferMixin, BadMockMixin): + pass + + +class TestTranferMixin(unittest.TestCase): + @mock.patch('mozharness.base.transfer.os') + def test_rsync_upload_dir_not_a_dir(self, os_mock): + # simulates upload dir but dir is a file + os_mock.path.isdir.return_value = False + tm = GoodTransferMixin() + self.assertEqual(tm.rsync_upload_directory( + local_path='', + ssh_key='my ssh key', + ssh_user='my ssh user', + remote_host='remote host', + remote_path='remote path',), -1) + + @mock.patch('mozharness.base.transfer.os') + def test_rsync_upload_fails_create_remote_dir(self, os_mock): + # we cannot create the remote directory + os_mock.path.isdir.return_value = True + tm = BadTransferMixin() + self.assertEqual(tm.rsync_upload_directory( + local_path='', + ssh_key='my ssh key', + ssh_user='my ssh user', + remote_host='remote host', + remote_path='remote path', + create_remote_directory=True), -2) + + @mock.patch('mozharness.base.transfer.os') + def test_rsync_upload_fails_do_not_create_remote_dir(self, os_mock): + # upload fails, remote directory is not created + os_mock.path.isdir.return_value = True + tm = BadTransferMixin() + self.assertEqual(tm.rsync_upload_directory( + local_path='', + ssh_key='my ssh key', + ssh_user='my ssh user', + remote_host='remote host', + remote_path='remote path', + create_remote_directory=False), -3) + + @mock.patch('mozharness.base.transfer.os') + def test_rsync_upload(self, os_mock): + # simulates an upload with no errors + os_mock.path.isdir.return_value = True + tm = GoodTransferMixin() + self.assertEqual(tm.rsync_upload_directory( + local_path='', + ssh_key='my ssh key', + ssh_user='my ssh user', + remote_host='remote host', + remote_path='remote path', + create_remote_directory=False), None) + + @mock.patch('mozharness.base.transfer.os') + def test_rsync_download_in_not_a_dir(self, os_mock): + # local path is not a directory + os_mock.path.isdir.return_value = False + tm = GoodTransferMixin() + self.assertEqual(tm.rsync_download_directory( + local_path='', + ssh_key='my ssh key', + ssh_user='my ssh user', + remote_host='remote host', + remote_path='remote path',), -1) + + @mock.patch('mozharness.base.transfer.os') + def test_rsync_download(self, os_mock): + # successful rsync + os_mock.path.isdir.return_value = True + tm = GoodTransferMixin() + self.assertEqual(tm.rsync_download_directory( + local_path='', + ssh_key='my ssh key', + ssh_user='my ssh user', + remote_host='remote host', + remote_path='remote path',), None) + + @mock.patch('mozharness.base.transfer.os') + def test_rsync_download_fail(self, os_mock): + # ops download has failed + os_mock.path.isdir.return_value = True + tm = BadTransferMixin() + self.assertEqual(tm.rsync_download_directory( + local_path='', + ssh_key='my ssh key', + ssh_user='my ssh user', + remote_host='remote host', + remote_path='remote path',), -3) + + +if __name__ == '__main__': + unittest.main() |