diff options
| author | Joel Wright <joel.wright@sohonet.com> | 2014-10-14 16:54:41 +0100 |
|---|---|---|
| committer | Joel Wright <joel.wright@sohonet.com> | 2015-07-20 20:44:51 +0100 |
| commit | a8c4df98eee43b419d6dd30e80c838d9f2efd025 (patch) | |
| tree | 31eaad7eb51f4c9ad1e04b073887b270cc6b9edc /tests/unit/test_shell.py | |
| parent | 63998b481c7fd2d242efa12e2ca5b959bcdd113b (diff) | |
| download | python-swiftclient-a8c4df98eee43b419d6dd30e80c838d9f2efd025.tar.gz | |
Reduce memory usage for download/delete and add --no-shuffle option to st_download
The current code builds a full object listing before performing either a multiple
download or delete operation (and also shuffles this complete list in the case of
a download). This patch removes the creation of the full object list and adds the
ability to turn off shuffle for files when downloading. Also added is a limit on
the number of list results that can be queued by a single call to service.list
without consuming results (reduces memory overhead for large listings).
Some tests added for service.py download and list.
Change-Id: Ie737cbb7f8b1fa8a79bbb88914730b05aa7f2906
Diffstat (limited to 'tests/unit/test_shell.py')
| -rw-r--r-- | tests/unit/test_shell.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index 8384f7a..5f9d497 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -377,6 +377,62 @@ class TestShell(unittest.TestCase): swiftclient.shell.main(argv) self.assertEqual('objcontent', output.out) + @mock.patch('swiftclient.service.shuffle') + @mock.patch('swiftclient.service.Connection') + def test_download_shuffle(self, connection, mock_shuffle): + # Test that the container and object lists are shuffled + mock_shuffle.side_effect = lambda l: l + connection.return_value.get_object.return_value = [ + {'content-type': 'text/plain', + 'etag': EMPTY_ETAG}, + ''] + + connection.return_value.get_container.side_effect = [ + (None, [{'name': 'object'}]), + (None, [{'name': 'pseudo/'}]), + (None, []), + ] + connection.return_value.auth_end_time = 0 + connection.return_value.attempts = 0 + connection.return_value.get_account.side_effect = [ + (None, [{'name': 'container'}]), + (None, []) + ] + + with mock.patch(BUILTIN_OPEN) as mock_open: + argv = ["", "download", "--all"] + swiftclient.shell.main(argv) + self.assertEqual(3, mock_shuffle.call_count) + mock_shuffle.assert_any_call(['container']) + mock_shuffle.assert_any_call(['object']) + mock_shuffle.assert_any_call(['pseudo/']) + mock_open.assert_called_once_with('container/object', 'wb') + + # Test that the container and object lists are not shuffled + mock_shuffle.reset_mock() + connection.return_value.get_object.return_value = [ + {'content-type': 'text/plain', + 'etag': 'd41d8cd98f00b204e9800998ecf8427e'}, + ''] + + connection.return_value.get_container.side_effect = [ + (None, [{'name': 'object'}]), + (None, [{'name': 'pseudo/'}]), + (None, []), + ] + connection.return_value.auth_end_time = 0 + connection.return_value.attempts = 0 + connection.return_value.get_account.side_effect = [ + (None, [{'name': 'container'}]), + (None, []) + ] + + with mock.patch(BUILTIN_OPEN) as mock_open: + argv = ["", "download", "--all", "--no-shuffle"] + swiftclient.shell.main(argv) + self.assertEqual(0, mock_shuffle.call_count) + mock_open.assert_called_once_with('container/object', 'wb') + @mock.patch('swiftclient.service.Connection') def test_download_no_content_type(self, connection): connection.return_value.get_object.return_value = [ |
