summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Suchomel <jsuchome@suse.cz>2014-10-23 10:48:33 +0200
committerAlistair Coles <alistair.coles@hp.com>2015-01-05 11:02:00 +0000
commit5d5701870702a554dcea61213999670ee15f4ea8 (patch)
tree87f477e3163702fd4ef0bf8d1addf24d05063bf6
parent2dde767e93f15dd7fb0fbb59fcbd416e384cf2a4 (diff)
downloadpython-swiftclient-5d5701870702a554dcea61213999670ee15f4ea8.tar.gz
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
-rwxr-xr-xswiftclient/shell.py5
-rw-r--r--tests/unit/test_shell.py27
2 files changed, 32 insertions, 0 deletions
diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index d58de60..c3f4628 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -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:
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py
index e6434dc..65530bc 100644
--- a/tests/unit/test_shell.py
+++ b/tests/unit/test_shell.py
@@ -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 = [