diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2018-02-09 17:01:15 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2018-02-09 17:08:35 +0800 |
commit | 66404e550d2d7d40e84990579d20d8697eb3167b (patch) | |
tree | 08ec754d0c0c6078b0bf56d7be085b355b5309c2 | |
parent | 01425d950874b9c231ba388cfbc7767258ecedfb (diff) |
Add UT cases for port chain
Change-Id: Icd407ee922768b2565e44c818b863ad553ca1c15
Issue-ID: VFC-754
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/ns/tests/sfcs/test_create_port_chain.py | 103 |
1 files changed, 59 insertions, 44 deletions
diff --git a/lcm/ns/tests/sfcs/test_create_port_chain.py b/lcm/ns/tests/sfcs/test_create_port_chain.py index 7391dac9..978d5f6a 100644 --- a/lcm/ns/tests/sfcs/test_create_port_chain.py +++ b/lcm/ns/tests/sfcs/test_create_port_chain.py @@ -11,47 +11,62 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# import mock -# import json -# from test_data import nsd_model -# from rest_framework import status -# from lcm.pub.utils import restcall -# from lcm.pub.database.models import FPInstModel -# from django.test import Client -# from django.test import TestCase -# -# -# class TestSfc(TestCase): -# def setUp(self): -# self.client = Client() -# FPInstModel.objects.all().delete() -# FPInstModel(fpinstid="fp_inst_1", sdncontrollerid="test_sdncontrollerid", -# symmetric=1, flowclassifiers="test_flowclassifiers", -# portpairgroups=json.JSONEncoder().encode([{"groupid": "1"}])).save() -# -# def tearDown(self): -# FPInstModel.objects.all().delete() -# -# @mock.patch.object(restcall, 'call_req') -# def test_create_port_chain_success(self, mock_call_req): -# data = { -# "fpinstid": "fp_inst_1", -# "context": json.dumps(nsd_model) -# } -# mock_vals = { -# "/api/aai-esr-server/v1/sdncontrollers/test_sdncontrollerid": -# [0, json.JSONEncoder().encode({"url": "url_1"}), '200'], -# "/api/sdncdriver/v1.0/createportchain": -# [0, json.JSONEncoder().encode({"id": "test_id_1"}), '200'], -# "/api/microservices/v1/services": -# [0, None, '200'] -# } -# -# def side_effect(*args): -# return mock_vals[args[4]] -# -# mock_call_req.side_effect = side_effect -# resp = self.client.post("/api/nslcm/v1/ns/create_port_chain", data) -# ret = FPInstModel.objects.get(fpinstid="fp_inst_1") -# self.assertEqual(resp.status_code, status.HTTP_200_OK) -# self.assertEqual("test_id_1", ret.sfcid) +import mock +import json +from test_data import nsd_model +from rest_framework import status +from lcm.pub.utils import restcall +from lcm.pub.database.models import FPInstModel +from django.test import Client +from django.test import TestCase + + +class TestSfc(TestCase): + def setUp(self): + self.client = Client() + FPInstModel.objects.all().delete() + FPInstModel(fpinstid="fp_inst_1", sdncontrollerid="test_sdncontrollerid", + symmetric=1, flowclassifiers="test_flowclassifiers", + portpairgroups=json.JSONEncoder().encode([{"groupid": "1"}])).save() + + def tearDown(self): + FPInstModel.objects.all().delete() + + @mock.patch.object(restcall, 'call_req') + def test_create_port_chain_success(self, mock_call_req): + data = { + "fpinstid": "fp_inst_1", + "context": json.dumps(nsd_model) + } + mock_vals = { + "/external-system/esr-thirdparty-sdnc-list/esr-thirdparty-sdnc/test_sdncontrollerid?depth=all": + [0, json.JSONEncoder().encode({ + "thirdparty-sdnc-id": "1", + "esr-system-info-list": { + "esr-system-info": [{ + "service-url": "url_1", + "thirdparty-sdnc-id": "1", + "user-name": "aa", + "password": "123", + "vendor": "zte", + "version": "v1.0", + "protocal": "http", + "product-name": "bbb", + "type": "11" + }] + } + }), '200'], + "/api/ztesdncdriver/v1/createportchain": + [0, json.JSONEncoder().encode({"id": "test_id_1"}), '200'], + "/api/microservices/v1/services": + [0, None, '200'] + } + + def side_effect(*args): + return mock_vals[args[4]] + + mock_call_req.side_effect = side_effect + resp = self.client.post("/api/nslcm/v1/ns/create_port_chain", data) + ret = FPInstModel.objects.get(fpinstid="fp_inst_1") + self.assertEqual(resp.status_code, status.HTTP_200_OK) + self.assertEqual("test_id_1", ret.sfcid) |