Add nf pkg distribute test cases
[vfc/nfvo/lcm.git] / lcm / packages / tests / test_sdc_nf.py
1 # Copyright 2017 ZTE Corporation.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 import json
15 import mock
16 from rest_framework import status
17 from django.test import TestCase
18 from django.test import Client
19
20 from lcm.pub.utils import restcall
21 from lcm.pub.utils import fileutil
22 from lcm.pub.database.models import NfPackageModel, NfInstModel
23 from lcm.pub.database.models import JobStatusModel, JobModel
24 from lcm.packages.sdc_nf_package import SdcNfDistributeThread, SdcNfPkgDeleteThread
25 from lcm.packages import sdc_nf_package
26
27
28 class TestNfPackage(TestCase):
29     def setUp(self):
30         self.client = Client()
31         NfPackageModel.objects.filter().delete()
32         NfInstModel.objects.filter().delete()
33         JobModel.objects.filter().delete()
34         JobStatusModel.objects.filter().delete()
35
36     def tearDown(self):
37         pass
38
39     def assert_job_result(self, job_id, job_progress, job_detail):
40         jobs = JobStatusModel.objects.filter(
41             jobid=job_id,
42             progress=job_progress,
43             descp=job_detail)
44         self.assertEqual(1, len(jobs))
45
46     @mock.patch.object(SdcNfDistributeThread, 'run')
47     def test_nf_pkg_on_distribute_normal(self, mock_run):
48         resp = self.client.post("/api/nslcm/v1/vnfpackage", {
49             "csarId": "1",
50             "vimIds": ["1"]
51             }, format='json')
52         self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)