Print info message about incorrect --totals usage

when neither -l nor --lh is provided.
Added test coverage for --totals.

Change-Id: I3245e715c26ec28457a21dec07311a58c475c066
Closes-Bug: 1258392
This commit is contained in:
Jiří Suchomel 2014-10-23 10:48:33 +02:00 committed by Alistair Coles
parent 2dde767e93
commit 5d57018707
2 changed files with 32 additions and 0 deletions
swiftclient
tests/unit

@ -378,6 +378,11 @@ def st_list(parser, args, output_manager):
_opts.pop('human')
_opts['long'] = True
if options.totals and not options.long and not options.human:
output_manager.error(
"Listing totals only works with -l or --lh.")
return
with SwiftService(options=_opts) as swift:
try:
if not args:

@ -225,6 +225,33 @@ class TestShell(unittest.TestCase):
' 0 0 ????-??-?? ??:??:?? container\n'
' 0 0\n')
@mock.patch('swiftclient.shell.OutputManager._print')
@mock.patch('swiftclient.service.Connection')
def test_list_account_totals_error(self, connection, error):
# No --lh provided: expect info message about incorrect --totals use
argv = ["", "list", "--totals"]
self.assertRaises(SystemExit, swiftclient.shell.main, argv)
self.assertEqual(error.call_args[0][0],
"Listing totals only works with -l or --lh.")
@mock.patch('swiftclient.shell.OutputManager._print')
@mock.patch('swiftclient.service.Connection')
def test_list_account_totals(self, connection, mock_print):
# Test account listing, only total count and size
connection.return_value.get_account.side_effect = [
[None, [{'name': 'container1', 'bytes': 1, 'count': 2},
{'name': 'container2', 'bytes': 2, 'count': 4}]],
[None, []],
]
argv = ["", "list", "--lh", "--totals"]
swiftclient.shell.main(argv)
calls = [mock.call(marker='', prefix=None)]
connection.return_value.get_account.assert_has_calls(calls)
mock_print.assert_called_once_with(' 6 3')
@mock.patch('swiftclient.service.Connection')
def test_list_container(self, connection):
connection.return_value.get_container.side_effect = [