Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/s3api/test_list_objects.py
1567 views
1
#!/usr/bin/env python
2
# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License"). You
5
# may not use this file except in compliance with the License. A copy of
6
# the License is located at
7
#
8
# http://aws.amazon.com/apache2.0/
9
#
10
# or in the "license" file accompanying this file. This file is
11
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
# ANY KIND, either express or implied. See the License for the specific
13
# language governing permissions and limitations under the License.
14
from awscli.testutils import BaseAWSCommandParamsTest
15
import base64
16
import json
17
18
19
class TestListObjects(BaseAWSCommandParamsTest):
20
21
prefix = 's3api list-objects'
22
23
def setUp(self):
24
super(TestListObjects, self).setUp()
25
self.parsed_response = {'Contents': []}
26
27
def test_simple(self):
28
cmdline = self.prefix
29
cmdline += ' --bucket mybucket'
30
self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',
31
'EncodingType': 'url'})
32
33
def test_max_items(self):
34
cmdline = self.prefix
35
cmdline += ' --bucket mybucket'
36
# The max-items is a customization and therefore won't
37
# show up in the result params.
38
cmdline += ' --max-items 100'
39
self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',
40
'EncodingType': 'url'})
41
42
def test_page_size(self):
43
cmdline = self.prefix
44
cmdline += ' --bucket mybucket'
45
# The max-items is a customization and therefore won't
46
# show up in the result params.
47
cmdline += ' --page-size 100'
48
self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',
49
'MaxKeys': 100,
50
'EncodingType': 'url'})
51
52
def test_starting_token(self):
53
# We don't need to test this in depth because botocore
54
# tests this. We just want to make sure this is hooked up
55
# properly.
56
cmdline = self.prefix
57
cmdline += ' --bucket mybucket'
58
token = {"Marker": "foo"}
59
token = base64.b64encode(json.dumps(token).encode('utf-8'))
60
token = token.decode('utf-8')
61
cmdline += ' --starting-token %s' % token
62
self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',
63
'Marker': 'foo',
64
'EncodingType': 'url'})
65
66
def test_no_paginate(self):
67
cmdline = self.prefix
68
cmdline += ' --bucket mybucket --no-paginate'
69
self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',
70
'EncodingType': 'url'})
71
72
def test_max_keys_can_be_specified(self):
73
cmdline = self.prefix
74
# --max-keys is a hidden argument and not documented,
75
# but for back-compat reasons if a user specifies this,
76
# we will automatically see this and turn auto-pagination off.
77
cmdline += ' --bucket mybucket --max-keys 1'
78
self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',
79
'MaxKeys': 1,
80
'EncodingType': 'url'})
81
self.assertEqual(len(self.operations_called), 1)
82
self.assertEqual(len(self.operations_called), 1)
83
self.assertEqual(self.operations_called[0][0].name, 'ListObjects')
84
85
def test_pagination_params_cannot_be_supplied_with_no_paginate(self):
86
cmdline = self.prefix + ' --bucket mybucket --no-paginate ' \
87
'--max-items 100'
88
self.assert_params_for_cmd(
89
cmdline, expected_rc=255,
90
stderr_contains="Error during pagination: Cannot specify "
91
"--no-paginate along with pagination arguments: "
92
"--max-items")
93
94