Skip to content

Commit

Permalink
Fix stream functional test
Browse files Browse the repository at this point in the history
This fixes two issues in the streaming functional tests. First, it
makes sure the mock payload is returning bytes instead of strings.
Second, it makes sure that files are created in a temporary
directory.
  • Loading branch information
JordonPhillips committed Apr 5, 2018
1 parent 2bb71c2 commit d6f30e3
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tests/functional/s3api/test_select_object_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import os
import tempfile
import shutil

import awscli.clidriver
from awscli.testutils import BaseAWSCommandParamsTest
from awscli.testutils import BaseAWSHelpOutputTest

Expand All @@ -25,34 +26,36 @@ class TestGetObject(BaseAWSCommandParamsTest):
def setUp(self):
super(TestGetObject, self).setUp()
self.parsed_response = {'Payload': self.create_fake_payload()}
self._tempdir = tempfile.mkdtemp()

def tearDown(self):
super(TestGetObject, self).tearDown()
shutil.rmtree(self._tempdir)

def create_fake_payload(self):
yield {'Records': {'Payload': 'a,b,c,d\n'}}
yield {'Records': {'Payload': b'a,b,c,d\n'}}
# These next two events are ignored because they aren't
# "Records".
yield {'Progress': {'Details': {'BytesScanned': 1048576,
'BytesProcessed': 37748736}}}
yield {'Records': {'Payload': 'e,f,g,h\n'}}
yield {'Records': {'Payload': b'e,f,g,h\n'}}
yield {'Stats': {'Details': {'BytesProcessed': 62605400,
'BytesScanned': 1662276}}}
yield {'End': {}}

def remove_file_if_exists(self, filename):
if os.path.isfile(filename):
os.remove(filename)

def test_can_stream_to_file(self):
filename = os.path.join(self._tempdir, 'outfile')
cmdline = self.prefix[::]
cmdline.extend(['--bucket', 'mybucket'])
cmdline.extend(['--key', 'mykey'])
cmdline.extend(['--expression', 'SELECT * FROM S3Object'])
cmdline.extend(['--expression-type', 'SQL'])
cmdline.extend(['--request-progress', 'Enabled=True'])
cmdline.extend(['--input-serialization', '{"CSV": {}, "CompressionType": "GZIP"}'])
cmdline.extend(['--input-serialization',
'{"CSV": {}, "CompressionType": "GZIP"}'])
cmdline.extend(['--output-serialization', '{"CSV": {}}'])
cmdline.extend(['outfile'])
cmdline.extend([filename])

self.addCleanup(self.remove_file_if_exists, 'outfile')
expected_params = {
'Bucket': 'mybucket',
'Key': u'mykey',
Expand All @@ -64,7 +67,7 @@ def test_can_stream_to_file(self):
}
stdout = self.assert_params_for_cmd(cmdline, expected_params)[0]
self.assertEqual(stdout, '')
with open('outfile', 'r') as f:
with open(filename, 'r') as f:
contents = f.read()
self.assertEqual(contents, (
'a,b,c,d\n'
Expand All @@ -87,7 +90,7 @@ def test_errors_are_propagated(self):
'--request-progress', 'Enabled=True',
'--input-serialization', '{"CSV": {}, "CompressionType": "GZIP"}',
'--output-serialization', '{"CSV": {}}',
'outfile',
os.path.join(self._tempdir, 'outfile'),
]
expected_params = {
'Bucket': 'mybucket',
Expand Down

0 comments on commit d6f30e3

Please sign in to comment.