From c909b127c309f586470689f7a6f345798a30b9ee Mon Sep 17 00:00:00 2001 From: xiexs Date: Mon, 21 Mar 2016 02:17:33 -0400 Subject: [PATCH] Add unit tests for ContainerManager.list() method The ContainerManager.list() has already supported the pagination and sorting features, but there is no unit case to cover them. This patch tries to add some tests for them. Change-Id: I8fb6767b64848e1f829aaeffc0f44a4bc3e4966d Partial-Bug: #1559838 --- magnumclient/tests/v1/test_containers.py | 106 +++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/magnumclient/tests/v1/test_containers.py b/magnumclient/tests/v1/test_containers.py index 2a70ff58..fd85d8c3 100644 --- a/magnumclient/tests/v1/test_containers.py +++ b/magnumclient/tests/v1/test_containers.py @@ -198,6 +198,48 @@ fake_responses = { {'output': '/home'}, ), }, + '/v1/containers/?limit=2': + { + 'GET': ( + {}, + {'containers': [CONTAINER1, CONTAINER2]}, + ), + }, + '/v1/containers/?marker=%s' % CONTAINER2['uuid']: + { + 'GET': ( + {}, + {'containers': [CONTAINER1, CONTAINER2]}, + ), + }, + '/v1/containers/?limit=2&marker=%s' % CONTAINER2['uuid']: + { + 'GET': ( + {}, + {'containers': [CONTAINER1, CONTAINER2]}, + ), + }, + '/v1/containers/?sort_dir=asc': + { + 'GET': ( + {}, + {'containers': [CONTAINER1, CONTAINER2]}, + ), + }, + '/v1/containers/?sort_key=uuid': + { + 'GET': ( + {}, + {'containers': [CONTAINER1, CONTAINER2]}, + ), + }, + '/v1/containers/?sort_key=uuid&sort_dir=desc': + { + 'GET': ( + {}, + {'containers': [CONTAINER2, CONTAINER1]}, + ), + }, } @@ -226,6 +268,70 @@ class ContainerManagerTest(testtools.TestCase): self.assertEqual(expect, self.api.calls) self.assertThat(containers, matchers.HasLength(2)) + def _test_container_list_with_filters( + self, limit=None, marker=None, + sort_key=None, sort_dir=None, + detail=False, expect=[]): + containers_filter = self.mgr.list(limit=limit, marker=marker, + sort_key=sort_key, + sort_dir=sort_dir, + detail=detail) + self.assertEqual(expect, self.api.calls) + self.assertThat(containers_filter, matchers.HasLength(2)) + + def test_container_list_with_limit(self): + expect = [ + ('GET', '/v1/containers/?limit=2', {}, None), + ] + self._test_container_list_with_filters( + limit=2, + expect=expect) + + def test_container_list_with_marker(self): + expect = [ + ('GET', '/v1/containers/?marker=%s' % CONTAINER2['uuid'], + {}, None), + ] + self._test_container_list_with_filters( + marker=CONTAINER2['uuid'], + expect=expect) + + def test_container_list_with_marker_limit(self): + expect = [ + ('GET', '/v1/containers/?limit=2&marker=%s' % CONTAINER2['uuid'], + {}, None), + ] + self._test_container_list_with_filters( + limit=2, marker=CONTAINER2['uuid'], + expect=expect) + + def test_container_list_with_sort_dir(self): + expect = [ + ('GET', '/v1/containers/?sort_dir=asc', + {}, None), + ] + self._test_container_list_with_filters( + sort_dir='asc', + expect=expect) + + def test_container_list_with_sort_key(self): + expect = [ + ('GET', '/v1/containers/?sort_key=uuid', + {}, None), + ] + self._test_container_list_with_filters( + sort_key='uuid', + expect=expect) + + def test_container_list_with_sort_key_dir(self): + expect = [ + ('GET', '/v1/containers/?sort_key=uuid&sort_dir=desc', + {}, None), + ] + self._test_container_list_with_filters( + sort_key='uuid', sort_dir='desc', + expect=expect) + def test_container_show(self): container = self.mgr.get(CONTAINER1['id']) expect = [