diff options
author | Joel Wright <joel.wright@sohonet.com> | 2015-01-04 21:14:02 +0000 |
---|---|---|
committer | Joel Wright <joel.wright@sohonet.com> | 2015-01-23 11:46:13 +0000 |
commit | bd42c2b00d0e4a18d15fd494bd9b9101742c4a37 (patch) | |
tree | 13aeb9c42ef70b6cd13a9bd3fd001cb66c81e1c5 /tests/unit/test_shell.py | |
parent | 7709fea51e71084163cf56c4d11a280ca4388357 (diff) | |
download | python-swiftclient-bd42c2b00d0e4a18d15fd494bd9b9101742c4a37.tar.gz |
This patch fixes downloading files to stdout.
This patch fixes downloading files to stdout and modifies
_SwiftReader to operate as an iterator that performs file
checks at the end of iteration as well as a context manager.
File verification checks have been removed from __exit__
and added to __iter__.
Change-Id: I3250bdeeef8484a9122c4b5b854756a7c8f8731e
Closes-Bug: 1395922
Closes-Bug: 1387376
Diffstat (limited to 'tests/unit/test_shell.py')
-rw-r--r-- | tests/unit/test_shell.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index 6513263..ccf0fe9 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -290,10 +290,15 @@ class TestShell(unittest.TestCase): @mock.patch('swiftclient.service.makedirs') @mock.patch('swiftclient.service.Connection') def test_download(self, connection, makedirs): - connection.return_value.get_object.return_value = [ - {'content-type': 'text/plain', - 'etag': 'd41d8cd98f00b204e9800998ecf8427e'}, - ''] + objcontent = six.BytesIO(b'objcontent') + connection.return_value.get_object.side_effect = [ + ({'content-type': 'text/plain', + 'etag': '2cbbfe139a744d6abbe695e17f3c1991'}, + objcontent), + ({'content-type': 'text/plain', + 'etag': 'd41d8cd98f00b204e9800998ecf8427e'}, + '') + ] # Test downloading whole container connection.return_value.get_container.side_effect = [ @@ -318,6 +323,12 @@ class TestShell(unittest.TestCase): mock_open.assert_called_once_with('object', 'wb') # Test downloading single object + objcontent = six.BytesIO(b'objcontent') + connection.return_value.get_object.side_effect = [ + ({'content-type': 'text/plain', + 'etag': '2cbbfe139a744d6abbe695e17f3c1991'}, + objcontent) + ] with mock.patch(BUILTIN_OPEN) as mock_open: argv = ["", "download", "container", "object"] swiftclient.shell.main(argv) @@ -326,6 +337,18 @@ class TestShell(unittest.TestCase): response_dict={}) mock_open.assert_called_with('object', 'wb') + # Test downloading single object to stdout + objcontent = six.BytesIO(b'objcontent') + connection.return_value.get_object.side_effect = [ + ({'content-type': 'text/plain', + 'etag': '2cbbfe139a744d6abbe695e17f3c1991'}, + objcontent) + ] + with CaptureOutput() as output: + argv = ["", "download", "--output", "-", "container", "object"] + swiftclient.shell.main(argv) + self.assertEqual('objcontent', output.out) + @mock.patch('swiftclient.service.Connection') def test_download_no_content_type(self, connection): connection.return_value.get_object.return_value = [ |