From cd9c5721aba7f0914dfb1b2c219dd729a3b2d44e Mon Sep 17 00:00:00 2001 From: maopengzhang Date: Thu, 28 Mar 2019 20:11:48 +0800 Subject: [PATCH] Fix query lcc ops bug Fix query lcc ops bug Change-Id: Iad3e9d23c9ba1b7ba0b6b2b9421f0f439a4bfdd2 Issue-ID: VFC-1059 Signed-off-by: maopengzhang --- lcm/ns/biz/query_ns_lcm_op_occ.py | 3 ++- lcm/ns/tests/test_query_ns_lcm_op.py | 12 ++++++------ lcm/ns/views/sol/lcm_op_occs_view.py | 2 ++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lcm/ns/biz/query_ns_lcm_op_occ.py b/lcm/ns/biz/query_ns_lcm_op_occ.py index e4e9d92e..051efb2f 100644 --- a/lcm/ns/biz/query_ns_lcm_op_occ.py +++ b/lcm/ns/biz/query_ns_lcm_op_occ.py @@ -46,7 +46,8 @@ class QueryNsLcmOpOcc: else: lcm_ops = NSLcmOpOccModel.objects.all() if not lcm_ops.exists(): - raise NSLCMException('LCM Operation Occurances do not exist') + return [] + # raise NSLCMException('LCM Operation Occurances do not exist') return [self.fill_resp_data(lcm_op) for lcm_op in lcm_ops] def fill_resp_data(self, lcm_op): diff --git a/lcm/ns/tests/test_query_ns_lcm_op.py b/lcm/ns/tests/test_query_ns_lcm_op.py index 723553e8..102325c4 100644 --- a/lcm/ns/tests/test_query_ns_lcm_op.py +++ b/lcm/ns/tests/test_query_ns_lcm_op.py @@ -103,12 +103,12 @@ class TestNSLcmOpOccs(TestCase): def test_get_nslcmopoccs_with_id_not_exist(self): response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?id=dummy", format='json') - self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) - expected_data = { - "status": 500, - "detail": "LCM Operation Occurances do not exist" - } - self.assertEqual(expected_data, response.data) + self.assertEqual(response.status_code, status.HTTP_200_OK) + # expected_data = { + # "status": 500, + # "detail": "LCM Operation Occurances do not exist" + # } + # self.assertEqual(expected_data, response.data) def test_get_nslcmopoccs_with_filters(self): lcm_op_id = "a6b9415c-ab99-11e8-9d37-dbb5e0378955" diff --git a/lcm/ns/views/sol/lcm_op_occs_view.py b/lcm/ns/views/sol/lcm_op_occs_view.py index 43579839..3405d13c 100644 --- a/lcm/ns/views/sol/lcm_op_occs_view.py +++ b/lcm/ns/views/sol/lcm_op_occs_view.py @@ -58,6 +58,8 @@ class QueryMultiNsLcmOpOccs(APIView): problem_details_serializer = get_problem_details_serializer(status.HTTP_400_BAD_REQUEST, "Not a valid filter") return Response(data=problem_details_serializer.data, status=status.HTTP_400_BAD_REQUEST) resp_data = QueryNsLcmOpOcc(request.query_params).query_multi_ns_lcm_op_occ() + if len(resp_data) == 0: + return Response(data=[], status=status.HTTP_200_OK) ns_lcm_op_occs_serializer = NSLCMOpOccsSerializer(data=resp_data) if not ns_lcm_op_occs_serializer.is_valid(): -- 2.16.6