update unit test and fix StartAfter
This commit is contained in:
parent
c04c72d435
commit
1c36e1e2c5
@ -451,15 +451,14 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||||||
continuation_token = querystring.get('continuation-token', [None])[0]
|
continuation_token = querystring.get('continuation-token', [None])[0]
|
||||||
start_after = querystring.get('start-after', [None])[0]
|
start_after = querystring.get('start-after', [None])[0]
|
||||||
|
|
||||||
|
# sort the combination of folders and keys into lexicographical order
|
||||||
|
all_keys = result_keys + result_folders
|
||||||
|
all_keys.sort(key=self._get_name)
|
||||||
|
|
||||||
if continuation_token or start_after:
|
if continuation_token or start_after:
|
||||||
limit = continuation_token or start_after
|
limit = continuation_token or start_after
|
||||||
if not delimiter:
|
all_keys = self._get_results_from_token(all_keys, limit)
|
||||||
result_keys = self._get_results_from_token(result_keys, limit)
|
|
||||||
else:
|
|
||||||
result_folders = self._get_results_from_token(result_folders, limit)
|
|
||||||
|
|
||||||
all_keys = result_keys + result_folders
|
|
||||||
all_keys.sort(key=self._get_key_name)
|
|
||||||
truncated_keys, is_truncated, next_continuation_token = self._truncate_result(all_keys, max_keys)
|
truncated_keys, is_truncated, next_continuation_token = self._truncate_result(all_keys, max_keys)
|
||||||
result_keys, result_folders = self._split_truncated_keys(truncated_keys)
|
result_keys, result_folders = self._split_truncated_keys(truncated_keys)
|
||||||
|
|
||||||
@ -480,7 +479,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_key_name(key):
|
def _get_name(key):
|
||||||
if isinstance(key, FakeKey):
|
if isinstance(key, FakeKey):
|
||||||
return key.name
|
return key.name
|
||||||
else:
|
else:
|
||||||
|
@ -1396,16 +1396,20 @@ def test_boto3_list_objects_v2_fetch_owner():
|
|||||||
def test_boto3_list_objects_v2_truncate_combined_keys_and_folders():
|
def test_boto3_list_objects_v2_truncate_combined_keys_and_folders():
|
||||||
s3 = boto3.client('s3', region_name='us-east-1')
|
s3 = boto3.client('s3', region_name='us-east-1')
|
||||||
s3.create_bucket(Bucket='mybucket')
|
s3.create_bucket(Bucket='mybucket')
|
||||||
s3.put_object(Bucket='mybucket', Key="A/a", Body="folder/a")
|
s3.put_object(Bucket='mybucket', Key='1/2', Body='')
|
||||||
s3.put_object(Bucket='mybucket', Key="A/aa", Body="folder/aa")
|
s3.put_object(Bucket='mybucket', Key='2', Body='')
|
||||||
s3.put_object(Bucket='mybucket', Key="A/B/a", Body="nested/folder/a")
|
s3.put_object(Bucket='mybucket', Key='3/4', Body='')
|
||||||
s3.put_object(Bucket='mybucket', Key="c", Body="plain c")
|
s3.put_object(Bucket='mybucket', Key='4', Body='')
|
||||||
|
|
||||||
resp = s3.list_objects_v2(Bucket='mybucket', Prefix="A/", MaxKeys=1, Delimiter="/")
|
resp = s3.list_objects_v2(Bucket='mybucket', MaxKeys=2, Delimiter='/')
|
||||||
assert "Prefix" in resp
|
assert 'Delimiter' in resp
|
||||||
assert "Delimiter" in resp
|
assert resp['IsTruncated'] is True
|
||||||
assert resp["IsTruncated"] is True
|
assert resp['KeyCount'] == 2
|
||||||
assert resp["KeyCount"] != 0
|
|
||||||
|
last_tail = resp['NextContinuationToken']
|
||||||
|
resp = s3.list_objects_v2(Bucket='mybucket', MaxKeys=2, Delimiter='/', StartAfter=last_tail)
|
||||||
|
assert resp['KeyCount'] == 2
|
||||||
|
assert resp['IsTruncated'] is False
|
||||||
|
|
||||||
|
|
||||||
@mock_s3
|
@mock_s3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user