aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog/packages/tests/test_pnf_descriptor.py3
-rw-r--r--catalog/packages/tests/test_vnf_package.py31
-rw-r--r--catalog/packages/views/ns_descriptor_views.py2
3 files changed, 27 insertions, 9 deletions
diff --git a/catalog/packages/tests/test_pnf_descriptor.py b/catalog/packages/tests/test_pnf_descriptor.py
index 0b8ce104..6d02bc14 100644
--- a/catalog/packages/tests/test_pnf_descriptor.py
+++ b/catalog/packages/tests/test_pnf_descriptor.py
@@ -26,7 +26,6 @@ from catalog.pub.database.models import PnfPackageModel, NSPackageModel
from catalog.pub.utils import toscaparser
from catalog.packages.const import PKG_STATUS
from catalog.packages.tests.const import pnfd_data
-from catalog.pub.config.config import CATALOG_ROOT_PATH
from catalog.packages.biz.pnf_descriptor import PnfPackage
@@ -155,8 +154,6 @@ class TestPnfDescriptor(TestCase):
self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(None, resp.data)
os.remove('pnfd_content.txt')
- os.remove(pnf_pkg[0].localFilePath)
- os.removedirs(os.path.join(CATALOG_ROOT_PATH, pnf_pkg[0].pnfPackageId))
def test_pnfd_content_upload_when_pnf_not_exist(self):
with open('pnfd_content.txt', 'wb') as fp:
diff --git a/catalog/packages/tests/test_vnf_package.py b/catalog/packages/tests/test_vnf_package.py
index 2760fde6..1bfafa7d 100644
--- a/catalog/packages/tests/test_vnf_package.py
+++ b/catalog/packages/tests/test_vnf_package.py
@@ -58,9 +58,6 @@ class TestVnfPackage(TestCase):
self.assertEqual(PKG_STATUS.ONBOARDED, vnf_pkg[0].onboardingState)
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
- os.remove(vnf_pkg[0].localFilePath)
- os.removedirs(os.path.join(CATALOG_ROOT_PATH, vnf_pkg[0].vnfPackageId))
-
def test_upload_vnf_pkg_failed(self):
data = {'file': open(os.path.join(CATALOG_ROOT_PATH, "empty.txt"), "rb")}
VnfPackageModel.objects.create(
@@ -84,8 +81,10 @@ class TestVnfPackage(TestCase):
vnf_pkg1 = VnfPackageModel.objects.filter(vnfPackageId="222")
self.assertEqual("zte-hss-1.0", vnf_pkg1[0].vnfdId)
- os.remove(vnf_pkg1[0].localFilePath)
- os.removedirs(os.path.join(CATALOG_ROOT_PATH, vnf_pkg1[0].vnfPackageId))
+ def test_upload_from_uri_failed(self):
+ req_data = {"username": "123"}
+ response = self.client.post("/api/vnfpkgm/v1/vnf_packages/111/package_content/upload_from_uri", data=req_data)
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
def test_create_vnf_pkg(self):
req_data = {
@@ -263,6 +262,15 @@ class TestVnfPackage(TestCase):
response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content")
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
+ def test_fetch_vnf_pkg_when_catch_cataloge_exception(self):
+ VnfPackageModel.objects.create(
+ vnfPackageId="222",
+ onboardingState="CREATED",
+ localFilePath="vnfPackage.csar"
+ )
+ response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content")
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+
@mock.patch.object(VnfPackage, "create_vnf_pkg")
def test_create_vnf_pkg_when_catch_exception(self, mock_create_vnf_pkg):
mock_create_vnf_pkg.side_effect = TypeError('integer type')
@@ -300,3 +308,16 @@ class TestVnfPackage(TestCase):
mock_parse_vnfd.side_effect = TypeError("integer type")
response = self.client.put("/api/vnfpkgm/v1/vnf_packages/222/package_content", data=data)
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+ @mock.patch.object(VnfPkgUploadThread, 'start')
+ def test_upload_from_uri_when_catch_exception(self, mock_start):
+ req_data = {"addressInformation": "https://127.0.0.1:1234/sdc/v1/hss.csar"}
+ mock_start.side_effect = TypeError("integer type")
+ response = self.client.post("/api/vnfpkgm/v1/vnf_packages/111/package_content/upload_from_uri", data=req_data)
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+ @mock.patch.object(VnfPackage, 'fetch_vnf_pkg')
+ def test_fetch_vnf_pkg_when_catch_exception(self, mock_fetch_vnf_pkg):
+ mock_fetch_vnf_pkg.side_effect = TypeError("integer type")
+ response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content")
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/catalog/packages/views/ns_descriptor_views.py b/catalog/packages/views/ns_descriptor_views.py
index a1df687c..30fe6e9e 100644
--- a/catalog/packages/views/ns_descriptor_views.py
+++ b/catalog/packages/views/ns_descriptor_views.py
@@ -216,5 +216,5 @@ def validate_data(data, serializer):
serialized_data = serializer(data=data)
if not serialized_data.is_valid():
logger.error('Data validation failed.')
- raise CatalogException(serialized_data.error)
+ raise CatalogException(serialized_data.errors)
return serialized_data