From b7d20b8a1899897e560d378b624163cf1ee1d299 Mon Sep 17 00:00:00 2001 From: Hu Bing <hubingsh@cn.ibm.com> Date: Fri, 26 Feb 2016 00:20:29 +0800 Subject: [PATCH] download method shouldn't download all object in python-swiftclient/swiftclient/service.py, there is a method def download(self, container=None, objects=None, options=None): if container is specified but objects not, it download all objects in specified container. if both container and objects are specified, it download all specified objects in the container. when it comes to the case that, objects argument is specified, but it turned out to be empty array [ ], the download method download all the objects under specified container. this may be not reasonable. for example, the objects was not empty when it came from command line, but it's filtered, maybe by --prefix argument. at last, it turned out to be empty array. when calling download method with objects arguments being empty array, we should download nothing instead of all the objects under the specified container. Change-Id: I81aab935533a50b40679c8b3575f298c285233a8 Closes-bug: #1549881 --- swiftclient/service.py | 2 +- tests/unit/test_service.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/swiftclient/service.py b/swiftclient/service.py index 5fa2870b..f253ec86 100644 --- a/swiftclient/service.py +++ b/swiftclient/service.py @@ -1004,7 +1004,7 @@ class SwiftService(object): raise raise SwiftError('Account not found', exc=err) - elif not objects: + elif objects is None: if '/' in container: raise SwiftError('\'/\' in container name', container=container) diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py index 3fbe987a..dcd2b854 100644 --- a/tests/unit/test_service.py +++ b/tests/unit/test_service.py @@ -1690,6 +1690,22 @@ class TestServiceDownload(_TestServiceBase): self.assertEqual(resp['object'], 'test') self.assertEqual(resp['path'], 'test') + @mock.patch('swiftclient.service.interruptable_as_completed') + @mock.patch('swiftclient.service.SwiftService._download_container') + @mock.patch('swiftclient.service.SwiftService._download_object_job') + def test_download_with_objects_empty(self, mock_down_obj, + mock_down_cont, mock_as_comp): + fake_future = Future() + fake_future.set_result(1) + mock_as_comp.return_value = [fake_future] + service = SwiftService() + next(service.download('c', [], self.opts), None) + mock_down_obj.assert_not_called() + mock_down_cont.assert_not_called() + + next(service.download('c', options=self.opts), None) + self.assertEqual(True, mock_down_cont.called) + def test_download_with_output_dir(self): service = SwiftService() with mock.patch('swiftclient.service.Connection') as mock_conn: