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.vnfpackage import VnfpkgUploadThread
35 class TestVnfPackage(TestCase):
37 self.client = APIClient()
42 def test_upload_vnfPkg(self):
43 data = {'file': open(os.path.join(CATALOG_ROOT_PATH, "empty.txt"), "rb")}
44 response = self.client.put("/api/vnfpkgm/v1/vnf_packages/222/package_content", data=data)
45 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
47 @mock.patch.object(urllib2, 'urlopen')
48 def test_upload_nf_pkg(self, mock_urlopen):
49 req_data = {"addressInformation": "https://127.0.0.1:1234/sdc/v1/hss.csar"}
50 mock_urlopen.return_value = MockReq()
52 VnfpkgUploadThread(req_data, vnfPkgId).run()
54 def test_create_vnf_pkg(self):
56 "userDefinedData": {"a": "A"}
58 response = self.client.post("/api/vnfpkgm/v1/vnf_packages", data=req_data, format="json")
59 resp_data = json.loads(response.content)
61 "id": resp_data.get("id"),
62 "onboardingState": "CREATED",
63 "operationalState": "DISABLED",
64 "usageState": "NOT_IN_USE",
65 "userDefinedData": {"a": "A"},
68 self.assertEqual(expect_resp_data, resp_data)
69 self.assertEqual(response.status_code, status.HTTP_201_CREATED)