From d99faddc5ab6f1858cb9cf716ea1a8e602bb4ce9 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Wed, 7 Mar 2018 03:54:11 +0000 Subject: [PATCH] Unify the format of list response Change the format of container_actions response for consistency with other APIs. Right now, all the list response is of the following format: {"xxx" [{...}, ...]} Change-Id: I388548a1c15e61b62e802da634c7be8697ff05b9 --- .../samples/container-actions-list-resp.json | 43 ++++++++++--------- zun/api/controllers/v1/containers.py | 2 +- .../api/controllers/v1/test_containers.py | 5 ++- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/api-ref/source/samples/container-actions-list-resp.json b/api-ref/source/samples/container-actions-list-resp.json index 945da5969..d8591fbc5 100644 --- a/api-ref/source/samples/container-actions-list-resp.json +++ b/api-ref/source/samples/container-actions-list-resp.json @@ -1,21 +1,22 @@ -[ - { - "action": "create", - "container_uuid": "b48316c5-71e8-45e4-9884-6c78055b9b13", - "message": null, - "project_id": "853719b303ef4858a195535eb520e58d", - "request_id": "req-25517360-b757-47d3-be45-0e8d2a01b36a", - "start_time": "2018-03-04 19:48:49+00:00", - "user_id": "22e81669093742b7a74b1d715a9a5813" - }, - { - "action": "stop", - "container_uuid": "b48316c5-71e8-45e4-9884-6c78055b9b13", - "message": null, - "project_id": "853719b303ef4858a195535eb520e58d", - "request_id": "req-3293a3f1-b44c-4609-b8d2-d81b105636b8", - "start_time": "2018-03-04 17:02:54+00:00", - "user_id": "22e81669093742b7a74b1d715a9a5813" - } -] - +{ + "containerActions": [ + { + "action": "create", + "container_uuid": "b48316c5-71e8-45e4-9884-6c78055b9b13", + "message": null, + "project_id": "853719b303ef4858a195535eb520e58d", + "request_id": "req-25517360-b757-47d3-be45-0e8d2a01b36a", + "start_time": "2018-03-04 19:48:49+00:00", + "user_id": "22e81669093742b7a74b1d715a9a5813" + }, + { + "action": "stop", + "container_uuid": "b48316c5-71e8-45e4-9884-6c78055b9b13", + "message": null, + "project_id": "853719b303ef4858a195535eb520e58d", + "request_id": "req-3293a3f1-b44c-4609-b8d2-d81b105636b8", + "start_time": "2018-03-04 17:02:54+00:00", + "user_id": "22e81669093742b7a74b1d715a9a5813" + } + ] +} diff --git a/zun/api/controllers/v1/containers.py b/zun/api/controllers/v1/containers.py index b9f8aca4b..f5db405e4 100644 --- a/zun/api/controllers/v1/containers.py +++ b/zun/api/controllers/v1/containers.py @@ -115,7 +115,7 @@ class ContainersActionsController(base.Controller): context, container.uuid) actions = [self._format_action(action) for action in actions_raw] - return actions + return {"containerActions": actions} @pecan.expose('json') @exception.wrap_pecan_controller_exception diff --git a/zun/tests/unit/api/controllers/v1/test_containers.py b/zun/tests/unit/api/controllers/v1/test_containers.py index a4192f5be..cd4a9aa28 100644 --- a/zun/tests/unit/api/controllers/v1/test_containers.py +++ b/zun/tests/unit/api/controllers/v1/test_containers.py @@ -1910,8 +1910,9 @@ class TestContainerActionController(api_base.FunctionalTest): test_container['uuid']) self.assertEqual(200, response.status_int) - self.assertEqual(self._format_action(test_action), - self._format_action(response.json[0])) + self.assertEqual( + self._format_action(test_action), + self._format_action(response.json['containerActions'][0])) @mock.patch('zun.objects.Container.get_by_uuid') @mock.patch('zun.common.policy.enforce')