Ejemplo n.º 1
0
    def test_get_chunk_info_matchfail(self, monkeypatch: MonkeyPatch):
        def listdir(path):
            return ["foo", "bar"]

        scput = SplitCopyPut()
        scput.scs = MockSplitCopyShared()
        scput.local_file = "somefile"
        monkeypatch.setattr("os.listdir", listdir)
        with raises(SystemExit):
            scput.get_chunk_info()
Ejemplo n.º 2
0
    def test_validate_remote_path_put_isdir(self):
        class MockSSHShell2(MockSSHShell):
            def run(cmd):
                return (True, "")

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        scput.local_file = "foo"
        scput.remote_path = "/var/tmp"
        result = scput.validate_remote_path_put()
        assert result == None
Ejemplo n.º 3
0
    def test_validate_remote_path_existingfile_basename_match(self):
        class MockSSHShell2(MockSSHShell):
            def run(cmd):
                if re.match(r"test -d", cmd):
                    return False, ""
                else:
                    return True, ""

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        scput.local_file = "foo"
        scput.remote_path = "/var/tmp/foo"
        result = scput.validate_remote_path_put()
        assert result == None
Ejemplo n.º 4
0
    def test_get_chunk_info(self, monkeypatch: MonkeyPatch):
        def listdir(path):
            return ["somefile_aa", "somefile_ab"]

        def stat(*args):
            stat.st_size = 10000
            return stat

        scput = SplitCopyPut()
        scput.scs = MockSplitCopyShared()
        scput.local_file = "somefile"
        monkeypatch.setattr("os.listdir", listdir)
        monkeypatch.setattr("os.stat", stat)
        result = scput.get_chunk_info()
        assert result == [["somefile_aa", 10000], ["somefile_ab", 10000]]
Ejemplo n.º 5
0
    def test_validate_remote_path_put_fail(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(cmd):
                return (False, "")

        def dirname(path):
            return "/var/tmp"

        monkeypatch.setattr("os.path.dirname", dirname)
        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        scput.scs = MockSplitCopyShared()
        scput.local_file = "foo"
        scput.remote_path = "/var/tmp/foo"
        with raises(SystemExit):
            scput.validate_remote_path_put()
Ejemplo n.º 6
0
    def test_validate_remote_path_put_newfile_basename_nomatch(self):
        class MockSSHShell2(MockSSHShell):
            self.instance = 0

            def run(cmd):
                if re.match(r"test -d", cmd) and not self.instance:
                    self.instance += 1
                    return False, ""
                elif re.match(r"test -d", cmd):
                    return True, ""
                else:
                    return False, ""

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        scput.local_file = "foo"
        scput.remote_path = "/var/tmp/bar"
        result = scput.validate_remote_path_put()
        assert result == None