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