aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2017-09-23 09:44:55 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2017-09-23 09:44:55 +0800
commit07acabebb3acdecd440987b2c3f377f08df6da3b (patch)
treec75bb2fd102c7c9ae2a8862ccfb86ef46ecbf230
parentabb68dc5834e408dd50a463180b4f2642502cfc2 (diff)
Add UT cases for nsd parse
Change-Id: Icf68fa98592001a813fd3ad56878ffb341ee6a27 Issue-id: VFC-437 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--catalog/packages/ns_package.py7
-rw-r--r--catalog/packages/tests/test_ns.py6
2 files changed, 9 insertions, 4 deletions
diff --git a/catalog/packages/ns_package.py b/catalog/packages/ns_package.py
index bdd7bdc7..db44b2fc 100644
--- a/catalog/packages/ns_package.py
+++ b/catalog/packages/ns_package.py
@@ -88,9 +88,10 @@ def parse_nsd(csar_id, inputs):
ret= None
try:
ns_pkg = NSPackageModel.objects.filter(nsPackageId=csar_id)
- if ns_pkg:
- csar_path = ns_pkg[0].localFilePath
- ret = {"model": toscaparser.parse_nsd(csar_path, inputs)}
+ if not ns_pkg:
+ raise CatalogException("CSAR(%s) does not exist." % csar_id)
+ csar_path = ns_pkg[0].localFilePath
+ ret = {"model": toscaparser.parse_nsd(csar_path, inputs)}
except CatalogException as e:
return [1, e.message]
except:
diff --git a/catalog/packages/tests/test_ns.py b/catalog/packages/tests/test_ns.py
index 605679f4..25295cb4 100644
--- a/catalog/packages/tests/test_ns.py
+++ b/catalog/packages/tests/test_ns.py
@@ -485,7 +485,7 @@ class TestNsPackage(TestCase):
###############################################################################################################
@mock.patch.object(toscaparser, 'parse_nsd')
- def test_nsd_parse(self, mock_parse_nsd):
+ def test_nsd_parse_normal(self, mock_parse_nsd):
NSPackageModel(nsPackageId="18", nsdId="12").save()
mock_parse_nsd.return_value = json.JSONEncoder().encode({"a": "b"})
resp = self.client.post("/api/catalog/v1/parsernsd",
@@ -493,6 +493,10 @@ class TestNsPackage(TestCase):
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual({"model": '{"a": "b"}'}, resp.data)
+ def test_nsd_parse_when_csar_not_exist(self):
+ resp = self.client.post("/api/catalog/v1/parsernsd",
+ {"csarId": "1", "inputs": []}, format='json')
+ self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)