diff options
author | yangyan <yangyanyj@chinamobile.com> | 2019-04-02 15:23:13 +0800 |
---|---|---|
committer | yangyan <yangyanyj@chinamobile.com> | 2019-04-02 15:23:27 +0800 |
commit | a6e8a5f86ff0f48613b36ebdf50a4bc98863757b (patch) | |
tree | 110250e72f7dd5b0b154b7c5a95d7bd460cb42c6 | |
parent | 1ee4a11393e48d1b98649872a1fc383c46ea7475 (diff) |
Add instantiate test case
Change-Id: I3fa03d310c38cc13d396fd20319b14b181bd0cdf
Signed-off-by: yangyan <yangyanyj@chinamobile.com>
Issue-ID: VFC-1327
-rw-r--r-- | lcm/ns/biz/ns_lcm_op_occ.py | 4 | ||||
-rw-r--r-- | lcm/ns/biz/query_ns_lcm_op_occ.py | 1 | ||||
-rw-r--r-- | lcm/ns/tests/test_sol_ns_instantiate_api.py | 50 |
3 files changed, 42 insertions, 13 deletions
diff --git a/lcm/ns/biz/ns_lcm_op_occ.py b/lcm/ns/biz/ns_lcm_op_occ.py index f808cd2d..2c7ffe53 100644 --- a/lcm/ns/biz/ns_lcm_op_occ.py +++ b/lcm/ns/biz/ns_lcm_op_occ.py @@ -15,6 +15,7 @@ import logging import datetime import uuid +import json from lcm.pub.database.models import NSLcmOpOccModel from lcm.pub.utils.values import update_value @@ -36,7 +37,8 @@ class NsLcmOpOcc(object): ns_instance_id=nsInstanceId, operation=lcmOperationType, is_automatic_invocation=isAutomaticInvocation, - operation_params=operationParams, + # operation_params=operationParams, + operation_params=json.dumps(operationParams), is_cancel_pending=False ) logger.debug("lcm_op_occ(%s) create successfully." % lcm_op_occ.id) diff --git a/lcm/ns/biz/query_ns_lcm_op_occ.py b/lcm/ns/biz/query_ns_lcm_op_occ.py index 1c8741e3..b2c96dba 100644 --- a/lcm/ns/biz/query_ns_lcm_op_occ.py +++ b/lcm/ns/biz/query_ns_lcm_op_occ.py @@ -1,4 +1,5 @@ # Copyright (c) 2019, CMCC Technologies Co., Ltd. +# Copyright (c) 2019, ZTE Corporation. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lcm/ns/tests/test_sol_ns_instantiate_api.py b/lcm/ns/tests/test_sol_ns_instantiate_api.py index 16d5efaf..598124c6 100644 --- a/lcm/ns/tests/test_sol_ns_instantiate_api.py +++ b/lcm/ns/tests/test_sol_ns_instantiate_api.py @@ -14,6 +14,8 @@ import json import mock +import uuid + from mock import MagicMock from django.test import TestCase from rest_framework import status @@ -290,7 +292,9 @@ class TestInstantiateNsApi(TestCase): }] } }) - NSInstModel(id="2", nspackage_id="7", nsd_id="2", status="active").save() + # NSInstModel(id="2", nspackage_id="7", nsd_id="2", status="active").save() + self.nsInstanceId = str(uuid.uuid4()) + NSInstModel(id=self.nsInstanceId, nspackage_id="7", nsd_id="2", status="active").save() def tearDown(self): pass @@ -305,20 +309,26 @@ class TestInstantiateNsApi(TestCase): [0, self.vnfms, '200'], [0, self.vnfm, '200'] ] - response = self.client.post(self.url % '2', data=self.req_data, format='json') + # response = self.client.post(self.url % '2', data=self.req_data, format='json') + response = self.client.post(self.url % self.nsInstanceId, data=self.req_data, format='json') self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) self.assertIsNotNone(response['Location']) + response = self.client.get(response['Location'], format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) @mock.patch.object(InstantNSService, 'do_biz') def test_ns_instantiate_normal(self, mock_do_biz): mock_do_biz.return_value = {'occ_id': "1"} - resp = self.client.post(self.url % '2', data=self.req_data, format='json') - self.failUnlessEqual(status.HTTP_202_ACCEPTED, resp.status_code) + # resp = self.client.post(self.url % '2', data=self.req_data, format='json') + response = self.client.post(self.url % self.nsInstanceId, data=self.req_data, format='json') + # self.failUnlessEqual(status.HTTP_202_ACCEPTED, resp.status_code) + self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code) @mock.patch.object(restcall, 'call_req') def test_ns_instantiate_when_fail_to_parse_nsd(self, mock_call_req): mock_call_req.return_value = [1, "Failed to parse nsd", '500'] - resp = self.client.post(self.url % '2', data=self.req_data, format='json') + # resp = self.client.post(self.url % '2', data=self.req_data, format='json') + resp = self.client.post(self.url % self.nsInstanceId, data=self.req_data, format='json') self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) @mock.patch('lcm.ns.biz.ns_instantiate_flow.post_deal') @@ -328,7 +338,9 @@ class TestInstantiateNsApi(TestCase): @mock.patch('lcm.pub.msapi.extsys.select_vnfm', MagicMock(return_value=vnfminfo)) def test_ns_instantiate_with_pnf(self, mock_updata_job, mock_call_req, mock_post_deal): config.WORKFLOW_OPTION = "grapflow" - NSInstModel(id="1", name="test_ns", nspackage_id="1", status="created").save() + # NSInstModel(id="1", name="test_ns", nspackage_id="1", status="created").save() + nsInstanceId = str(uuid.uuid4()) + NSInstModel(id=nsInstanceId, name="test_ns", nspackage_id="1", status="created").save() ret = [0, json.JSONEncoder().encode({'jobId': "1", "responseDescriptor": {"progress": 100}}), '200'] mock_call_req.side_effect = [ret for i in range(1, 20)] data = { @@ -353,18 +365,29 @@ class TestInstantiateNsApi(TestCase): "pnfProfileId": "du" }] } - response = self.client.post(self.url % '1', data=data, format='json') + # response = self.client.post(self.url % '1', data=data, format='json') + response = self.client.post(self.url % nsInstanceId, data=data, format='json') self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED) self.assertIsNotNone(response['Location']) + response = self.client.get(response['Location'], format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) def test_method_not_allowed(self): - response = self.client.put(self.url % '1', data=self.req_data, format='json') + # response = self.client.put(self.url % '1', data=self.req_data, format='json') + # self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code) + # response = self.client.patch(self.url % '1', data=self.req_data, format='json') + # self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code) + # response = self.client.delete(self.url % '1', data=self.req_data, format='json') + # self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code) + # response = self.client.get(self.url % '1', data=self.req_data, format='json') + # self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code) + response = self.client.put(self.url % self.nsInstanceId, data=self.req_data, format='json') self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code) - response = self.client.patch(self.url % '1', data=self.req_data, format='json') + response = self.client.patch(self.url % self.nsInstanceId, data=self.req_data, format='json') self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code) - response = self.client.delete(self.url % '1', data=self.req_data, format='json') + response = self.client.delete(self.url % self.nsInstanceId, data=self.req_data, format='json') self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code) - response = self.client.get(self.url % '1', data=self.req_data, format='json') + response = self.client.get(self.url % self.nsInstanceId, data=self.req_data, format='json') self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code) @mock.patch.object(restcall, 'call_req') @@ -480,6 +503,9 @@ class TestInstantiateNsApi(TestCase): } ] } - response = self.client.post(self.url % '2', data=req_data, format='json') + # response = self.client.post(self.url % '2', data=req_data, format='json') + response = self.client.post(self.url % self.nsInstanceId, data=req_data, format='json') self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) self.assertIsNotNone(response['Location']) + response = self.client.get(response['Location'], format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) |