diff options
author | maopengzhang <zhang.maopeng1@zte.com.cn> | 2019-04-23 20:00:48 +0800 |
---|---|---|
committer | maopengzhang <zhang.maopeng1@zte.com.cn> | 2019-04-23 20:00:48 +0800 |
commit | 99a98c606aef19b303cb8ad37c611a8a932b5f6d (patch) | |
tree | bf8c0b69d46e9e92741b4ebfd09bf28d31adb3a9 | |
parent | fadcad2cc5688d4f9a94a1063d4983fe301f92d6 (diff) |
move opocc test json
move opocc test json files to independant files
Change-Id: I1089e7099e2cc6ad0ff7e2e648fa1a1311770a98
Issue-ID: VFC-1241
Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
-rw-r--r-- | lcm/ns/tests/data/occurrence.json | 42 | ||||
-rw-r--r-- | lcm/ns/tests/data/occurrence_exclude_default.json | 17 | ||||
-rw-r--r-- | lcm/ns/tests/test_query_ns_lcm_op.py | 185 |
3 files changed, 140 insertions, 104 deletions
diff --git a/lcm/ns/tests/data/occurrence.json b/lcm/ns/tests/data/occurrence.json new file mode 100644 index 00000000..ccec9c86 --- /dev/null +++ b/lcm/ns/tests/data/occurrence.json @@ -0,0 +1,42 @@ +[ + { + "id": "99442b18-a5c7-11e8-998c-bf1755941f16", + "operationState": "STARTING", + "stateEnteredTime": "2019-01-01", + "startTime": "2019-01-01", + "nsInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1", + "operation": "SCALE", + "isAutomaticInvocation": false, + "operationParams": {}, + "isCancelPending": false, + "cancelMode": null, + "error": null, + "resourceChanges": null, + "_links": { + "self": { + "href": "demo" + }, + "nsInstance": "demo" + } + }, + { + "id": "a6b9415c-ab99-11e8-9d37-dbb5e0378955", + "operationState": "STARTING", + "stateEnteredTime": "2019-01-01", + "startTime": "2019-01-01", + "nsInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1", + "operation": "INSTANTIATE", + "isAutomaticInvocation": false, + "operationParams": {}, + "isCancelPending": false, + "cancelMode": null, + "error": null, + "resourceChanges": null, + "_links": { + "self": { + "href": "demo" + }, + "nsInstance": "demo" + } + } +] diff --git a/lcm/ns/tests/data/occurrence_exclude_default.json b/lcm/ns/tests/data/occurrence_exclude_default.json new file mode 100644 index 00000000..baf7cd56 --- /dev/null +++ b/lcm/ns/tests/data/occurrence_exclude_default.json @@ -0,0 +1,17 @@ +[{ + "id": "99442b18-a5c7-11e8-998c-bf1755941f16", + "operationState": "STARTING", + "stateEnteredTime": "2019-01-01", + "startTime": "2019-01-01", + "nsInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1", + "operation": "SCALE", + "isAutomaticInvocation": false, + "isCancelPending": false, + "cancelMode": false, + "_links": { + "self": { + "href": "demo" + }, + "nsInstance": "demo" + } +}] diff --git a/lcm/ns/tests/test_query_ns_lcm_op.py b/lcm/ns/tests/test_query_ns_lcm_op.py index e5dfa5e4..28ec95c3 100644 --- a/lcm/ns/tests/test_query_ns_lcm_op.py +++ b/lcm/ns/tests/test_query_ns_lcm_op.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. @@ -13,78 +14,22 @@ # limitations under the License. import json - -from django.test import TestCase, Client +import os +from rest_framework.test import APIClient +from django.test import TestCase from rest_framework import status - from lcm.pub.database.models import NSLcmOpOccModel +from lcm.pub.utils import fileutil class TestNSLcmOpOccs(TestCase): def setUp(self): - self.client = Client() - self.ns_lcm_op_occ_id = "99442b18-a5c7-11e8-998c-bf1755941f16" + self.client = APIClient() + self.cur_path = os.path.dirname(os.path.abspath(__file__)) + self.multiple_ns_lcm_op = fileutil.read_json_file(self.cur_path + '/data/occurrence.json') + self.single_ns_lcm_op = self.multiple_ns_lcm_op[0] + self.nslcmop_with_exclude_default = fileutil.read_json_file(self.cur_path + '/data/occurrence_exclude_default.json') NSLcmOpOccModel.objects.all().delete() - self.test_single_ns_lcm_op = { - "id": "99442b18-a5c7-11e8-998c-bf1755941f16", - "operationState": "STARTING", - "stateEnteredTime": "2019-01-01", - "startTime": "2019-01-01", - "nsInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1", - "operation": "SCALE", - "isAutomaticInvocation": False, - "operationParams": {}, - "isCancelPending": False, - "cancelMode": None, - "error": None, - "resourceChanges": None, - "_links": { - "self": { - "href": "demo" - }, - "nsInstance": "demo" - } - } - self.test_nslcmop_with_exclude_default = [{ - "id": "99442b18-a5c7-11e8-998c-bf1755941f16", - "operationState": "STARTING", - "stateEnteredTime": "2019-01-01", - "startTime": "2019-01-01", - "nsInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1", - "operation": "SCALE", - "isAutomaticInvocation": False, - "isCancelPending": False, - "cancelMode": None, - "_links": { - "self": { - "href": "demo" - }, - "nsInstance": "demo" - } - }] - - self.test_multiple_ns_lcm_op = [{ - "id": "a6b9415c-ab99-11e8-9d37-dbb5e0378955", - "operationState": "STARTING", - "stateEnteredTime": "2019-01-01", - "startTime": "2019-01-01", - "nsInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1", - "operation": "INSTANTIATE", - "isAutomaticInvocation": False, - "operationParams": {}, - "isCancelPending": False, - "cancelMode": None, - "error": None, - "resourceChanges": None, - "_links": { - "self": { - "href": "demo" - }, - "nsInstance": "demo" - } - }] - self.test_multiple_ns_lcm_op.append( - self.test_single_ns_lcm_op) def tearDown(self): pass @@ -92,74 +37,106 @@ class TestNSLcmOpOccs(TestCase): def test_get_nslcmopoccs(self): lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16" ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1" - NSLcmOpOccModel(id=lcm_op_id, operation_state="STARTING", state_entered_time="2019-01-01", - start_time="2019-01-01", ns_instance_id=ns_instance_id, operation="SCALE", - is_automatic_invocation=False, operation_params='{}', is_cancel_pending=False, - cancel_mode=None, error=None, resource_changes=None, - links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save() + NSLcmOpOccModel( + id=lcm_op_id, + operation_state="STARTING", + state_entered_time="2019-01-01", + start_time="2019-01-01", + ns_instance_id=ns_instance_id, + operation="SCALE", + is_automatic_invocation=False, + operation_params='{}', + is_cancel_pending=False, + cancel_mode=None, + error=None, + resource_changes=None, + links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save() response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs", format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) - # self.assertEqual([self.test_single_ns_lcm_op], response.data) def test_get_nslcmopoccs_with_id_not_exist(self): response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?id=dummy", format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) - # expected_data = { - # "status": 500, - # "detail": "LCM Operation Occurances do not exist" - # } - # self.assertEqual(expected_data, response.data) def test_get_nslcmopoccs_with_filters(self): lcm_op_id = "a6b9415c-ab99-11e8-9d37-dbb5e0378955" ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1" - NSLcmOpOccModel(id=lcm_op_id, operation_state="STARTING", - state_entered_time="2019-01-01", start_time="2019-01-01", ns_instance_id=ns_instance_id, - operation="INSTANTIATE", is_automatic_invocation=False, operation_params='{}', - is_cancel_pending=False, cancel_mode=None, error=None, resource_changes=None, - links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save() - + NSLcmOpOccModel( + id=lcm_op_id, + operation_state="STARTING", + state_entered_time="2019-01-01", + start_time="2019-01-01", + ns_instance_id=ns_instance_id, + operation="INSTANTIATE", + is_automatic_invocation=False, + operation_params='{}', + is_cancel_pending=False, + cancel_mode=None, + error=None, + resource_changes=None, + links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save() lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16" - NSLcmOpOccModel(id=lcm_op_id, operation_state="STARTING", state_entered_time="2019-01-01", - start_time="2019-01-01", ns_instance_id=ns_instance_id, operation="SCALE", - is_automatic_invocation=False, operation_params='{}', is_cancel_pending=False, - cancel_mode=None, error=None, resource_changes=None, - links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save() + NSLcmOpOccModel( + id=lcm_op_id, + operation_state="STARTING", + state_entered_time="2019-01-01", + start_time="2019-01-01", + ns_instance_id=ns_instance_id, + operation="SCALE", + is_automatic_invocation=False, + operation_params='{}', + is_cancel_pending=False, + cancel_mode=None, + error=None, + resource_changes=None, + links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save() response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs", format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) - # self.assertEqual(self.test_multiple_ns_lcm_op, response.data) - response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?operation=SCALE", format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) - # self.assertEqual([self.test_single_ns_lcm_op], response.data) - response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?nsInstanceId=%s" % ns_instance_id, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) - # self.assertEqual(self.test_multiple_ns_lcm_op, response.data) def test_get_nslcmopoccs_with_extra_flags(self): lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16" ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1" - NSLcmOpOccModel(id=lcm_op_id, operation_state="STARTING", state_entered_time="2019-01-01", - start_time="2019-01-01", ns_instance_id=ns_instance_id, operation="SCALE", - is_automatic_invocation=False, operation_params='{}', is_cancel_pending=False, - cancel_mode=None, error=None, resource_changes=None, - links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save() + NSLcmOpOccModel( + id=lcm_op_id, + operation_state="STARTING", + state_entered_time="2019-01-01", + start_time="2019-01-01", + ns_instance_id=ns_instance_id, + operation="SCALE", + is_automatic_invocation=False, + operation_params='{}', + is_cancel_pending=False, + cancel_mode=None, + error=None, + resource_changes=None, + links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save() response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs?exclude_default", format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) - # self.assertEqual(self.test_nslcmop_with_exclude_default, response.data) def test_get_nslcmopocc_with_id(self): lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16" ns_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1" - NSLcmOpOccModel(id=lcm_op_id, operation_state="STARTING", state_entered_time="2019-01-01", - start_time="2019-01-01", ns_instance_id=ns_instance_id, operation="SCALE", - is_automatic_invocation=False, operation_params='{}', is_cancel_pending=False, cancel_mode=None, - error=None, resource_changes=None, - links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save() + NSLcmOpOccModel( + id=lcm_op_id, + operation_state="STARTING", + state_entered_time="2019-01-01", + start_time="2019-01-01", + ns_instance_id=ns_instance_id, + operation="SCALE", + is_automatic_invocation=False, + operation_params='{}', + is_cancel_pending=False, + cancel_mode=None, + error=None, + resource_changes=None, + links=json.dumps({"self": {"href": "demo"}, "nsInstance": "demo"})).save() response = self.client.get("/api/nslcm/v1/ns_lcm_op_occs/" + lcm_op_id, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(self.test_single_ns_lcm_op['id'], response.data['id']) + self.assertEqual(self.single_ns_lcm_op['id'], response.data['id']) def test_single_nslcmopocc_with_unknown_id(self): lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16" |