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
This commit is contained in:
parent
0f60cf05f4
commit
b7d20b8a18
@ -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)
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user