Exemplo n.º 1
0
def test_azure_maybe_update_md5(ctx):
    contents = b"meow!"
    meow_hash = hashlib.md5(contents).hexdigest()
    alternative_contents = b"purr"
    purr_hash = hashlib.md5(alternative_contents).hexdigest()

    with ctx() as path:
        _write_contents(path, contents)
        _isfile, metadata = ops._azure_isfile(path)
        assert ops._azure_maybe_update_md5(path, metadata["ETag"], meow_hash)
        _write_contents(path, alternative_contents)
        assert not ops._azure_maybe_update_md5(path, metadata["ETag"], meow_hash)
        _isfile, metadata = ops._azure_isfile(path)
        assert base64.b64decode(metadata["Content-MD5"]).hex() == purr_hash
Exemplo n.º 2
0
def test_azure_metadata(ctx):
    # make sure metadata is preserved when opening a file for writing
    # which clears uncommitted blocks
    contents = b"meow!"

    with ctx() as path:
        with bf.BlobFile(path, "wb") as f:
            f.write(contents)

        bf.set_mtime(path, 1)
        _isfile, orig_metadata = ops._azure_isfile(path)
        time.sleep(5)
        with bf.BlobFile(path, "wb", streaming=True) as f:
            _isfile, new_metadata = ops._azure_isfile(path)
        keys = set(orig_metadata.keys()).union(new_metadata.keys())
        for key in sorted(keys):
            orig_val = orig_metadata.get(key)
            new_val = new_metadata.get(key)
            if key not in ["Date", "ETag", "Last-Modified", "x-ms-request-id"]:
                assert orig_val == new_val