diff options
author | Tim Burke <tim.burke@gmail.com> | 2020-04-10 17:16:11 -0700 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2020-04-10 17:16:15 -0700 |
commit | 9b0da49c0b337585e24825de2ad670a0798179ac (patch) | |
tree | 64c9884888f53609f91cc4eef8778bc53bb35547 /test/unit/test_shell.py | |
parent | 78edffa46c591fdc53f253b343e1ea144e24089d (diff) | |
download | python-swiftclient-9b0da49c0b337585e24825de2ad670a0798179ac.tar.gz |
Improve `list --versions` output
Have `--versions` imply `--long` and add a new column for version_id.
Also, have version-aware listings show all versions as "null" on old
Swifts that don't support object versioning (or when object versioning
is not enabled).
Change-Id: I0e009bce2471d1c140ac9b83700591cb355fee3f
Diffstat (limited to 'test/unit/test_shell.py')
-rw-r--r-- | test/unit/test_shell.py | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/test/unit/test_shell.py b/test/unit/test_shell.py index b94cdcf..a63d16b 100644 --- a/test/unit/test_shell.py +++ b/test/unit/test_shell.py @@ -334,8 +334,15 @@ class TestShell(unittest.TestCase): def test_list_container_with_versions(self, connection): connection.return_value.get_container.side_effect = [ [None, [ - {'name': 'foo', 'version_id': '2'}, - {'name': 'foo', 'version_id': '1'}, + {'name': 'foo', 'version_id': '2', + 'content_type': 'text/plain', + 'last_modified': '123T456', 'bytes': 78}, + {'name': 'foo', 'version_id': '1', + 'content_type': 'text/rtf', + 'last_modified': '123T456', 'bytes': 90}, + {'name': 'bar', 'version_id': 'null', + 'content_type': 'text/plain', + 'last_modified': '123T456', 'bytes': 123}, ]], [None, []], ] @@ -346,10 +353,46 @@ class TestShell(unittest.TestCase): prefix=None, query_string='versions=true', version_marker=''), mock.call('container', delimiter=None, headers={}, - marker='foo', prefix=None, - query_string='versions=true', version_marker='1')] + marker='bar', prefix=None, + query_string='versions=true', + version_marker='null')] connection.return_value.get_container.assert_has_calls(calls) - self.assertEqual(output.out, 'foo\nfoo\n') + self.assertEqual([line.split() for line in output.out.split('\n')], [ + ['78', '123', '456', '2', 'text/plain', 'foo'], + ['90', '123', '456', '1', 'text/rtf', 'foo'], + ['123', '123', '456', 'null', 'text/plain', 'bar'], + [], + ]) + + @mock.patch('swiftclient.service.Connection') + def test_list_container_with_versions_old_swift(self, connection): + # Versions of swift that don't support object-versioning won't + # include verison_id keys in listings. We want to present that + # as though the container is unversioned. + connection.return_value.get_container.side_effect = [ + [None, [ + {'name': 'foo', 'content_type': 'text/plain', + 'last_modified': '123T456', 'bytes': 78}, + {'name': 'bar', 'content_type': 'text/plain', + 'last_modified': '123T456', 'bytes': 123}, + ]], + [None, []], + ] + argv = ["", "list", "container", "--versions"] + with CaptureOutput(suppress_systemexit=True) as output: + swiftclient.shell.main(argv) + calls = [mock.call('container', delimiter=None, headers={}, marker='', + prefix=None, query_string='versions=true', + version_marker=''), + mock.call('container', delimiter=None, headers={}, + marker='bar', prefix=None, + query_string='versions=true', version_marker='')] + connection.return_value.get_container.assert_has_calls(calls) + self.assertEqual([line.split() for line in output.out.split('\n')], [ + ['78', '123', '456', 'null', 'text/plain', 'foo'], + ['123', '123', '456', 'null', 'text/plain', 'bar'], + [], + ]) def test_list_account_with_versions(self): argv = ["", "list", "--versions"] |