1212# ANY KIND, either express or implied. See the License for the specific
1313# language governing permissions and limitations under the License.
1414import os
15- import shutil
1615import tempfile
16+ import shutil
1717
18- from awscli .testutils import (
19- BaseAWSCommandParamsTest ,
20- BaseAWSHelpOutputTest ,
21- skip_if_windows ,
22- )
18+ from awscli .testutils import BaseAWSCommandParamsTest
19+ from awscli .testutils import BaseAWSHelpOutputTest
2320
2421
2522class TestGetObject (BaseAWSCommandParamsTest ):
23+
2624 prefix = ['s3api' , 'select-object-content' ]
2725
2826 def setUp (self ):
@@ -38,23 +36,11 @@ def create_fake_payload(self):
3836 yield {'Records' : {'Payload' : b'a,b,c,d\n ' }}
3937 # These next two events are ignored because they aren't
4038 # "Records".
41- yield {
42- 'Progress' : {
43- 'Details' : {
44- 'BytesScanned' : 1048576 ,
45- 'BytesProcessed' : 37748736 ,
46- }
47- }
48- }
39+ yield {'Progress' : {'Details' : {'BytesScanned' : 1048576 ,
40+ 'BytesProcessed' : 37748736 }}}
4941 yield {'Records' : {'Payload' : b'e,f,g,h\n ' }}
50- yield {
51- 'Stats' : {
52- 'Details' : {
53- 'BytesProcessed' : 62605400 ,
54- 'BytesScanned' : 1662276 ,
55- }
56- }
57- }
42+ yield {'Stats' : {'Details' : {'BytesProcessed' : 62605400 ,
43+ 'BytesScanned' : 1662276 }}}
5844 yield {'End' : {}}
5945
6046 def test_can_stream_to_file (self ):
@@ -65,15 +51,14 @@ def test_can_stream_to_file(self):
6551 cmdline .extend (['--expression' , 'SELECT * FROM S3Object' ])
6652 cmdline .extend (['--expression-type' , 'SQL' ])
6753 cmdline .extend (['--request-progress' , 'Enabled=True' ])
68- cmdline .extend (
69- ['--input-serialization' , '{"CSV": {}, "CompressionType": "GZIP"}' ]
70- )
54+ cmdline .extend (['--input-serialization' ,
55+ '{"CSV": {}, "CompressionType": "GZIP"}' ])
7156 cmdline .extend (['--output-serialization' , '{"CSV": {}}' ])
7257 cmdline .extend ([filename ])
7358
7459 expected_params = {
7560 'Bucket' : 'mybucket' ,
76- 'Key' : 'mykey' ,
61+ 'Key' : u 'mykey' ,
7762 'Expression' : 'SELECT * FROM S3Object' ,
7863 'ExpressionType' : 'SQL' ,
7964 'InputSerialization' : {'CSV' : {}, 'CompressionType' : 'GZIP' },
@@ -82,31 +67,12 @@ def test_can_stream_to_file(self):
8267 }
8368 stdout = self .assert_params_for_cmd (cmdline , expected_params )[0 ]
8469 self .assertEqual (stdout , '' )
85- with open (filename ) as f :
70+ with open (filename , 'r' ) as f :
8671 contents = f .read ()
87- self .assertEqual (contents , ('a,b,c,d\n ' 'e,f,g,h\n ' ))
88-
89- @skip_if_windows ('chmod is not supported on Windows' )
90- def test_output_file_permissions (self ):
91- filename = os .path .join (self ._tempdir , 'outfile_perms' )
92- cmdline = self .prefix + [
93- '--bucket' ,
94- 'mybucket' ,
95- '--key' ,
96- 'mykey' ,
97- '--expression' ,
98- 'SELECT * FROM S3Object' ,
99- '--expression-type' ,
100- 'SQL' ,
101- '--input-serialization' ,
102- '{"CSV": {}}' ,
103- '--output-serialization' ,
104- '{"CSV": {}}' ,
105- filename ,
106- ]
107- self .assert_params_for_cmd (cmdline , ignore_params = True )
108- # Mask file type bits to isolate permission bits (rwxrwxrwx)
109- self .assertEqual (os .stat (filename ).st_mode & 0o777 , 0o600 )
72+ self .assertEqual (contents , (
73+ 'a,b,c,d\n '
74+ 'e,f,g,h\n '
75+ ))
11076
11177 def test_errors_are_propagated (self ):
11278 self .http_response .status_code = 400
@@ -117,39 +83,30 @@ def test_errors_are_propagated(self):
11783 }
11884 }
11985 cmdline = self .prefix + [
120- '--bucket' ,
121- 'mybucket' ,
122- '--key' ,
123- 'mykey' ,
124- '--expression' ,
125- 'SELECT * FROM S3Object' ,
126- '--expression-type' ,
127- 'SQL' ,
128- '--request-progress' ,
129- 'Enabled=True' ,
130- '--input-serialization' ,
131- '{"CSV": {}, "CompressionType": "GZIP"}' ,
132- '--output-serialization' ,
133- '{"CSV": {}}' ,
86+ '--bucket' , 'mybucket' ,
87+ '--key' , 'mykey' ,
88+ '--expression' , 'SELECT * FROM S3Object' ,
89+ '--expression-type' , 'SQL' ,
90+ '--request-progress' , 'Enabled=True' ,
91+ '--input-serialization' , '{"CSV": {}, "CompressionType": "GZIP"}' ,
92+ '--output-serialization' , '{"CSV": {}}' ,
13493 os .path .join (self ._tempdir , 'outfile' ),
13594 ]
13695 expected_params = {
13796 'Bucket' : 'mybucket' ,
138- 'Key' : 'mykey' ,
97+ 'Key' : u 'mykey' ,
13998 'Expression' : 'SELECT * FROM S3Object' ,
14099 'ExpressionType' : 'SQL' ,
141100 'InputSerialization' : {'CSV' : {}, 'CompressionType' : 'GZIP' },
142101 'OutputSerialization' : {'CSV' : {}},
143102 'RequestProgress' : {'Enabled' : True },
144103 }
145104 self .assert_params_for_cmd (
146- cmd = cmdline ,
147- params = expected_params ,
105+ cmd = cmdline , params = expected_params ,
148106 expected_rc = 255 ,
149107 stderr_contains = (
150108 'An error occurred (CastFailed) when '
151- 'calling the SelectObjectContent operation'
152- ),
109+ 'calling the SelectObjectContent operation' ),
153110 )
154111
155112
@@ -159,7 +116,8 @@ def test_output(self):
159116 # We don't want to be super picky because the wording may change
160117 # We just want to verify the Output section was customized.
161118 self .assert_contains (
162- 'Output\n ======\n ' 'This command generates no output'
119+ 'Output\n ======\n '
120+ 'This command generates no output'
163121 )
164122 self .assert_not_contains ('[outfile' )
165123 self .assert_contains ('outfile' )
0 commit comments