diff options
author | Zuul <zuul@review.opendev.org> | 2019-07-10 18:54:30 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-07-10 18:54:30 +0000 |
commit | 2fcd4d872713dc30e7352845c37515280f1d21ab (patch) | |
tree | 76024c37110dfa755e8d0e752b1537c152aba3cf /tests/unit/test_shell.py | |
parent | 7cf8541b38a8782decdd27cb37909e737ed67b8a (diff) | |
parent | 936631eac617c83bec1f1c44b1adcaa51d36329c (diff) | |
download | python-swiftclient-2fcd4d872713dc30e7352845c37515280f1d21ab.tar.gz |
Merge "Optionally display listings in raw json"
Diffstat (limited to 'tests/unit/test_shell.py')
-rw-r--r-- | tests/unit/test_shell.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index f729c25..d9ddb3e 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -298,6 +298,26 @@ class TestShell(unittest.TestCase): headers={'Skip-Middleware': 'Test'})]) @mock.patch('swiftclient.service.Connection') + def test_list_json(self, connection): + connection.return_value.get_account.side_effect = [ + [None, [{'name': 'container'}]], + [None, [{'name': u'\u263A', 'some-custom-key': 'and value'}]], + [None, []], + ] + + argv = ["", "list", "--json"] + with CaptureOutput(suppress_systemexit=True) as output: + swiftclient.shell.main(argv) + calls = [mock.call(marker='', prefix=None, headers={}), + mock.call(marker='container', prefix=None, headers={})] + connection.return_value.get_account.assert_has_calls(calls) + + listing = [{'name': 'container'}, + {'name': u'\u263A', 'some-custom-key': 'and value'}] + expected = json.dumps(listing, sort_keys=True, indent=2) + '\n' + self.assertEqual(output.out, expected) + + @mock.patch('swiftclient.service.Connection') def test_list_account(self, connection): # Test account listing connection.return_value.get_account.side_effect = [ |