Fix sort of *list command output
While sorting output of list command ("audittemplate list",
"strategy list", etc) by sort-key that is not belongs
to specific model, this sort-key was passed to db what
caused error (HTTP 500). We added check on such keys and now,
if got one of them, then we make sort on API side
instead of db side.
We removed excess sort and changed all sorting routines
to unified way.
Also added sort tests on every model.
Change-Id: I41faea1622605ee4fa8dc48cd572876d75be8383
Closes-Bug: 1662887
This commit is contained in:
@@ -221,6 +221,27 @@ class TestListStrategy(api_base.FunctionalTest):
|
||||
for strategy in strategies:
|
||||
self.assertEqual(goal1['uuid'], strategy['goal_uuid'])
|
||||
|
||||
def test_many_with_sort_key_goal_uuid(self):
|
||||
goals_uuid_list = []
|
||||
for idx in range(1, 6):
|
||||
strategy = obj_utils.create_test_strategy(
|
||||
self.context, id=idx,
|
||||
uuid=utils.generate_uuid(),
|
||||
name='STRATEGY_{0}'.format(idx))
|
||||
goals_uuid_list.append(strategy.goal.uuid)
|
||||
|
||||
response = self.get_json('/strategies/?sort_key=goal_uuid')
|
||||
|
||||
self.assertEqual(5, len(response['strategies']))
|
||||
goal_uuids = [s['goal_uuid'] for s in response['strategies']]
|
||||
self.assertEqual(sorted(goals_uuid_list), goal_uuids)
|
||||
|
||||
def test_sort_key_validation(self):
|
||||
response = self.get_json(
|
||||
'/strategies?sort_key=%s' % 'bad_name',
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, response.status_int)
|
||||
|
||||
|
||||
class TestStrategyPolicyEnforcement(api_base.FunctionalTest):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user