Path: blob/develop/tests/unit/customizations/s3/test_copy_params.py
1569 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.13import os14import sys15import re16import copy1718from awscli.testutils import BaseAWSCommandParamsTest1920if sys.version_info[:2] == (2, 6):21from StringIO import StringIO222324# file is gone in python3, so instead IOBase must be used.25# Given this test module is the only place that cares about26# this type check, we do the check directly in this test module.27try:28file_type = file29except NameError:30import io31file_type = io.IOBase323334class TestGetObject(BaseAWSCommandParamsTest):3536prefix = 's3 cp '3738def setUp(self):39super(TestGetObject, self).setUp()40self.file_path = os.path.join(os.path.dirname(__file__),41'test_copy_params_data')42self.parsed_response = {'ETag': '"120ea8a25e5d487bf68b5f7096440019"',}4344def assert_params(self, cmdline, result):45foo = self.assert_params_for_cmd(cmdline, result, expected_rc=0,46ignore_params=['Body'])4748def test_simple(self):49cmdline = self.prefix50cmdline += self.file_path51cmdline += ' s3://mybucket/mykey'52result = {'Bucket': u'mybucket', 'Key': u'mykey', 'ChecksumAlgorithm': 'CRC32'}53self.assert_params(cmdline, result)5455def test_sse(self):56cmdline = self.prefix57cmdline += self.file_path58cmdline += ' s3://mybucket/mykey'59cmdline += ' --sse'60result = {'Bucket': u'mybucket', 'Key': u'mykey',61'ServerSideEncryption': 'AES256', 'ChecksumAlgorithm': 'CRC32'}62self.assert_params(cmdline, result)6364def test_storage_class(self):65cmdline = self.prefix66cmdline += self.file_path67cmdline += ' s3://mybucket/mykey'68cmdline += ' --storage-class REDUCED_REDUNDANCY'69result = {'Bucket': u'mybucket', 'Key': u'mykey',70'StorageClass': u'REDUCED_REDUNDANCY', 'ChecksumAlgorithm': 'CRC32'}71self.assert_params(cmdline, result)7273def test_standard_ia_storage_class(self):74cmdline = self.prefix75cmdline += self.file_path76cmdline += ' s3://mybucket/mykey'77cmdline += ' --storage-class STANDARD_IA'78result = {'Bucket': u'mybucket', 'Key': u'mykey',79'StorageClass': u'STANDARD_IA', 'ChecksumAlgorithm': 'CRC32'}80self.assert_params(cmdline, result)8182def test_glacier_ir_storage_class(self):83cmdline = self.prefix84cmdline += self.file_path85cmdline += ' s3://mybucket/mykey'86cmdline += ' --storage-class GLACIER_IR'87result = {'Bucket': u'mybucket', 'Key': u'mykey',88'ChecksumAlgorithm': 'CRC32', 'StorageClass': u'GLACIER_IR'}89self.assert_params(cmdline, result)9091def test_website_redirect(self):92cmdline = self.prefix93cmdline += self.file_path94cmdline += ' s3://mybucket/mykey'95cmdline += ' --website-redirect /foobar'96result = {'Bucket': u'mybucket',97'Key': u'mykey',98'ChecksumAlgorithm': 'CRC32',99'WebsiteRedirectLocation': u'/foobar'}100self.assert_params(cmdline, result)101102def test_acl(self):103cmdline = self.prefix104cmdline += self.file_path105cmdline += ' s3://mybucket/mykey'106cmdline += ' --acl public-read'107result = {'Bucket': 'mybucket', 'Key': 'mykey', 'ChecksumAlgorithm': 'CRC32', 'ACL': 'public-read'}108self.assert_params(cmdline, result)109110def test_content_params(self):111cmdline = self.prefix112cmdline += self.file_path113cmdline += ' s3://mybucket/mykey'114cmdline += ' --content-encoding x-gzip'115cmdline += ' --content-language piglatin'116cmdline += ' --cache-control max-age=3600,must-revalidate'117cmdline += ' --content-disposition attachment;filename="fname.ext"'118result = {'Bucket': 'mybucket', 'Key': 'mykey',119'ChecksumAlgorithm': 'CRC32',120'ContentEncoding': 'x-gzip',121'ContentLanguage': 'piglatin',122'ContentDisposition': 'attachment;filename="fname.ext"',123'CacheControl': 'max-age=3600,must-revalidate'}124self.assert_params(cmdline, result)125126def test_grants(self):127cmdline = self.prefix128cmdline += self.file_path129cmdline += ' s3://mybucket/mykey'130cmdline += ' --grants read=bob'131cmdline += ' full=alice'132result = {'Bucket': u'mybucket',133'GrantFullControl': u'alice',134'GrantRead': u'bob',135'Key': u'mykey',136'ChecksumAlgorithm': 'CRC32'}137self.assert_params(cmdline, result)138139def test_grants_bad(self):140cmdline = self.prefix141cmdline += self.file_path142cmdline += ' s3://mybucket/mykey'143cmdline += ' --grants read:bob'144self.assert_params_for_cmd(cmdline, expected_rc=1,145ignore_params=['Payload'])146147def test_content_type(self):148cmdline = self.prefix149cmdline += self.file_path150cmdline += ' s3://mybucket/mykey'151cmdline += ' --content-type text/xml'152result = {'Bucket': u'mybucket', 'ContentType': u'text/xml',153'Key': u'mykey', 'ChecksumAlgorithm': 'CRC32'}154self.assert_params(cmdline, result)155156157if __name__ == "__main__":158unittest.main()159160161162