From fc24142ed41e15622687558c68d670bdc37223f0 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 18 Nov 2020 15:55:44 +0000 Subject: compute: Add missing options for 'keypair list' Add pagination parameters, '--limit' and '--marker'. This isn't compatible with our client-side '--project' parameter so we error out for that. Change-Id: I403cf0fb7aabad4a3dfda5adae62d47ecf7faf5c Signed-off-by: Stephen Finucane --- .../tests/unit/compute/v2/test_keypair.py | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'openstackclient/tests') diff --git a/openstackclient/tests/unit/compute/v2/test_keypair.py b/openstackclient/tests/unit/compute/v2/test_keypair.py index 5a17808f..65d9396a 100644 --- a/openstackclient/tests/unit/compute/v2/test_keypair.py +++ b/openstackclient/tests/unit/compute/v2/test_keypair.py @@ -569,6 +569,74 @@ class TestKeypairList(TestKeypair): tests_utils.ParserException, self.check_parser, self.cmd, arglist, None) + @mock.patch.object( + sdk_utils, 'supports_microversion', new=mock.Mock(return_value=True)) + def test_keypair_list_with_limit(self): + arglist = [ + '--limit', '1', + ] + verifylist = [ + ('limit', 1), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.cmd.take_action(parsed_args) + + self.sdk_client.keypairs.assert_called_with(limit=1) + + @mock.patch.object( + sdk_utils, 'supports_microversion', new=mock.Mock(return_value=False)) + def test_keypair_list_with_limit_pre_v235(self): + arglist = [ + '--limit', '1', + ] + verifylist = [ + ('limit', 1), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + ex = self.assertRaises( + exceptions.CommandError, + self.cmd.take_action, + parsed_args) + + self.assertIn( + '--os-compute-api-version 2.35 or greater is required', str(ex)) + + @mock.patch.object( + sdk_utils, 'supports_microversion', new=mock.Mock(return_value=True)) + def test_keypair_list_with_marker(self): + arglist = [ + '--marker', 'test_kp', + ] + verifylist = [ + ('marker', 'test_kp'), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.cmd.take_action(parsed_args) + + self.sdk_client.keypairs.assert_called_with(marker='test_kp') + + @mock.patch.object( + sdk_utils, 'supports_microversion', new=mock.Mock(return_value=False)) + def test_keypair_list_with_marker_pre_v235(self): + arglist = [ + '--marker', 'test_kp', + ] + verifylist = [ + ('marker', 'test_kp'), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + ex = self.assertRaises( + exceptions.CommandError, + self.cmd.take_action, + parsed_args) + + self.assertIn( + '--os-compute-api-version 2.35 or greater is required', str(ex)) + class TestKeypairShow(TestKeypair): -- cgit v1.2.1