aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog/packages/biz/common.py6
-rw-r--r--catalog/packages/tests/test_vnf_package.py16
2 files changed, 19 insertions, 3 deletions
diff --git a/catalog/packages/biz/common.py b/catalog/packages/biz/common.py
index c4205fb6..ce77a41e 100644
--- a/catalog/packages/biz/common.py
+++ b/catalog/packages/biz/common.py
@@ -45,7 +45,7 @@ def read(file_path, start, end):
def parse_file_range(file_path, file_range):
start, end = 0, os.path.getsize(file_path)
if file_range:
- [start, end] = file_range.split('-')
- start, end = start.strip(), end.strip()
- start, end = int(start), int(end)
+ [start, range_end] = file_range.split('-')
+ range_end = range_end.strip() if range_end.strip() else end
+ start, end = int(start.strip()), int(range_end)
return start, end
diff --git a/catalog/packages/tests/test_vnf_package.py b/catalog/packages/tests/test_vnf_package.py
index 07486cdc..8def3ba9 100644
--- a/catalog/packages/tests/test_vnf_package.py
+++ b/catalog/packages/tests/test_vnf_package.py
@@ -261,6 +261,22 @@ class TestVnfPackage(TestCase):
self.assertEqual('BBB', partial_file_content)
os.remove("vnfPackage.csar")
+ def test_fetch_last_partical_vnf_pkg(self):
+ 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", HTTP_RANGE=" 4-")
+ 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('BBBBCCCCDDDD', partial_file_content)
+ os.remove("vnfPackage.csar")
+
def test_fetch_vnf_pkg_when_pkg_not_exist(self):
response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content")
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)