import os
import shutil
+
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APIClient
-from genericparser.packages.biz.pnf_descriptor import PnfDescriptor
-from genericparser.packages.const import PKG_STATUS
-from genericparser.packages.tests.const import pnfd_data
-from genericparser.pub.config.config import GENERICPARSER_ROOT_PATH
-from genericparser.pub.database.models import PnfPackageModel, NSPackageModel
-from genericparser.pub.utils import toscaparsers
+from catalog.packages.biz.pnf_descriptor import PnfDescriptor
+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.pub.database.models import PnfPackageModel, NSPackageModel
+from catalog.pub.utils import toscaparser
class TestPnfDescriptor(TestCase):
}
def tearDown(self):
- file_path = os.path.join(GENERICPARSER_ROOT_PATH, "22")
+ file_path = os.path.join(CATALOG_ROOT_PATH, "22")
if os.path.exists(file_path):
shutil.rmtree(file_path)
)
response.data.pop('id')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
- # self.assertEqual(expected_reponse_data, response.data)
- for key, value in expected_reponse_data.items():
- self.assertEqual(response.data[key], value)
+ self.assertEqual(expected_reponse_data, response.data)
def test_query_multiple_pnfds_normal(self):
expected_reponse_data = [
self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(None, resp.data)
- @mock.patch.object(toscaparsers, "parse_pnfd")
+ @mock.patch.object(toscaparser, "parse_pnfd")
def test_pnfd_content_upload_normal(self, mock_parse_pnfd):
user_defined_data_json = json.JSONEncoder().encode(self.user_defined_data)
PnfPackageModel(
)
self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
- @mock.patch.object(toscaparsers, "parse_pnfd")
+ @mock.patch.object(toscaparser, "parse_pnfd")
def test_pnfd_content_upload_when_pnfd_exist(self, mock_parse_pnfd):
with open('pnfd_content.txt', 'wt') as fp:
fp.write('test')
resp = self.client.get("/api/nsd/v1/pnf_descriptors/22/pnfd_content")
file_content = ""
for data in resp.streaming_content:
- file_content = '%s%s' % (file_content, data)
+ file_content = '%s%s' % (file_content, data.decode())
self.assertEqual(resp.status_code, status.HTTP_200_OK)
- self.assertEqual("b'test1test2'", file_content)
+ self.assertEqual("test1test2", file_content)
os.remove('pnfd_content.txt')
def test_pnfd_download_failed(self):
response = self.client.get("/api/nsd/v1/pnf_descriptors/22/pnfd_content")
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
- @mock.patch.object(toscaparsers, 'parse_pnfd')
+ @mock.patch.object(toscaparser, 'parse_pnfd')
def test_pnfd_parse_normal(self, mock_parse_pnfd):
PnfPackageModel(pnfPackageId="8", pnfdId="10").save()
mock_parse_pnfd.return_value = json.JSONEncoder().encode({"c": "d"})
req_data = {"csarId": "8", "inputs": []}
- resp = self.client.post("/api/parser/v1/parserpnfd", req_data, format='json')
+ resp = self.client.post("/api/catalog/v1/parserpnfd", req_data, format='json')
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual({"model": '{"c": "d"}'}, resp.data)