Path: blob/develop/tests/functional/s3api/test_get_object.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 BaseAWSCommandParamsTest14from awscli.compat import StringIO15import os16import re1718import awscli.clidriver192021class TestGetObject(BaseAWSCommandParamsTest):2223prefix = 's3api get-object'2425def setUp(self):26super(TestGetObject, self).setUp()27self.parsed_response = {'Body': StringIO()}2829def remove_file_if_exists(self, filename):30if os.path.isfile(filename):31os.remove(filename)3233def test_simple(self):34cmdline = self.prefix35cmdline += ' --bucket mybucket'36cmdline += ' --key mykey'37cmdline += ' outfile'38self.addCleanup(self.remove_file_if_exists, 'outfile')39self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',40'ChecksumMode': 'ENABLED',41'Key': 'mykey'})4243def test_range(self):44cmdline = self.prefix45cmdline += ' --bucket mybucket'46cmdline += ' --key mykey'47cmdline += ' --range bytes=0-499'48cmdline += ' outfile'49self.addCleanup(self.remove_file_if_exists, 'outfile')50self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',51'ChecksumMode': 'ENABLED',52'Key': 'mykey',53'Range': 'bytes=0-499'})5455def test_response_headers(self):56cmdline = self.prefix57cmdline += ' --bucket mybucket'58cmdline += ' --key mykey'59cmdline += ' --response-cache-control No-cache'60cmdline += ' --response-content-encoding x-gzip'61cmdline += ' outfile'62self.addCleanup(self.remove_file_if_exists, 'outfile')63self.assert_params_for_cmd(64cmdline, {65'Bucket': 'mybucket',66'ChecksumMode': 'ENABLED',67'Key': 'mykey',68'ResponseCacheControl': 'No-cache',69'ResponseContentEncoding': 'x-gzip'70}71)7273def test_streaming_output_arg_with_error_response(self):74# Checking that the StreamingOutputArg handles the75# case where it's passed an error body. Previously76# it would propagate a KeyError so we want to ensure77# this case is handled.78self.parsed_response = {79'Error': {80'Code': 'AuthError', 'Message': 'SomeError'81}82}83cmdline = self.prefix84cmdline += ' --bucket mybucket'85cmdline += ' --key mykey'86cmdline += ' outfile'87self.addCleanup(self.remove_file_if_exists, 'outfile')88self.assert_params_for_cmd(89cmdline, {'Bucket': 'mybucket', 'ChecksumMode': 'ENABLED', 'Key': 'mykey'})909192if __name__ == "__main__":93unittest.main()949596