Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/s3/test_copy_params.py
1569 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
import os
15
import sys
16
import re
17
import copy
18
19
from awscli.testutils import BaseAWSCommandParamsTest
20
21
if sys.version_info[:2] == (2, 6):
22
from StringIO import StringIO
23
24
25
# file is gone in python3, so instead IOBase must be used.
26
# Given this test module is the only place that cares about
27
# this type check, we do the check directly in this test module.
28
try:
29
file_type = file
30
except NameError:
31
import io
32
file_type = io.IOBase
33
34
35
class TestGetObject(BaseAWSCommandParamsTest):
36
37
prefix = 's3 cp '
38
39
def setUp(self):
40
super(TestGetObject, self).setUp()
41
self.file_path = os.path.join(os.path.dirname(__file__),
42
'test_copy_params_data')
43
self.parsed_response = {'ETag': '"120ea8a25e5d487bf68b5f7096440019"',}
44
45
def assert_params(self, cmdline, result):
46
foo = self.assert_params_for_cmd(cmdline, result, expected_rc=0,
47
ignore_params=['Body'])
48
49
def test_simple(self):
50
cmdline = self.prefix
51
cmdline += self.file_path
52
cmdline += ' s3://mybucket/mykey'
53
result = {'Bucket': u'mybucket', 'Key': u'mykey', 'ChecksumAlgorithm': 'CRC32'}
54
self.assert_params(cmdline, result)
55
56
def test_sse(self):
57
cmdline = self.prefix
58
cmdline += self.file_path
59
cmdline += ' s3://mybucket/mykey'
60
cmdline += ' --sse'
61
result = {'Bucket': u'mybucket', 'Key': u'mykey',
62
'ServerSideEncryption': 'AES256', 'ChecksumAlgorithm': 'CRC32'}
63
self.assert_params(cmdline, result)
64
65
def test_storage_class(self):
66
cmdline = self.prefix
67
cmdline += self.file_path
68
cmdline += ' s3://mybucket/mykey'
69
cmdline += ' --storage-class REDUCED_REDUNDANCY'
70
result = {'Bucket': u'mybucket', 'Key': u'mykey',
71
'StorageClass': u'REDUCED_REDUNDANCY', 'ChecksumAlgorithm': 'CRC32'}
72
self.assert_params(cmdline, result)
73
74
def test_standard_ia_storage_class(self):
75
cmdline = self.prefix
76
cmdline += self.file_path
77
cmdline += ' s3://mybucket/mykey'
78
cmdline += ' --storage-class STANDARD_IA'
79
result = {'Bucket': u'mybucket', 'Key': u'mykey',
80
'StorageClass': u'STANDARD_IA', 'ChecksumAlgorithm': 'CRC32'}
81
self.assert_params(cmdline, result)
82
83
def test_glacier_ir_storage_class(self):
84
cmdline = self.prefix
85
cmdline += self.file_path
86
cmdline += ' s3://mybucket/mykey'
87
cmdline += ' --storage-class GLACIER_IR'
88
result = {'Bucket': u'mybucket', 'Key': u'mykey',
89
'ChecksumAlgorithm': 'CRC32', 'StorageClass': u'GLACIER_IR'}
90
self.assert_params(cmdline, result)
91
92
def test_website_redirect(self):
93
cmdline = self.prefix
94
cmdline += self.file_path
95
cmdline += ' s3://mybucket/mykey'
96
cmdline += ' --website-redirect /foobar'
97
result = {'Bucket': u'mybucket',
98
'Key': u'mykey',
99
'ChecksumAlgorithm': 'CRC32',
100
'WebsiteRedirectLocation': u'/foobar'}
101
self.assert_params(cmdline, result)
102
103
def test_acl(self):
104
cmdline = self.prefix
105
cmdline += self.file_path
106
cmdline += ' s3://mybucket/mykey'
107
cmdline += ' --acl public-read'
108
result = {'Bucket': 'mybucket', 'Key': 'mykey', 'ChecksumAlgorithm': 'CRC32', 'ACL': 'public-read'}
109
self.assert_params(cmdline, result)
110
111
def test_content_params(self):
112
cmdline = self.prefix
113
cmdline += self.file_path
114
cmdline += ' s3://mybucket/mykey'
115
cmdline += ' --content-encoding x-gzip'
116
cmdline += ' --content-language piglatin'
117
cmdline += ' --cache-control max-age=3600,must-revalidate'
118
cmdline += ' --content-disposition attachment;filename="fname.ext"'
119
result = {'Bucket': 'mybucket', 'Key': 'mykey',
120
'ChecksumAlgorithm': 'CRC32',
121
'ContentEncoding': 'x-gzip',
122
'ContentLanguage': 'piglatin',
123
'ContentDisposition': 'attachment;filename="fname.ext"',
124
'CacheControl': 'max-age=3600,must-revalidate'}
125
self.assert_params(cmdline, result)
126
127
def test_grants(self):
128
cmdline = self.prefix
129
cmdline += self.file_path
130
cmdline += ' s3://mybucket/mykey'
131
cmdline += ' --grants read=bob'
132
cmdline += ' full=alice'
133
result = {'Bucket': u'mybucket',
134
'GrantFullControl': u'alice',
135
'GrantRead': u'bob',
136
'Key': u'mykey',
137
'ChecksumAlgorithm': 'CRC32'}
138
self.assert_params(cmdline, result)
139
140
def test_grants_bad(self):
141
cmdline = self.prefix
142
cmdline += self.file_path
143
cmdline += ' s3://mybucket/mykey'
144
cmdline += ' --grants read:bob'
145
self.assert_params_for_cmd(cmdline, expected_rc=1,
146
ignore_params=['Payload'])
147
148
def test_content_type(self):
149
cmdline = self.prefix
150
cmdline += self.file_path
151
cmdline += ' s3://mybucket/mykey'
152
cmdline += ' --content-type text/xml'
153
result = {'Bucket': u'mybucket', 'ContentType': u'text/xml',
154
'Key': u'mykey', 'ChecksumAlgorithm': 'CRC32'}
155
self.assert_params(cmdline, result)
156
157
158
if __name__ == "__main__":
159
unittest.main()
160
161
162