diff options
| author | Jenkins <jenkins@review.openstack.org> | 2015-03-16 20:11:34 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2015-03-16 20:11:34 +0000 |
| commit | c32a41415ded280cb4a5d78254290ed6213deb82 (patch) | |
| tree | a2475cf0a3d29fd76719096e9b3658078d8fd48f /tests | |
| parent | 7c54b14cf042d5febfbd1d835af9052fa2231e8a (diff) | |
| parent | fc79467ff6813e0b1fe02d078ac55de79ea526b2 (diff) | |
| download | python-glanceclient-c32a41415ded280cb4a5d78254290ed6213deb82.tar.gz | |
Merge "Adds the ability to sort images with multiple keys"
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/v2/test_images.py | 71 | ||||
| -rw-r--r-- | tests/v2/test_shell_v2.py | 44 |
2 files changed, 112 insertions, 3 deletions
diff --git a/tests/v2/test_images.py b/tests/v2/test_images.py index f4abec4..ec48e3e 100644 --- a/tests/v2/test_images.py +++ b/tests/v2/test_images.py @@ -394,9 +394,55 @@ data_fixtures = { {'images': []}, ), }, + '/v2/images?limit=%d&sort_key=name' % images.DEFAULT_PAGE_SIZE: { + 'GET': ( + {}, + {'images': [ + { + 'id': '2a4560b2-e585-443e-9b39-553b46ec92d1', + 'name': 'image-1', + }, + { + 'id': '6f99bf80-2ee6-47cf-acfe-1f1fabb7e810', + 'name': 'image-2', + }, + ]}, + ), + }, + '/v2/images?limit=%d&sort_key=name&sort_key=id' + % images.DEFAULT_PAGE_SIZE: { + 'GET': ( + {}, + {'images': [ + { + 'id': '2a4560b2-e585-443e-9b39-553b46ec92d1', + 'name': 'image', + }, + { + 'id': '6f99bf80-2ee6-47cf-acfe-1f1fabb7e810', + 'name': 'image', + }, + ]}, + ), + }, + '/v2/images?limit=%d&sort_dir=desc&sort_key=id' + % images.DEFAULT_PAGE_SIZE: { + 'GET': ( + {}, + {'images': [ + { + 'id': '6f99bf80-2ee6-47cf-acfe-1f1fabb7e810', + 'name': 'image-2', + }, + { + 'id': '2a4560b2-e585-443e-9b39-553b46ec92d1', + 'name': 'image-1', + }, + ]}, + ), + } } - schema_fixtures = { 'image': { 'GET': ( @@ -560,6 +606,29 @@ class TestController(testtools.TestCase): images = list(self.controller.list(**filters)) self.assertEqual(0, len(images)) + def test_list_images_with_single_sort_key(self): + img_id1 = '2a4560b2-e585-443e-9b39-553b46ec92d1' + sort_key = 'name' + images = list(self.controller.list(sort_key=sort_key)) + self.assertEqual(2, len(images)) + self.assertEqual('%s' % img_id1, images[0].id) + + def test_list_with_multiple_sort_keys(self): + img_id1 = '2a4560b2-e585-443e-9b39-553b46ec92d1' + sort_key = ['name', 'id'] + images = list(self.controller.list(sort_key=sort_key)) + self.assertEqual(2, len(images)) + self.assertEqual('%s' % img_id1, images[0].id) + + def test_list_images_with_desc_sort_dir(self): + img_id1 = '2a4560b2-e585-443e-9b39-553b46ec92d1' + sort_key = 'id' + sort_dir = 'desc' + images = list(self.controller.list(sort_key=sort_key, + sort_dir=sort_dir)) + self.assertEqual(2, len(images)) + self.assertEqual('%s' % img_id1, images[1].id) + def test_list_images_for_property(self): filters = {'filters': dict([('os_distro', 'NixOS')])} images = list(self.controller.list(**filters)) diff --git a/tests/v2/test_shell_v2.py b/tests/v2/test_shell_v2.py index 25d7d99..84137e9 100644 --- a/tests/v2/test_shell_v2.py +++ b/tests/v2/test_shell_v2.py @@ -68,7 +68,9 @@ class ShellV2Test(testtools.TestCase): 'owner': 'test', 'checksum': 'fake_checksum', 'tag': 'fake tag', - 'properties': [] + 'properties': [], + 'sort_key': ['name', 'id'], + 'sort_dir': 'desc' } args = self._make_args(input) with mock.patch.object(self.gc.images, 'list') as mocked_list: @@ -84,6 +86,40 @@ class ShellV2Test(testtools.TestCase): 'tag': 'fake tag' } mocked_list.assert_called_once_with(page_size=18, + sort_key=['name', 'id'], + sort_dir='desc', + filters=exp_img_filters) + utils.print_list.assert_called_once_with({}, ['ID', 'Name']) + + def test_do_image_list_with_single_sort_key(self): + input = { + 'limit': None, + 'page_size': 18, + 'visibility': True, + 'member_status': 'Fake', + 'owner': 'test', + 'checksum': 'fake_checksum', + 'tag': 'fake tag', + 'properties': [], + 'sort_key': ['name'], + 'sort_dir': 'desc' + } + args = self._make_args(input) + with mock.patch.object(self.gc.images, 'list') as mocked_list: + mocked_list.return_value = {} + + test_shell.do_image_list(self.gc, args) + + exp_img_filters = { + 'owner': 'test', + 'member_status': 'Fake', + 'visibility': True, + 'checksum': 'fake_checksum', + 'tag': 'fake tag' + } + mocked_list.assert_called_once_with(page_size=18, + sort_key=['name'], + sort_dir='desc', filters=exp_img_filters) utils.print_list.assert_called_once_with({}, ['ID', 'Name']) @@ -96,7 +132,9 @@ class ShellV2Test(testtools.TestCase): 'owner': 'test', 'checksum': 'fake_checksum', 'tag': 'fake tag', - 'properties': ['os_distro=NixOS', 'architecture=x86_64'] + 'properties': ['os_distro=NixOS', 'architecture=x86_64'], + 'sort_key': ['name'], + 'sort_dir': 'desc' } args = self._make_args(input) with mock.patch.object(self.gc.images, 'list') as mocked_list: @@ -115,6 +153,8 @@ class ShellV2Test(testtools.TestCase): } mocked_list.assert_called_once_with(page_size=1, + sort_key=['name'], + sort_dir='desc', filters=exp_img_filters) utils.print_list.assert_called_once_with({}, ['ID', 'Name']) |
