Ejemplo n.º 1
0
    def test_local_sha_get_mismatch(self, monkeypatch: MonkeyPatch):
        class Mock512(MockHash):
            pass

        class Mock384(MockHash):
            pass

        class Mock256(MockHash):
            pass

        class Mock224(MockHash):
            pass

        class Mock1(MockHash):
            pass

        scget = SplitCopyGet()
        monkeypatch.setattr("builtins.open", MockOpen)
        monkeypatch.setattr("os.path.sep", "/")
        monkeypatch.setattr("hashlib.sha512", Mock512)
        monkeypatch.setattr("hashlib.sha384", Mock384)
        monkeypatch.setattr("hashlib.sha256", Mock256)
        monkeypatch.setattr("hashlib.sha224", Mock224)
        monkeypatch.setattr("hashlib.sha1", Mock1)
        scget.scs = MockSplitCopyShared()
        sha_hash = {
            512: "0bcdef0123456789",
        }
        scget.local_file = "foo"
        scget.local_dir = "/var/tmp"
        with raises(SystemExit):
            scget.local_sha_get(sha_hash)
Ejemplo n.º 2
0
    def test_delete_target_local(self, monkeypatch: MonkeyPatch):
        def exists(*args):
            return True

        def remove(*args):
            return True

        monkeypatch.setattr("os.path.exists", exists)
        monkeypatch.setattr("os.remove", remove)
        monkeypatch.setattr("os.path.sep", "/")
        scget = SplitCopyGet()
        scget.local_dir = "/var/tmp"
        scget.local_file = "foo"
        result = scget.delete_target_local()
        expected = None
        assert expected == result
Ejemplo n.º 3
0
    def test_local_sha_get(self, monkeypatch: MonkeyPatch):
        class MockHash:
            def __init__(self):
                pass

            def update(self, data):
                pass

            def hexdigest(self):
                return "abcdef0123456789"

        class Mock512(MockHash):
            pass

        class Mock384(MockHash):
            pass

        class Mock256(MockHash):
            pass

        class Mock224(MockHash):
            pass

        class Mock1(MockHash):
            pass

        scget = SplitCopyGet()
        monkeypatch.setattr("builtins.open", MockOpen)
        monkeypatch.setattr("os.path.sep", "/")
        monkeypatch.setattr("hashlib.sha512", Mock512)
        monkeypatch.setattr("hashlib.sha384", Mock384)
        monkeypatch.setattr("hashlib.sha256", Mock256)
        monkeypatch.setattr("hashlib.sha224", Mock224)
        monkeypatch.setattr("hashlib.sha1", Mock1)
        sha_hash = {
            1: "abcdef0123456789",
            224: "abcdef0123456789",
            256: "abcdef0123456789",
            384: "abcdef0123456789",
            512: "abcdef0123456789",
        }
        scget.local_file = "foo"
        scget.local_dir = "/var/tmp"
        for i in [512, 384, 256, 224, 1]:
            result = scget.local_sha_get(sha_hash)
            assert result == None
            del sha_hash[i]
Ejemplo n.º 4
0
    def test_join_files_local_fail(self, monkeypatch: MonkeyPatch):
        def isfile(path):
            return False

        def glob(path):
            return ["file1", "file2"]

        monkeypatch.setattr("glob.glob", glob)
        monkeypatch.setattr("builtins.open", MockOpen)
        monkeypatch.setattr("os.path.isfile", isfile)
        monkeypatch.setattr("os.path.sep", "/")
        scget = SplitCopyGet()
        scget.remote_file = "foo"
        scget.local_file = "foo"
        scget.local_dir = "/var/tmp"
        scget.scs = MockSplitCopyShared()
        with raises(SystemExit):
            scget.join_files_local()
Ejemplo n.º 5
0
    def test_join_files_local(self, monkeypatch: MonkeyPatch):
        def isfile(path):
            return True

        def glob(path):
            return ["file1", "file2"]

        monkeypatch.setattr("glob.glob", glob)
        monkeypatch.setattr("builtins.open", MockOpen)
        monkeypatch.setattr("os.path.isfile", isfile)
        monkeypatch.setattr("os.path.sep", "/")
        scget = SplitCopyGet()
        scget.remote_file = "foo"
        scget.local_file = "foo"
        scget.local_dir = "/var/tmp"
        scget.scs = MockSplitCopyShared()

        result = scget.join_files_local()
        assert result == None