Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/s3/__init__.py
1567 views
1
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
from awscli.testutils import mock, BaseAWSCommandParamsTest, FileCreator
14
from awscli.compat import BytesIO
15
16
class BaseS3TransferCommandTest(BaseAWSCommandParamsTest):
17
def setUp(self):
18
super(BaseS3TransferCommandTest, self).setUp()
19
self.files = FileCreator()
20
21
def tearDown(self):
22
super(BaseS3TransferCommandTest, self).tearDown()
23
self.files.remove_all()
24
25
def assert_operations_called(self, expected_operations_with_params):
26
actual_operations_with_params = [
27
(operation_called[0].name, operation_called[1])
28
for operation_called in self.operations_called
29
]
30
self.assertEqual(
31
actual_operations_with_params, expected_operations_with_params)
32
33
def head_object_response(self, **override_kwargs):
34
response = {
35
'ContentLength': 100,
36
'LastModified': '00:00:00Z',
37
'ETag': '"foo-1"'
38
}
39
response.update(override_kwargs)
40
return response
41
42
def list_objects_response(self, keys):
43
contents = []
44
for key in keys:
45
contents.append(
46
{
47
'Key': key,
48
'LastModified': '00:00:00Z',
49
'Size': 100,
50
'ETag': '"foo-1"',
51
}
52
)
53
54
return {
55
'Contents': contents,
56
'CommonPrefixes': []
57
}
58
59
def get_object_response(self):
60
return {
61
'ETag': '"foo-1"',
62
'Body': BytesIO(b'foo')
63
}
64
65
def copy_object_response(self):
66
return self.empty_response()
67
68
def delete_object_response(self):
69
return self.empty_response()
70
71
def create_mpu_response(self, upload_id):
72
return {
73
'UploadId': upload_id
74
}
75
76
def upload_part_copy_response(self):
77
return {
78
'CopyPartResult': {
79
'ETag': '"etag"'
80
}
81
}
82
83
def complete_mpu_response(self):
84
return self.empty_response()
85
86
def empty_response(self):
87
return {}
88
89
def head_object_request(self, bucket, key, **override_kwargs):
90
params = {
91
'Bucket': bucket,
92
'Key': key,
93
}
94
params.update(override_kwargs)
95
return 'HeadObject', params
96
97
def list_objects_request(self, bucket, prefix=None, **override_kwargs):
98
params = {
99
'Bucket': bucket,
100
}
101
if prefix is None:
102
params['Prefix'] = ''
103
params.update(override_kwargs)
104
return 'ListObjectsV2', params
105
106
def put_object_request(self, bucket, key, **override_kwargs):
107
params = {
108
'Bucket': bucket,
109
'Key': key,
110
'ChecksumAlgorithm': 'CRC32',
111
'Body': mock.ANY,
112
}
113
params.update(override_kwargs)
114
return 'PutObject', params
115
116
def get_object_request(self, bucket, key, **override_kwargs):
117
params = {
118
'Bucket': bucket,
119
'Key': key,
120
}
121
params.update(override_kwargs)
122
return 'GetObject', params
123
124
def copy_object_request(self, source_bucket, source_key, bucket, key,
125
**override_kwargs):
126
params = {
127
'Bucket': bucket,
128
'Key': key,
129
'CopySource': {
130
'Bucket': source_bucket,
131
'Key': source_key
132
}
133
}
134
params.update(override_kwargs)
135
return 'CopyObject', params
136
137
def delete_object_request(self, bucket, key, **override_kwargs):
138
params = {
139
'Bucket': bucket,
140
'Key': key,
141
}
142
params.update(override_kwargs)
143
return 'DeleteObject', params
144
145
def create_mpu_request(self, bucket, key, **override_kwargs):
146
params = {
147
'Bucket': bucket,
148
'Key': key,
149
}
150
params.update(override_kwargs)
151
return 'CreateMultipartUpload', params
152
153
def upload_part_copy_request(self, source_bucket, source_key, bucket, key,
154
upload_id, **override_kwargs):
155
params = {
156
'Bucket': bucket,
157
'Key': key,
158
'CopySource': {
159
'Bucket': source_bucket,
160
'Key': source_key
161
},
162
'UploadId': upload_id,
163
164
}
165
params.update(override_kwargs)
166
return 'UploadPartCopy', params
167
168
def complete_mpu_request(self, bucket, key, upload_id, num_parts,
169
**override_kwargs):
170
parts = []
171
for i in range(num_parts):
172
parts.append(
173
{
174
'ETag': '"etag"', 'PartNumber': i + 1
175
}
176
)
177
params = {
178
'Bucket': bucket,
179
'Key': key,
180
'UploadId': upload_id,
181
'MultipartUpload': {'Parts': parts}
182
}
183
params.update(override_kwargs)
184
return 'CompleteMultipartUpload', params
185
186