Sort s3 object versions by last_modified_on in descending order (#3588)

* Sort s3 object versions by last_modified_on in descending order

- addresses https://github.com/localstack/localstack/issues/3433

* fix for python 2

* fix lint
This commit is contained in:
Rahul Ranjan 2021-01-15 23:58:28 +05:30 committed by GitHub
commit 628c026a07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View file

@ -873,12 +873,12 @@ def test_list_versions():
versions.should.have.length_of(2)
versions[0].name.should.equal("the-key")
versions[0].version_id.should.equal(key_versions[0])
versions[0].get_contents_as_string().should.equal(b"Version 1")
versions[0].version_id.should.equal(key_versions[1])
versions[0].get_contents_as_string().should.equal(b"Version 2")
versions[1].name.should.equal("the-key")
versions[1].version_id.should.equal(key_versions[1])
versions[1].get_contents_as_string().should.equal(b"Version 2")
versions[1].version_id.should.equal(key_versions[0])
versions[1].get_contents_as_string().should.equal(b"Version 1")
key = Key(bucket, "the2-key")
key.set_contents_from_string("Version 1")
@ -3700,6 +3700,10 @@ def test_boto3_list_object_versions():
len(response["Versions"]).should.equal(2)
keys = set([item["Key"] for item in response["Versions"]])
keys.should.equal({key})
# the first item in the list should be the latest
response["Versions"][0]["IsLatest"].should.equal(True)
# Test latest object version is returned
response = s3.get_object(Bucket=bucket_name, Key=key)
response["Body"].read().should.equal(items[-1])