diff options
author | 2018-09-18 14:22:30 +0800 | |
---|---|---|
committer | 2018-09-18 14:22:30 +0800 | |
commit | 87f316c1810eba45c280ac51f519c2c97f6710eb (patch) | |
tree | 088ef6f779d032e949a054c7a44794d4be047aff | |
parent | b0fe9e5ea7d7c4f86a2d79ce7d1b994e2642218a (diff) |
add query nsdinfo by nsd_id
add query nsdinfo by nsd_id in catalog
Change-Id: Iac2b53c9567f6e5c6fcc08708ea6016595285dd4
Issue-ID: VFC-635
Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
-rw-r--r-- | catalog/packages/biz/ns_descriptor.py | 7 | ||||
-rw-r--r-- | catalog/packages/tests/test_ns_descriptor.py | 14 | ||||
-rw-r--r-- | catalog/packages/views/ns_descriptor_views.py | 3 |
3 files changed, 20 insertions, 4 deletions
diff --git a/catalog/packages/biz/ns_descriptor.py b/catalog/packages/biz/ns_descriptor.py index 9a484b20..a58235f6 100644 --- a/catalog/packages/biz/ns_descriptor.py +++ b/catalog/packages/biz/ns_descriptor.py @@ -58,8 +58,11 @@ class NsDescriptor(object): logger.info('A NSD(%s) has been created.' % data['id']) return data - def query_multiple(self): - ns_pkgs = NSPackageModel.objects.all() + def query_multiple(self, nsdId=None): + if nsdId: + ns_pkgs = NSPackageModel.objects.filter(nsdId=nsdId) + else: + ns_pkgs = NSPackageModel.objects.all() response_data = [] for ns_pkg in ns_pkgs: data = self.fill_resp_data(ns_pkg) diff --git a/catalog/packages/tests/test_ns_descriptor.py b/catalog/packages/tests/test_ns_descriptor.py index ec6357b5..8ed04d01 100644 --- a/catalog/packages/tests/test_ns_descriptor.py +++ b/catalog/packages/tests/test_ns_descriptor.py @@ -91,7 +91,9 @@ class TestNsDescriptor(TestCase): copy.deepcopy(self.expected_nsd_info) ] expected_reponse_data[0]['id'] = '0' + expected_reponse_data[0]['nsdId'] = '0' expected_reponse_data[1]['id'] = '1' + expected_reponse_data[1]['nsdId'] = '1' user_defined_data = json.JSONEncoder().encode(self.user_defined_data) for i in range(2): @@ -100,13 +102,23 @@ class TestNsDescriptor(TestCase): onboardingState='CREATED', operationalState='DISABLED', usageState='NOT_IN_USE', - userDefinedData=user_defined_data + userDefinedData=user_defined_data, + nsdId=str(i) ).save() response = self.client.get('/api/nsd/v1/ns_descriptors', format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(expected_reponse_data, response.data) + expected_reponse_data = [ + copy.deepcopy(self.expected_nsd_info) + ] + expected_reponse_data[0]['id'] = '1' + expected_reponse_data[0]['nsdId'] = '1' + response = self.client.get('/api/nsd/v1/ns_descriptors?nsdId=1', format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(expected_reponse_data, response.data) + def test_query_single_nsd_normal(self): expected_reponse_data = copy.deepcopy(self.expected_nsd_info) expected_reponse_data['id'] = '22' diff --git a/catalog/packages/views/ns_descriptor_views.py b/catalog/packages/views/ns_descriptor_views.py index 589ab8ee..ff3d5f14 100644 --- a/catalog/packages/views/ns_descriptor_views.py +++ b/catalog/packages/views/ns_descriptor_views.py @@ -114,7 +114,8 @@ def ns_descriptors_rc(request): if request.method == 'GET': try: - data = NsDescriptor().query_multiple() + nsdId = request.query_params.get("nsdId", None) + data = NsDescriptor().query_multiple(nsdId) nsd_infos = validate_data(data, NsdInfosSerializer) return Response(data=nsd_infos.data, status=status.HTTP_200_OK) except Exception as e: |