Merge "Add sorting and pagination tests for trunk resources"

This commit is contained in:
Jenkins 2016-07-06 02:18:32 +00:00 committed by Gerrit Code Review
commit 77cdddb055
2 changed files with 58 additions and 6 deletions

View File

@ -491,6 +491,8 @@ class BaseSearchCriteriaTest(BaseNetworkTest):
# This should be defined by subclasses to reflect resource name to test
resource = None
field = 'name'
# NOTE(ihrachys): some names, like those starting with an underscore (_)
# are sorted differently depending on whether the plugin implements native
# sorting support, or not. So we avoid any such cases here, sticking to
@ -510,7 +512,7 @@ class BaseSearchCriteriaTest(BaseNetworkTest):
actual = list(actual)
self.assertEqual(len(original), len(actual))
for expected, res in zip(original, actual):
self.assertEqual(expected['name'], res['name'])
self.assertEqual(expected[self.field], res[self.field])
@utils.classproperty
def plural_name(self):
@ -537,13 +539,13 @@ class BaseSearchCriteriaTest(BaseNetworkTest):
def _test_list_sorts(self, direction):
sort_args = {
'sort_dir': direction,
'sort_key': 'name'
'sort_key': self.field
}
body = self.list_method(**sort_args)
resources = self._extract_resources(body)
self.assertNotEmpty(
resources, "%s list returned is empty" % self.resource)
retrieved_names = [res['name'] for res in resources]
retrieved_names = [res[self.field] for res in resources]
expected = sorted(retrieved_names)
if direction == constants.SORT_DIRECTION_DESC:
expected = list(reversed(expected))
@ -580,7 +582,7 @@ class BaseSearchCriteriaTest(BaseNetworkTest):
# first, collect all resources for later comparison
sort_args = {
'sort_dir': constants.SORT_DIRECTION_ASC,
'sort_key': 'name'
'sort_key': self.field
}
body = self.list_method(**sort_args)
expected_resources = self._extract_resources(body)
@ -666,7 +668,7 @@ class BaseSearchCriteriaTest(BaseNetworkTest):
self, direction=constants.SORT_DIRECTION_ASC):
pagination_args = {
'sort_dir': direction,
'sort_key': 'name',
'sort_key': self.field,
}
body = self.list_method(**pagination_args)
expected_resources = self._extract_resources(body)
@ -709,7 +711,7 @@ class BaseSearchCriteriaTest(BaseNetworkTest):
def _test_list_pagination_page_reverse(self, direction):
pagination_args = {
'sort_dir': direction,
'sort_key': 'name',
'sort_key': self.field,
'limit': 3,
}
body = self.list_method(**pagination_args)

View File

@ -131,3 +131,53 @@ class TrunkTestJSON(TrunkTestJSONBase):
trunk = self.client.get_subports(trunk['trunk']['id'])
observed_subports = trunk['sub_ports']
self.assertEqual(1, len(observed_subports))
class TrunksSearchCriteriaTest(base.BaseSearchCriteriaTest):
resource = 'trunk'
field = 'id'
@classmethod
def resource_setup(cls):
super(TrunksSearchCriteriaTest, cls).resource_setup()
net = cls.create_network(network_name='trunk-search-test-net')
for name in cls.resource_names:
parent_port = cls.create_port(net)
cls.client.create_trunk(parent_port['id'], [])
@test.idempotent_id('fab73df4-960a-4ae3-87d3-60992b8d3e2d')
def test_list_sorts_asc(self):
self._test_list_sorts_asc()
@test.idempotent_id('a426671d-7270-430f-82ff-8f33eec93010')
def test_list_sorts_desc(self):
self._test_list_sorts_desc()
@test.idempotent_id('b202fdc8-6616-45df-b6a0-463932de6f94')
def test_list_pagination(self):
self._test_list_pagination()
@test.idempotent_id('c4723b8e-8186-4b9a-bf9e-57519967e048')
def test_list_pagination_with_marker(self):
self._test_list_pagination_with_marker()
@test.idempotent_id('dcd02a7a-f07e-4d5e-b0ca-b58e48927a9b')
def test_list_pagination_with_href_links(self):
self._test_list_pagination_with_href_links()
@test.idempotent_id('eafe7024-77ab-4cfe-824b-0b2bf4217727')
def test_list_no_pagination_limit_0(self):
self._test_list_no_pagination_limit_0()
@test.idempotent_id('f8857391-dc44-40cc-89b7-2800402e03ce')
def test_list_pagination_page_reverse_asc(self):
self._test_list_pagination_page_reverse_asc()
@test.idempotent_id('ae51e9c9-ceae-4ec0-afd4-147569247699')
def test_list_pagination_page_reverse_desc(self):
self._test_list_pagination_page_reverse_desc()
@test.idempotent_id('b4293e59-d794-4a93-be09-38667199ef68')
def test_list_pagination_page_reverse_with_href_links(self):
self._test_list_pagination_page_reverse_with_href_links()