diff options
-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: |