Path: blob/develop/tests/functional/s3api/test_list_objects.py
1567 views
#!/usr/bin/env python1# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13from awscli.testutils import BaseAWSCommandParamsTest14import base6415import json161718class TestListObjects(BaseAWSCommandParamsTest):1920prefix = 's3api list-objects'2122def setUp(self):23super(TestListObjects, self).setUp()24self.parsed_response = {'Contents': []}2526def test_simple(self):27cmdline = self.prefix28cmdline += ' --bucket mybucket'29self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',30'EncodingType': 'url'})3132def test_max_items(self):33cmdline = self.prefix34cmdline += ' --bucket mybucket'35# The max-items is a customization and therefore won't36# show up in the result params.37cmdline += ' --max-items 100'38self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',39'EncodingType': 'url'})4041def test_page_size(self):42cmdline = self.prefix43cmdline += ' --bucket mybucket'44# The max-items is a customization and therefore won't45# show up in the result params.46cmdline += ' --page-size 100'47self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',48'MaxKeys': 100,49'EncodingType': 'url'})5051def test_starting_token(self):52# We don't need to test this in depth because botocore53# tests this. We just want to make sure this is hooked up54# properly.55cmdline = self.prefix56cmdline += ' --bucket mybucket'57token = {"Marker": "foo"}58token = base64.b64encode(json.dumps(token).encode('utf-8'))59token = token.decode('utf-8')60cmdline += ' --starting-token %s' % token61self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',62'Marker': 'foo',63'EncodingType': 'url'})6465def test_no_paginate(self):66cmdline = self.prefix67cmdline += ' --bucket mybucket --no-paginate'68self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',69'EncodingType': 'url'})7071def test_max_keys_can_be_specified(self):72cmdline = self.prefix73# --max-keys is a hidden argument and not documented,74# but for back-compat reasons if a user specifies this,75# we will automatically see this and turn auto-pagination off.76cmdline += ' --bucket mybucket --max-keys 1'77self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',78'MaxKeys': 1,79'EncodingType': 'url'})80self.assertEqual(len(self.operations_called), 1)81self.assertEqual(len(self.operations_called), 1)82self.assertEqual(self.operations_called[0][0].name, 'ListObjects')8384def test_pagination_params_cannot_be_supplied_with_no_paginate(self):85cmdline = self.prefix + ' --bucket mybucket --no-paginate ' \86'--max-items 100'87self.assert_params_for_cmd(88cmdline, expected_rc=255,89stderr_contains="Error during pagination: Cannot specify "90"--no-paginate along with pagination arguments: "91"--max-items")929394