コード例 #1
0
def test_list_versions_many(oss):
    oss = OSSFileSystem(key=key, secret=secret, endpoint=endpoint, version_aware=True)
    versioned_file = versioned_bucket_name + "/versioned_file-" + str(uuid.uuid4())
    for i in range(1200):
        with oss.open(versioned_file, "wb") as fo:
            fo.write(b"1")
    versions = oss.object_version_info(versioned_file)
    assert len(versions) == 1200
コード例 #2
0
def test_versioned_file_fullpath(oss):
    versioned_file = (versioned_bucket_name + "/versioned_file_fullpath-" + str(uuid.uuid4()))
    oss = OSSFileSystem(key=key, secret=secret, endpoint=endpoint, version_aware=True)
    with oss.open(versioned_file, "wb") as fo:
        fo.write(b"1")
    # moto doesn't correctly return a versionId for a multipart upload. So we resort to this.
    # version_id = fo.version_id
    versions = oss.object_version_info(versioned_file)
    version_ids = [version.versionid for version in reversed(versions)]
    version_id = version_ids[0]

    with oss.open(versioned_file, "wb") as fo:
        fo.write(b"2")

    file_with_version = "{}?versionId={}".format(versioned_file, version_id)

    with oss.open(file_with_version, "rb") as fo:
        assert fo.version_id == version_id
        assert fo.read() == b"1"
コード例 #3
0
def test_versions(oss):
    versioned_file = versioned_bucket_name + "/versioned_file_" + str(uuid.uuid4())
    oss = OSSFileSystem(key=key, secret=secret, endpoint=endpoint, version_aware=True)

    with oss.open(versioned_file, "wb") as fo:
        fo.write(b"1")
    with oss.open(versioned_file, "wb") as fo:
        fo.write(b"2")
    assert oss.isfile(versioned_file)
    versions = oss.object_version_info(versioned_file)
    version_ids = [version.versionid for version in reversed(versions)]
    assert len(version_ids) == 2
    with oss.open(versioned_file) as fo:
        assert fo.version_id == version_ids[1]
        assert fo.read() == b"2"

    with oss.open(versioned_file, version_id=version_ids[0]) as fo:
        assert fo.version_id == version_ids[0]
        assert fo.read() == b"1"