1 # Copyright 2018 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
20 from rest_framework.test import APIClient
21 from django.test import TestCase
22 from rest_framework import status
23 from catalog.pub.config.config import CATALOG_ROOT_PATH
24 from catalog.packages.biz.vnf_package import VnfPkgUploadThread
25 from catalog.pub.database.models import VnfPackageModel
36 class TestVnfPackage(TestCase):
38 self.client = APIClient()
43 def test_upload_vnf_pkg(self):
44 data = {'file': open(os.path.join(CATALOG_ROOT_PATH, "empty.txt"), "rb")}
45 VnfPackageModel.objects.create(
47 onboardingState="CREATED"
49 response = self.client.put("/api/vnfpkgm/v1/vnf_packages/222/package_content", data=data)
50 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
52 @mock.patch.object(urllib2, 'urlopen')
53 def test_upload_nf_pkg_from_uri(self, mock_urlopen):
54 vnf_pkg = VnfPackageModel.objects.create(
56 onboardingState="CREATED"
58 req_data = {"addressInformation": "https://127.0.0.1:1234/sdc/v1/hss.csar"}
59 mock_urlopen.return_value = MockReq()
60 vnf_pkg_id = vnf_pkg.vnfPackageId
61 VnfPkgUploadThread(req_data, vnf_pkg_id).run()
63 def test_create_vnf_pkg(self):
65 "userDefinedData": {"a": "A"}
67 response = self.client.post("/api/vnfpkgm/v1/vnf_packages", data=req_data, format="json")
68 resp_data = json.loads(response.content)
70 "id": resp_data.get("id"),
71 "onboardingState": "CREATED",
72 "operationalState": "DISABLED",
73 "usageState": "NOT_IN_USE",
74 "userDefinedData": {"a": "A"},
77 self.assertEqual(expect_resp_data, resp_data)
78 self.assertEqual(response.status_code, status.HTTP_201_CREATED)