diff options
author | biancunkang <bian.cunkang@zte.com.cn> | 2018-08-30 12:15:03 +0800 |
---|---|---|
committer | biancunkang <bian.cunkang@zte.com.cn> | 2018-08-30 12:15:03 +0800 |
commit | 504b1c47853ce512352be084fb73d648bc46aae9 (patch) | |
tree | 389dd054b569ceb397834813152d7cdc41900335 | |
parent | ff9565e291dbd0ca526e65f78dc02d341530503d (diff) |
Add a test
Add a test for download ns file
Change-Id: I15230b31f81254a1697a85800a52e2a65b3856b2
Issue-ID: VFC-1038
Signed-off-by: biancunkang <bian.cunkang@zte.com.cn>
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | catalog/packages/tests/test_ns_descriptor.py | 20 | ||||
-rw-r--r-- | catalog/packages/tests/test_pnf_descriptor.py | 3 | ||||
-rw-r--r-- | catalog/packages/tests/test_vnf_package.py | 6 |
4 files changed, 27 insertions, 4 deletions
@@ -3,3 +3,5 @@ logs/*.log .idea .tox target +htmlcov +.coverage
\ No newline at end of file diff --git a/catalog/packages/tests/test_ns_descriptor.py b/catalog/packages/tests/test_ns_descriptor.py index d00c440a..9e2ad68e 100644 --- a/catalog/packages/tests/test_ns_descriptor.py +++ b/catalog/packages/tests/test_ns_descriptor.py @@ -161,12 +161,30 @@ class TestNsDescriptor(TestCase): self.assertEqual(None, resp.data) self.assertEqual(file_content, 'test') os.remove('nsd_content.txt') + os.remove(ns_pkg[0].localFilePath) + os.removedirs(os.path.join(CATALOG_ROOT_PATH, ns_pkg[0].nsPackageId)) def test_nsd_content_upload_failure(self): pass def test_nsd_content_download_normal(self): - pass + with open('nsd_content.txt', 'wb') as fp: + fp.writelines('test1') + fp.writelines('test2') + NSPackageModel.objects.create( + nsPackageId='23', + onboardingState='ONBOARDED', + localFilePath='nsd_content.txt' + ) + response = self.client.get( + "/api/nsd/v1/ns_descriptors/23/nsd_content", format='json' + ) + file_content = "" + for data in response.streaming_content: + file_content = '%s%s' % (file_content, data) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual('test1test2', file_content) + os.remove('nsd_content.txt') def test_nsd_content_partial_download_normal(self): with open('nsd_content.txt', 'wb') as fp: diff --git a/catalog/packages/tests/test_pnf_descriptor.py b/catalog/packages/tests/test_pnf_descriptor.py index fe15eae4..1291f957 100644 --- a/catalog/packages/tests/test_pnf_descriptor.py +++ b/catalog/packages/tests/test_pnf_descriptor.py @@ -26,6 +26,7 @@ from catalog.pub.database.models import PnfPackageModel 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 class TestPnfDescriptor(TestCase): @@ -143,6 +144,8 @@ 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_failure(self): pass diff --git a/catalog/packages/tests/test_vnf_package.py b/catalog/packages/tests/test_vnf_package.py index 0f7d47cc..b5f9455b 100644 --- a/catalog/packages/tests/test_vnf_package.py +++ b/catalog/packages/tests/test_vnf_package.py @@ -223,11 +223,11 @@ class TestVnfPackage(TestCase): localFilePath="vnfPackage.csar" ) response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content") - partial_file_content = '' + file_content = '' for data in response.streaming_content: - partial_file_content = partial_file_content + data + file_content = file_content + data self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual('AAAABBBBCCCCDDDD', partial_file_content) + self.assertEqual('AAAABBBBCCCCDDDD', file_content) os.remove("vnfPackage.csar") def test_fetch_partical_vnf_pkg(self): |