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_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]