From 61a40343fdbb89a1c6404ab03fcfd84daee31c9e Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 21 Jan 2015 15:02:58 -0600 Subject: Add filter to image list * Hides previously broken --page-size option * Adds --property to image list for filtering on properties * Adds Visibility, Protected, Owner, Properties/Tags to --long output * Adds api.utils.simple_filter() for selecting matches out of a list of objects * Adds tests for all of the above * Updates image docs There are additional filtering options to be added in later reviews. Change-Id: I32feff0ad61aae749b33621c817658d7dc90c3aa Closes-bug: 1401902 --- openstackclient/tests/image/v1/test_image.py | 53 ++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'openstackclient/tests/image/v1') diff --git a/openstackclient/tests/image/v1/test_image.py b/openstackclient/tests/image/v1/test_image.py index 88809966..355f8c82 100644 --- a/openstackclient/tests/image/v1/test_image.py +++ b/openstackclient/tests/image/v1/test_image.py @@ -407,8 +407,18 @@ class TestImageList(TestImage): detailed=True, ) - collist = ('ID', 'Name', 'Disk Format', 'Container Format', - 'Size', 'Status') + collist = ( + 'ID', + 'Name', + 'Disk Format', + 'Container Format', + 'Size', + 'Status', + 'Visibility', + 'Protected', + 'Owner', + 'Properties', + ) self.assertEqual(collist, columns) datalist = (( @@ -418,6 +428,45 @@ class TestImageList(TestImage): '', '', '', + 'public', + False, + image_fakes.image_owner, + "Alpha='a', Beta='b', Gamma='g'", + ), ) + self.assertEqual(datalist, tuple(data)) + + @mock.patch('openstackclient.api.utils.simple_filter') + def test_image_list_property_option(self, sf_mock): + sf_mock.return_value = [ + copy.deepcopy(image_fakes.IMAGE), + ] + + arglist = [ + '--property', 'a=1', + ] + verifylist = [ + ('property', {'a': '1'}), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # DisplayCommandBase.take_action() returns two tuples + columns, data = self.cmd.take_action(parsed_args) + self.api_mock.image_list.assert_called_with( + detailed=True, + ) + sf_mock.assert_called_with( + [image_fakes.IMAGE], + attr='a', + value='1', + property_field='properties', + ) + + collist = ('ID', 'Name') + + self.assertEqual(columns, collist) + datalist = (( + image_fakes.image_id, + image_fakes.image_name, ), ) self.assertEqual(datalist, tuple(data)) -- cgit v1.2.1