Exemple #1
0
    def test_get(self, monkeypatch: MonkeyPatch):
        scget = SplitCopyGet()
        scget.scs = MockSplitCopyShared()
        scget.progress = MockProgress()

        def validate_remote_path_get():
            pass

        def delete_target_local():
            pass

        def remote_filesize():
            return 1000000

        def remote_sha_get():
            return "abcdef012345"

        def split_file_remote(scp_lib, file_size, split_size, remote_tmpdir):
            pass

        def get_chunk_info(remote_tmpdir):
            return [["a", 1234], ["b", 1234], ["c", 1234]]

        def get_files(ftp_lib, ssh_lib, scp_lib, chunk, remote_tmpdir,
                      ssh_kwargs):
            return None

        def join_files_local():
            pass

        def local_sha_get(hash):
            pass

        def inc_percentage():
            for n in range(90, 101):
                time.sleep(0.1)
                scget.progress.totals["percent_done"] = n

        monkeypatch.setattr(scget, "validate_remote_path_get",
                            validate_remote_path_get)
        monkeypatch.setattr(scget, "delete_target_local", delete_target_local)
        monkeypatch.setattr(scget, "remote_filesize", remote_filesize)
        monkeypatch.setattr(scget, "remote_sha_get", remote_sha_get)
        monkeypatch.setattr(scget, "split_file_remote", split_file_remote)
        monkeypatch.setattr(scget, "get_chunk_info", get_chunk_info)
        monkeypatch.setattr(scget, "get_files", get_files)
        monkeypatch.setattr(scget, "join_files_local", join_files_local)
        monkeypatch.setattr(scget, "local_sha_get", local_sha_get)
        thread = Thread(
            name="inc_percentage_done",
            target=inc_percentage,
        )
        thread.start()
        result = scget.get()
        thread.join()

        assert isinstance(result[0], datetime.datetime), isinstance(
            result[1], datetime.datetime)
Exemple #2
0
    def test_get_files_scp(self):
        scget = SplitCopyGet()
        scget.progress = MockProgress()
        scget.copy_proto = "scp"

        result = scget.get_files(
            MockFTP,
            MockSSHShell,
            MockSCPClient,
            ["chunk0", 1999],
            "/var/tmp/foo",
            {},
        )
        assert result == None
Exemple #3
0
    def test_get_files_scp_authfail(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def worker_thread_auth(self):
                return False

        def sleep(secs):
            pass

        monkeypatch.setattr("time.sleep", sleep)
        scget = SplitCopyGet()
        scget.progress = MockProgress()
        scget.copy_proto = "scp"
        with raises(TransferError):
            scget.get_files(MockFTP, MockSSHShell2, MockSCPClient,
                            ["chunk0", 1999], "/tmp/", {})
Exemple #4
0
    def test_get_files_scp_fail(self, monkeypatch: MonkeyPatch):
        class MockSCPClient2(MockSCPClient):
            def get(self, *args):
                raise SCPException

        def sleep(secs):
            pass

        monkeypatch.setattr("time.sleep", sleep)
        scget = SplitCopyGet()
        scget.progress = MockProgress()
        scget.copy_proto = "scp"
        with raises(TransferError):
            scget.get_files(MockFTP, MockSSHShell, MockSCPClient2,
                            ["chunk0", 1999], "/tmp/", {})
Exemple #5
0
    def test_get_files_ftp_filenotfound_fail(self, monkeypatch: MonkeyPatch):
        class MockFTP2(MockFTP):
            def get(self, *args):
                raise error_proto

        def sleep(secs):
            pass

        monkeypatch.setattr("time.sleep", sleep)
        scget = SplitCopyGet()
        scget.progress = MockProgress()
        scget.copy_proto = "ftp"
        with raises(TransferError):
            scget.get_files(MockFTP2, MockSSHShell, MockSCPClient,
                            ["chunk0", 1999], "/tmp/", {})
Exemple #6
0
    def test_get_files_ftp_fail(self, monkeypatch: MonkeyPatch):
        class MockFTP2(MockFTP):
            def get(self, *args):
                raise error_proto

        def sleep(secs):
            pass

        def stat(*args):
            stat.st_size = 10000
            stat.st_mode = 1
            stat.st_mtime = None
            return stat

        monkeypatch.setattr("time.sleep", sleep)
        monkeypatch.setattr("os.stat", stat)
        scget = SplitCopyGet()
        scget.progress = MockProgress()
        scget.copy_proto = "ftp"
        with raises(TransferError):
            scget.get_files(MockFTP2, MockSSHShell, MockSCPClient,
                            ["chunk0", 1999], "/tmp/", {})
Exemple #7
0
    def test_get_fail(self, monkeypatch: MonkeyPatch):
        def validate_remote_path_get():
            pass

        def delete_target_local():
            pass

        def remote_filesize():
            return 1000000

        def remote_sha_get():
            return "abcdef012345"

        def split_file_remote(scp_lib, file_size, split_size, remote_tmpdir):
            pass

        def get_chunk_info(remote_tmpdir):
            return [["a", 1234], ["b", 1234], ["c", 1234]]

        def get_files(ftp_lib, ssh_lib, scp_lib, chunk, remote_tmpdir,
                      ssh_kwargs):
            raise TransferError

        scget = SplitCopyGet()
        scget.scs = MockSplitCopyShared()
        scget.progress = MockProgress()
        monkeypatch.setattr(scget, "validate_remote_path_get",
                            validate_remote_path_get)
        monkeypatch.setattr(scget, "delete_target_local", delete_target_local)
        monkeypatch.setattr(scget, "remote_filesize", remote_filesize)
        monkeypatch.setattr(scget, "remote_sha_get", remote_sha_get)
        monkeypatch.setattr(scget, "split_file_remote", split_file_remote)
        monkeypatch.setattr(scget, "get_chunk_info", get_chunk_info)
        monkeypatch.setattr(scget, "get_files", get_files)

        with raises(SystemExit):
            scget.get()