Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/s3api/test_get_object.py
1567 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
from awscli.testutils import BaseAWSCommandParamsTest
15
from awscli.compat import StringIO
16
import os
17
import re
18
19
import awscli.clidriver
20
21
22
class TestGetObject(BaseAWSCommandParamsTest):
23
24
prefix = 's3api get-object'
25
26
def setUp(self):
27
super(TestGetObject, self).setUp()
28
self.parsed_response = {'Body': StringIO()}
29
30
def remove_file_if_exists(self, filename):
31
if os.path.isfile(filename):
32
os.remove(filename)
33
34
def test_simple(self):
35
cmdline = self.prefix
36
cmdline += ' --bucket mybucket'
37
cmdline += ' --key mykey'
38
cmdline += ' outfile'
39
self.addCleanup(self.remove_file_if_exists, 'outfile')
40
self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',
41
'ChecksumMode': 'ENABLED',
42
'Key': 'mykey'})
43
44
def test_range(self):
45
cmdline = self.prefix
46
cmdline += ' --bucket mybucket'
47
cmdline += ' --key mykey'
48
cmdline += ' --range bytes=0-499'
49
cmdline += ' outfile'
50
self.addCleanup(self.remove_file_if_exists, 'outfile')
51
self.assert_params_for_cmd(cmdline, {'Bucket': 'mybucket',
52
'ChecksumMode': 'ENABLED',
53
'Key': 'mykey',
54
'Range': 'bytes=0-499'})
55
56
def test_response_headers(self):
57
cmdline = self.prefix
58
cmdline += ' --bucket mybucket'
59
cmdline += ' --key mykey'
60
cmdline += ' --response-cache-control No-cache'
61
cmdline += ' --response-content-encoding x-gzip'
62
cmdline += ' outfile'
63
self.addCleanup(self.remove_file_if_exists, 'outfile')
64
self.assert_params_for_cmd(
65
cmdline, {
66
'Bucket': 'mybucket',
67
'ChecksumMode': 'ENABLED',
68
'Key': 'mykey',
69
'ResponseCacheControl': 'No-cache',
70
'ResponseContentEncoding': 'x-gzip'
71
}
72
)
73
74
def test_streaming_output_arg_with_error_response(self):
75
# Checking that the StreamingOutputArg handles the
76
# case where it's passed an error body. Previously
77
# it would propagate a KeyError so we want to ensure
78
# this case is handled.
79
self.parsed_response = {
80
'Error': {
81
'Code': 'AuthError', 'Message': 'SomeError'
82
}
83
}
84
cmdline = self.prefix
85
cmdline += ' --bucket mybucket'
86
cmdline += ' --key mykey'
87
cmdline += ' outfile'
88
self.addCleanup(self.remove_file_if_exists, 'outfile')
89
self.assert_params_for_cmd(
90
cmdline, {'Bucket': 'mybucket', 'ChecksumMode': 'ENABLED', 'Key': 'mykey'})
91
92
93
if __name__ == "__main__":
94
unittest.main()
95
96