diff options
| author | Jenkins <jenkins@review.openstack.org> | 2015-03-16 20:12:42 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2015-03-16 20:12:42 +0000 |
| commit | 6db625f287ffcce80df65d25a117ceb0de2ea776 (patch) | |
| tree | 8429166f39dbfcd22556159decae209797a3a125 /tests | |
| parent | 82143e26d36431d4600beef833d6b681119c9245 (diff) | |
| parent | 3f3066be97349677fd489703effb85f45c0cdd76 (diff) | |
| download | python-glanceclient-6db625f287ffcce80df65d25a117ceb0de2ea776.tar.gz | |
Merge "Extend images CLI v2 with new sorting syntax"
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/v2/test_images.py | 48 | ||||
| -rw-r--r-- | tests/v2/test_shell_v2.py | 42 |
2 files changed, 87 insertions, 3 deletions
diff --git a/tests/v2/test_images.py b/tests/v2/test_images.py index 1082f26..00b06e3 100644 --- a/tests/v2/test_images.py +++ b/tests/v2/test_images.py @@ -473,6 +473,22 @@ data_fixtures = { ]}, ), }, + '/v2/images?limit=%d&sort=name%%3Adesc%%2Csize%%3Aasc' + % 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 = { @@ -679,6 +695,13 @@ class TestController(testtools.TestCase): self.assertEqual(2, len(images)) self.assertEqual('%s' % img_id1, images[1].id) + def test_list_images_with_new_sorting_syntax(self): + img_id1 = '2a4560b2-e585-443e-9b39-553b46ec92d1' + sort = 'name:desc,size:asc' + images = list(self.controller.list(sort=sort)) + self.assertEqual(2, len(images)) + self.assertEqual('%s' % img_id1, images[1].id) + def test_list_images_sort_dirs_fewer_than_keys(self): sort_key = ['name', 'id', 'created_at'] sort_dir = ['desc', 'asc'] @@ -688,6 +711,31 @@ class TestController(testtools.TestCase): sort_key=sort_key, sort_dir=sort_dir)) + def test_list_images_combined_syntax(self): + sort_key = ['name', 'id'] + sort_dir = ['desc', 'asc'] + sort = 'name:asc' + self.assertRaises(exc.HTTPBadRequest, + list, + self.controller.list( + sort=sort, + sort_key=sort_key, + sort_dir=sort_dir)) + + def test_list_images_new_sorting_syntax_invalid_key(self): + sort = 'INVALID:asc' + self.assertRaises(exc.HTTPBadRequest, + list, + self.controller.list( + sort=sort)) + + def test_list_images_new_sorting_syntax_invalid_direction(self): + sort = 'name:INVALID' + self.assertRaises(exc.HTTPBadRequest, + list, + self.controller.list( + sort=sort)) + 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 033585d..fc8f2db 100644 --- a/tests/v2/test_shell_v2.py +++ b/tests/v2/test_shell_v2.py @@ -70,7 +70,8 @@ class ShellV2Test(testtools.TestCase): 'tag': 'fake tag', 'properties': [], 'sort_key': ['name', 'id'], - 'sort_dir': ['desc', 'asc'] + 'sort_dir': ['desc', 'asc'], + 'sort': None } args = self._make_args(input) with mock.patch.object(self.gc.images, 'list') as mocked_list: @@ -102,7 +103,8 @@ class ShellV2Test(testtools.TestCase): 'tag': 'fake tag', 'properties': [], 'sort_key': ['name'], - 'sort_dir': ['desc'] + 'sort_dir': ['desc'], + 'sort': None } args = self._make_args(input) with mock.patch.object(self.gc.images, 'list') as mocked_list: @@ -123,6 +125,39 @@ class ShellV2Test(testtools.TestCase): filters=exp_img_filters) utils.print_list.assert_called_once_with({}, ['ID', 'Name']) + def test_do_image_list_new_sorting_syntax(self): + input = { + 'limit': None, + 'page_size': 18, + 'visibility': True, + 'member_status': 'Fake', + 'owner': 'test', + 'checksum': 'fake_checksum', + 'tag': 'fake tag', + 'properties': [], + 'sort': 'name:desc,size:asc', + 'sort_key': [], + 'sort_dir': [] + } + 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='name:desc,size:asc', + filters=exp_img_filters) + utils.print_list.assert_called_once_with({}, ['ID', 'Name']) + def test_do_image_list_with_property_filter(self): input = { 'limit': None, @@ -134,7 +169,8 @@ class ShellV2Test(testtools.TestCase): 'tag': 'fake tag', 'properties': ['os_distro=NixOS', 'architecture=x86_64'], 'sort_key': ['name'], - 'sort_dir': ['desc'] + 'sort_dir': ['desc'], + 'sort': None } args = self._make_args(input) with mock.patch.object(self.gc.images, 'list') as mocked_list: |
