import json
import mock
import os
-
+import shutil
from django.test import TestCase
from rest_framework import status
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
}
def tearDown(self):
- pass
+ file_path = os.path.join(GENERICPARSER_ROOT_PATH, "22")
+ if os.path.exists(file_path):
+ shutil.rmtree(file_path)
def test_pnfd_create_normal(self):
request_data = {'userDefinedData': self.user_defined_data}
)
response.data.pop('id')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
- self.assertEqual(expected_reponse_data, response.data)
+ # self.assertEqual(expected_reponse_data, response.data)
+ for key, value in expected_reponse_data.items():
+ self.assertEqual(response.data[key], value)
def test_query_multiple_pnfds_normal(self):
expected_reponse_data = [
userDefinedData=user_defined_data_json,
).save()
mock_parse_pnfd.return_value = json.JSONEncoder().encode(pnfd_data)
- with open('pnfd_content.txt', 'wb') as fp:
+ with open('pnfd_content.txt', 'wt') as fp:
fp.write('test')
- with open('pnfd_content.txt', 'rb') as fp:
+ with open('pnfd_content.txt', 'rt') as fp:
resp = self.client.put(
"/api/nsd/v1/pnf_descriptors/22/pnfd_content",
{'file': fp},
os.remove('pnfd_content.txt')
def test_pnfd_content_upload_when_pnf_not_exist(self):
- with open('pnfd_content.txt', 'wb') as fp:
+ with open('pnfd_content.txt', 'wt') as fp:
fp.write('test')
- with open('pnfd_content.txt', 'rb') as fp:
+ with open('pnfd_content.txt', 'rt') as fp:
resp = self.client.put(
"/api/nsd/v1/pnf_descriptors/22/pnfd_content",
{'file': fp},
@mock.patch.object(toscaparsers, "parse_pnfd")
def test_pnfd_content_upload_when_pnfd_exist(self, mock_parse_pnfd):
- with open('pnfd_content.txt', 'wb') as fp:
+ with open('pnfd_content.txt', 'wt') as fp:
fp.write('test')
PnfPackageModel(
pnfPackageId='22',
pnfdId="zte-1.0"
).save()
mock_parse_pnfd.return_value = json.JSONEncoder().encode(pnfd_data)
- with open('pnfd_content.txt', 'rb') as fp:
+ with open('pnfd_content.txt', 'rt') as fp:
resp = self.client.put(
"/api/nsd/v1/pnf_descriptors/22/pnfd_content",
{'file': fp},
self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
def test_pnfd_download_normal(self):
- with open('pnfd_content.txt', 'wb') as fp:
+ with open('pnfd_content.txt', 'wt') as fp:
fp.writelines('test1')
fp.writelines('test2')
user_defined_data = json.JSONEncoder().encode(self.user_defined_data)
for data in resp.streaming_content:
file_content = '%s%s' % (file_content, data)
self.assertEqual(resp.status_code, status.HTTP_200_OK)
- self.assertEqual('test1test2', file_content)
+ self.assertEqual("b'test1test2'", file_content)
os.remove('pnfd_content.txt')
def test_pnfd_download_failed(self):
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_pnfd_download_when_not_on_boarded(self):
- with open('pnfd_content.txt', 'wb') as fp:
+ with open('pnfd_content.txt', 'wt') as fp:
fp.writelines('test1')
fp.writelines('test2')
user_defined_data = json.JSONEncoder().encode(self.user_defined_data)
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/genericparser/v1/parserpnfd", req_data, format='json')
+ resp = self.client.post("/api/parser/v1/parserpnfd", req_data, format='json')
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual({"model": '{"c": "d"}'}, resp.data)