aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lcm/ns/tests/__init__.py3
-rw-r--r--lcm/ns/tests/data/ns_package_info.json7
-rw-r--r--lcm/ns/tests/data/sol_create_ns.json5
-rw-r--r--lcm/ns/tests/data/sol_rest_header.json4
-rw-r--r--lcm/ns/tests/test_sol_ns_instances_api.py146
5 files changed, 39 insertions, 126 deletions
diff --git a/lcm/ns/tests/__init__.py b/lcm/ns/tests/__init__.py
index 52e7a57d..7cf59e9f 100644
--- a/lcm/ns/tests/__init__.py
+++ b/lcm/ns/tests/__init__.py
@@ -34,3 +34,6 @@ SCALE_NS_DICT = fileutil.read_json_file(cur_path + '/data/scale_ns.json')
OCCURRENCE_DICT = fileutil.read_json_file(cur_path + '/data/occurrence.json')
NSLCMOP_WITH_EXCLUDE_DEFAULT_DICT = fileutil.read_json_file(cur_path + '/data/occurrence_exclude_default.json')
SUBSCRIPTION_DICT = fileutil.read_json_file(cur_path + '/data/subscription.json')
+SOL_REST_HEADER_DICT = fileutil.read_json_file(cur_path + '/data/sol_rest_header.json')
+SOL_CREATE_NS_DICT = fileutil.read_json_file(cur_path + '/data/sol_create_ns.json')
+NS_PACKAGE_INFO_DICT = fileutil.read_json_file(cur_path + '/data/ns_package_info.json')
diff --git a/lcm/ns/tests/data/ns_package_info.json b/lcm/ns/tests/data/ns_package_info.json
new file mode 100644
index 00000000..88206818
--- /dev/null
+++ b/lcm/ns/tests/data/ns_package_info.json
@@ -0,0 +1,7 @@
+{
+ "csarId": "c9f0a95e-dea0-4698-96e5-5a79bc5a233d",
+ "packageInfo": {
+ "nsPackageId": "c9f0a95e-dea0-4698-96e5-5a79bc5a233d",
+ "nsdId": "c9f0a95e-dea0-4698-96e5-5a79bc5a233d"
+ }
+}
diff --git a/lcm/ns/tests/data/sol_create_ns.json b/lcm/ns/tests/data/sol_create_ns.json
new file mode 100644
index 00000000..2e001f73
--- /dev/null
+++ b/lcm/ns/tests/data/sol_create_ns.json
@@ -0,0 +1,5 @@
+{
+ "nsdId": "c9f0a95e-dea0-4698-96e5-5a79bc5a233d",
+ "nsName": "ns",
+ "nsDescription": "description"
+}
diff --git a/lcm/ns/tests/data/sol_rest_header.json b/lcm/ns/tests/data/sol_rest_header.json
new file mode 100644
index 00000000..b742e8ec
--- /dev/null
+++ b/lcm/ns/tests/data/sol_rest_header.json
@@ -0,0 +1,4 @@
+{
+ "HTTP_GLOBALCUSTOMERID": "global-customer-id-test1",
+ "HTTP_SERVICETYPE": "service-type-test1"
+}
diff --git a/lcm/ns/tests/test_sol_ns_instances_api.py b/lcm/ns/tests/test_sol_ns_instances_api.py
index 242c2e80..930838ae 100644
--- a/lcm/ns/tests/test_sol_ns_instances_api.py
+++ b/lcm/ns/tests/test_sol_ns_instances_api.py
@@ -13,7 +13,6 @@
# limitations under the License.
import json
-import uuid
import mock
from django.test import TestCase
@@ -23,6 +22,7 @@ from lcm.pub.database.models import NSInstModel
from lcm.pub.utils import restcall
from lcm.ns.biz.ns_create import CreateNSService
from lcm.pub.exceptions import NSLCMException
+from lcm.ns.tests import SOL_CREATE_NS_DICT, SOL_REST_HEADER_DICT, NS_PACKAGE_INFO_DICT, NS_INFO_AAI_DICT
class TestNsInstanceApi(TestCase):
@@ -31,176 +31,77 @@ class TestNsInstanceApi(TestCase):
self.apiClient = APIClient()
self.format = 'json'
self.ns_instances_url = '/api/nslcm/v1/ns_instances'
- self.nsd_id = str(uuid.uuid4())
- self.ns_package_id = str(uuid.uuid4())
+ self.nsd_id = "c9f0a95e-dea0-4698-96e5-5a79bc5a233d"
+ self.ns_package_id = "c9f0a95e-dea0-4698-96e5-5a79bc5a233d"
def tearDown(self):
NSInstModel.objects.all().delete()
@mock.patch.object(restcall, 'call_req')
def test_create_ns(self, mock_call_req):
- nspackage_info = {
- "csarId": self.ns_package_id,
- "packageInfo": {
- "nsPackageId": self.ns_package_id,
- "nsdId": self.nsd_id
- }
- }
- r1_query_nspackage_from_catalog = [0, json.JSONEncoder().encode(nspackage_info), '201']
+ r1_query_nspackage_from_catalog = [0, json.JSONEncoder().encode(NS_PACKAGE_INFO_DICT), '201']
r2_create_ns_to_aai = [0, json.JSONEncoder().encode({}), '201']
mock_call_req.side_effect = [r1_query_nspackage_from_catalog, r2_create_ns_to_aai]
-
- header = {
- 'HTTP_GLOBALCUSTOMERID': 'global-customer-id-test1',
- 'HTTP_SERVICETYPE': 'service-type-test1'
- }
-
- data = {
- "nsdId": self.nsd_id,
- "nsName": "ns",
- "nsDescription": "description"
- }
- response = self.apiClient.post(self.ns_instances_url, data=data, format=self.format, **header)
+ response = self.apiClient.post(self.ns_instances_url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)
return response.data['id']
@mock.patch.object(restcall, 'call_req')
def test_create_ns_cpe(self, mock_call_req):
- nspackage_info = {
- "csarId": "c9f0a95e-dea0-4698-96e5-5a79bc5a233d",
- "packageInfo": {
- "nsPackageId": "c9f0a95e-dea0-4698-96e5-5a79bc5a233d",
- "nsdId": "c9f0a95e-dea0-4698-96e5-5a79bc5a233d"
- }
- }
- r1_query_nspackage_from_catalog = [0, json.JSONEncoder().encode(nspackage_info), '201']
+ r1_query_nspackage_from_catalog = [0, json.JSONEncoder().encode(NS_PACKAGE_INFO_DICT), '201']
r2_create_ns_to_aai = [0, json.JSONEncoder().encode({}), '201']
mock_call_req.side_effect = [r1_query_nspackage_from_catalog, r2_create_ns_to_aai]
-
- header = {
- 'HTTP_GLOBALCUSTOMERID': 'global-customer-id-test1',
- 'HTTP_SERVICETYPE': 'service-type-test1'
- }
-
- data = {
- "nsdId": "c9f0a95e-dea0-4698-96e5-5a79bc5a233d",
- "nsName": "vcpe_e2e_vnf_test2",
- "nsDescription": "null"
- }
- response = self.apiClient.post(self.ns_instances_url, data=data, format=self.format, **header)
+ response = self.apiClient.post(self.ns_instances_url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)
@mock.patch.object(restcall, 'call_req')
def test_create_ns_when_ns_name_exist(self, mock_call_req):
NSInstModel.objects.all().delete()
NSInstModel(id="1", name="ns").save()
- nspackage_info = json.JSONEncoder().encode({
- "csarId": self.ns_package_id,
- "packageInfo": {}
- })
+ nspackage_info = json.JSONEncoder().encode(NS_PACKAGE_INFO_DICT)
mock_call_req.return_value = [0, nspackage_info, '200']
- header = {
- 'HTTP_GLOBALCUSTOMERID': 'global-customer-id-test1',
- 'HTTP_SERVICETYPE': 'service-type-test1'
- }
-
- data = {
- "nsdId": self.nsd_id,
- "nsName": "ns",
- "nsDescription": "description"
- }
- response = self.apiClient.post(self.ns_instances_url, data=data, format=self.format, **header)
+ response = self.apiClient.post(self.ns_instances_url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
@mock.patch.object(CreateNSService, "do_biz")
def test_create_ns_empty_data(self, mock_do_biz):
mock_do_biz.side_effect = Exception("Exception in CreateNS.")
- data = {
- 'nsdId': 'nsdId'
- }
- header = {
- 'HTTP_GLOBALCUSTOMERID': 'global-customer-id-test1',
- 'HTTP_SERVICETYPE': 'service-type-test1'
- }
- response = self.apiClient.post(self.ns_instances_url, data=data, format=self.format, **header)
+ response = self.apiClient.post(self.ns_instances_url, data={}, format=self.format, **SOL_REST_HEADER_DICT)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
@mock.patch.object(CreateNSService, "do_biz")
def test_create_ns_no_header(self, mock_do_biz):
mock_do_biz.side_effect = Exception("Exception in CreateNS.")
- data = {
- "nsdId": self.nsd_id,
- "nsName": "ns",
- "nsDescription": "description"
- }
- response = self.apiClient.post(self.ns_instances_url, data=data, format=self.format)
+ response = self.apiClient.post(self.ns_instances_url, data=SOL_CREATE_NS_DICT, format=self.format)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
@mock.patch.object(CreateNSService, "do_biz")
def test_create_ns_non_existing_nsd(self, mock_do_biz):
mock_do_biz.side_effect = NSLCMException("nsd not exists.")
- data = {
- "nsdId": self.nsd_id,
- "nsName": "ns",
- "nsDescription": "description"
- }
- header = {
- 'HTTP_GLOBALCUSTOMERID': 'global-customer-id-test1',
- 'HTTP_SERVICETYPE': 'service-type-test1'
- }
- response = self.apiClient.post(self.ns_instances_url, data=data, format=self.format, **header)
+ response = self.apiClient.post(self.ns_instances_url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
@mock.patch.object(restcall, 'call_req')
def test_create_ns_when_fail_to_get_nsd(self, mock_call_req):
mock_call_req.return_value = [1, "Failed to get nsd.", '500']
- data = {
- "nsdId": self.nsd_id,
- "nsName": "ns",
- "nsDescription": "description"
- }
- header = {
- 'HTTP_GLOBALCUSTOMERID': 'global-customer-id-test1',
- 'HTTP_SERVICETYPE': 'service-type-test1'
- }
- response = self.apiClient.post(self.ns_instances_url, data=data, format=self.format, **header)
+ response = self.apiClient.post(self.ns_instances_url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
def test_ns_instances_method_not_allowed(self):
- header = {
- 'HTTP_GLOBALCUSTOMERID': 'global-customer-id-test1',
- 'HTTP_SERVICETYPE': 'service-type-test1'
- }
-
- data = {
- "nsdId": self.nsd_id,
- "nsName": "ns",
- "nsDescription": "description"
- }
- response = self.apiClient.delete(self.ns_instances_url, data=data, format=self.format, **header)
+ response = self.apiClient.delete(self.ns_instances_url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
- response = self.apiClient.put(self.ns_instances_url, data=data, format=self.format, **header)
+ response = self.apiClient.put(self.ns_instances_url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
- response = self.apiClient.patch(self.ns_instances_url, data=data, format=self.format, **header)
+ response = self.apiClient.patch(self.ns_instances_url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
def test_invidual_ns_instance_method_not_allowed(self):
- header = {
- 'HTTP_GLOBALCUSTOMERID': 'global-customer-id-test1',
- 'HTTP_SERVICETYPE': 'service-type-test1'
- }
-
- data = {
- "nsdId": self.nsd_id,
- "nsName": "ns",
- "nsDescription": "description"
- }
url = self.ns_instances_url + '/1'
- response = self.apiClient.post(url, data=data, format=self.format, **header)
+ response = self.apiClient.post(url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
- response = self.apiClient.put(url, data=data, format=self.format, **header)
+ response = self.apiClient.put(url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
- response = self.apiClient.patch(url, data=data, format=self.format, **header)
+ response = self.apiClient.patch(url, data=SOL_CREATE_NS_DICT, format=self.format, **SOL_REST_HEADER_DICT)
self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
def test_query_ns(self):
@@ -228,14 +129,7 @@ class TestNsInstanceApi(TestCase):
@mock.patch.object(restcall, 'call_req')
def test_delete_ns(self, mock_call_req):
NSInstModel(id="1", nspackage_id="7", nsd_id="2").save()
- ns_info = {
- "service-instance-id": "service-instance-id-9b9348f2-f75d-4559-823d-db7ac138ed34",
- "service-instance-name": "service-instance-name-9b9348f2-f75d-4559-823d-db7ac138ed34",
- "service-type": "service-type-9b9348f2-f75d-4559-823d-db7ac138ed34",
- "service-role": "service-role-9b9348f2-f75d-4559-823d-db7ac138ed34",
- "resource-version": "1505350720009"
- }
- r1_query_ns_to_aai = [0, json.JSONEncoder().encode(ns_info), '200']
+ r1_query_ns_to_aai = [0, json.JSONEncoder().encode(NS_INFO_AAI_DICT), '200']
r2_delete_ns_to_aai = [0, json.JSONEncoder().encode({}), '200']
mock_call_req.side_effect = [r1_query_ns_to_aai, r2_delete_ns_to_aai]
url = self.ns_instances_url + '/1'