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:
###############################################################################################################
@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",
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)