diff options
author | biancunkang <bian.cunkang@zte.com.cn> | 2018-08-28 09:20:25 +0800 |
---|---|---|
committer | biancunkang <bian.cunkang@zte.com.cn> | 2018-08-28 09:26:14 +0800 |
commit | 14e4e5d6d90f5545fc7fc7c24dc0175bb223380a (patch) | |
tree | 5d22c77f83d4882adcb74ba8806de48802ad2229 | |
parent | 6d7b122d40e3ee932b3cb699319083b085704b59 (diff) |
Deal with nfPackage
Add a test
Change-Id: I5b164914682ac410a1a5e16bcf0a80171a305401
Issue-ID: VFC-1038
Signed-off-by: biancunkang <bian.cunkang@zte.com.cn>
-rw-r--r-- | catalog/packages/biz/vnf_package.py | 6 | ||||
-rw-r--r-- | catalog/packages/tests/test_vnf_package.py | 15 |
2 files changed, 17 insertions, 4 deletions
diff --git a/catalog/packages/biz/vnf_package.py b/catalog/packages/biz/vnf_package.py index d3f1f587..da5cc566 100644 --- a/catalog/packages/biz/vnf_package.py +++ b/catalog/packages/biz/vnf_package.py @@ -22,7 +22,7 @@ import urllib2 import uuid from rest_framework import status -from django.http import FileResponse, StreamingHttpResponse +from django.http import StreamingHttpResponse from catalog.pub.config.config import CATALOG_ROOT_PATH from catalog.pub.database.models import VnfPackageModel from catalog.pub.exceptions import CatalogException @@ -188,9 +188,9 @@ def fetch_vnf_pkg(request, vnf_pkg_id): f.seek(start, 0) fs = f.read(end - start + 1) response = StreamingHttpResponse(fs, status=status.HTTP_200_OK) - response['Content-Type'] = 'application/octet-stream' response['Content-Range'] = file_range else: - response = FileResponse(open(file_path, 'rb'), status=status.HTTP_200_OK) + response = StreamingHttpResponse(open(file_path, 'rb'), status=status.HTTP_200_OK) + response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment; filename=%s' % file_name.encode('utf-8') return response diff --git a/catalog/packages/tests/test_vnf_package.py b/catalog/packages/tests/test_vnf_package.py index efde444d..fb3a5dee 100644 --- a/catalog/packages/tests/test_vnf_package.py +++ b/catalog/packages/tests/test_vnf_package.py @@ -411,7 +411,20 @@ class TestVnfPackage(TestCase): self.assertEqual(response.data, None) def test_fetch_vnf_pkg(self): - pass + with open("vnfPackage.csar", "wb") as fp: + fp.writelines("AAAABBBBCCCCDDDD") + VnfPackageModel.objects.create( + vnfPackageId="222", + onboardingState="ONBOARDED", + localFilePath="vnfPackage.csar" + ) + response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content") + partial_file_content = '' + for data in response.streaming_content: + partial_file_content = partial_file_content + data + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual('AAAABBBBCCCCDDDD', partial_file_content) + os.remove("vnfPackage.csar") def test_fetch_partical_vnf_pkg(self): with open("vnfPackage.csar", "wb") as fp: |