1 # Copyright 2017 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.
19 from django.test import TestCase
20 from rest_framework import status
21 from rest_framework.test import APIClient
23 from .const import vnfpackage_info
24 from lcm.pub.database.models import NfInstModel
25 from lcm.pub.database.models import JobStatusModel
26 from lcm.pub.utils import restcall
27 from lcm.pub.utils.timeutil import now_time
30 class TestNFInstantiate(TestCase):
32 self.client = APIClient()
36 "tenant": 'tenantname_1'
42 def assert_job_result(self, job_id, job_progress, job_detail):
43 jobs = JobStatusModel.objects.filter(
45 progress=job_progress,
48 self.assertEqual(1, len(jobs))
50 def test_create_vnf_identifier_when_vnf_is_exist(self):
51 NfInstModel.objects.create(
59 status='NOT_INSTANTIATED',
60 nf_desc='vFW in Nanjing TIC Edge',
62 create_time=now_time()
66 "vnfInstanceName": "vFW_01",
67 "vnfInstanceDescription": "vFW in Nanjing TIC Edge"
69 response = self.client.post(
70 "/api/vnflcm/v1/vnf_instances",
75 status.HTTP_500_INTERNAL_SERVER_ERROR,
78 context = json.loads(response.content)
80 'detail': 'VNF is already exist.',
84 @mock.patch.object(restcall, 'call_req')
85 @mock.patch.object(uuid, 'uuid4')
86 def test_create_vnf_identifier(self, mock_uuid4, mock_call_req):
87 r2_get_vnfpackage_from_catalog = [
89 json.JSONEncoder().encode(vnfpackage_info),
92 mock_call_req.return_value = r2_get_vnfpackage_from_catalog
93 mock_uuid4.return_value = "1"
96 "vnfInstanceName": "vFW_01",
97 "vnfInstanceDescription": "vFW in Nanjing TIC Edge"
99 response = self.client.post(
100 "/api/vnflcm/v1/vnf_instances",
106 "vnfProvider": "huawei",
107 "vnfdVersion": "1.0",
109 "instantiationState": "NOT_INSTANTIATED"
111 self.assertEqual(expect_data, response.data)