Add test for bulk-delete-attempt-counter fix

Change-Id: Ifdeefeb4a5a3fc6895bd6cda695684de02f8c602
Related-Change: If4af9141fe4f3436a4e9e0e2dfc24c6ec7292996
Related-Bug: #1852808
This commit is contained in:
Tim Burke 2019-11-15 22:08:51 +00:00
parent 709ab385c6
commit e83cd32e2a
2 changed files with 22 additions and 2 deletions

View File

@ -170,7 +170,7 @@ def st_delete(parser, args, output_manager, return_parser=False):
c = r.get('container', '')
o = r.get('object', '')
a = (' [after {0} attempts]'.format(r.get('attempts'))
if r.get('attempts') > 1 else '')
if r.get('attempts', 1) > 1 else '')
if r['action'] == 'bulk_delete':
if r['success']:

View File

@ -1420,12 +1420,32 @@ class TestShell(unittest.TestCase):
b'{"Number Not Found": 0, "Response Status": "200 OK", '
b'"Errors": [], "Number Deleted": 1, "Response Body": ""}')
connection.return_value.attempts = 0
swiftclient.shell.main(argv)
with CaptureOutput() as out:
swiftclient.shell.main(argv)
connection.return_value.post_account.assert_called_with(
query_string='bulk-delete', data=b'/container/object\n',
headers={'Content-Type': 'text/plain',
'Accept': 'application/json'},
response_dict={})
self.assertEqual('object\n', out.out)
@mock.patch.object(swiftclient.service.SwiftService,
'_bulk_delete_page_size', lambda *a: 10)
@mock.patch('swiftclient.service.Connection')
def test_delete_bulk_object_with_retry(self, connection):
argv = ["", "delete", "container", "object"]
connection.return_value.post_account.return_value = {}, (
b'{"Number Not Found": 0, "Response Status": "200 OK", '
b'"Errors": [], "Number Deleted": 1, "Response Body": ""}')
connection.return_value.attempts = 3
with CaptureOutput() as out:
swiftclient.shell.main(argv)
connection.return_value.post_account.assert_called_with(
query_string='bulk-delete', data=b'/container/object\n',
headers={'Content-Type': 'text/plain',
'Accept': 'application/json'},
response_dict={})
self.assertEqual('object [after 3 attempts]\n', out.out)
def test_delete_verbose_output(self):
del_obj_res = {'success': True, 'response_dict': {}, 'attempts': 2,