diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2018-02-09 16:47:51 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2018-02-09 16:47:51 +0800 |
commit | 01425d950874b9c231ba388cfbc7767258ecedfb (patch) | |
tree | 4ae5249378645199e98ffb4f5aa0f1a36ff315d9 | |
parent | 726b1dc6e7830dea06ff5dee0a047282b6315af4 (diff) |
Add UT cases for sfc
Change-Id: I212cfba47c5f6effcf2a3f1e3a0306f5f5dd9dcb
Issue-ID: VFC-754
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/ns/tests/sfcs/test_create_flow_classifier.py | 101 |
1 files changed, 58 insertions, 43 deletions
diff --git a/lcm/ns/tests/sfcs/test_create_flow_classifier.py b/lcm/ns/tests/sfcs/test_create_flow_classifier.py index 2c48c293..1f69931d 100644 --- a/lcm/ns/tests/sfcs/test_create_flow_classifier.py +++ b/lcm/ns/tests/sfcs/test_create_flow_classifier.py @@ -11,46 +11,61 @@ # 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", fpid="fpd_1", sdncontrollerid="test").save() -# -# def tearDown(self): -# FPInstModel.objects.all().delete() -# -# @mock.patch.object(restcall, 'call_req') -# def test_create_flow_classifier_success(self, mock_call_req): -# data = { -# "fpinstid": "fp_inst_1", -# "context": json.dumps(nsd_model) -# } -# mock_vals = { -# "/api/aai-esr-server/v1/sdncontrollers/test": -# [0, json.JSONEncoder().encode({"url": "url_1"}), '200'], -# "/api/sdncdriver/v1.0/createflowclassfier": -# [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_flow_classifier", data) -# ret = FPInstModel.objects.get(fpinstid="fp_inst_1") -# self.assertEqual(resp.status_code, status.HTTP_200_OK) -# self.assertEqual("test_id_1", ret.flowclassifiers) +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", fpid="fpd_1", sdncontrollerid="test").save() + + def tearDown(self): + FPInstModel.objects.all().delete() + + @mock.patch.object(restcall, 'call_req') + def test_create_flow_classifier_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?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/createflowclassfier": + [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_flow_classifier", data) + ret = FPInstModel.objects.get(fpinstid="fp_inst_1") + self.assertEqual(resp.status_code, status.HTTP_200_OK) + self.assertEqual("test_id_1", ret.flowclassifiers) |