1 # Copyright 2017 ZTE Corporation.
\r
3 # Licensed under the Apache License, Version 2.0 (the "License");
\r
4 # you may not use this file except in compliance with the License.
\r
5 # You may obtain a copy of the License at
\r
7 # http://www.apache.org/licenses/LICENSE-2.0
\r
9 # Unless required by applicable law or agreed to in writing, software
\r
10 # distributed under the License is distributed on an "AS IS" BASIS,
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 # See the License for the specific language governing permissions and
\r
13 # limitations under the License.
\r
14 from django.test import TestCase, Client
\r
15 from rest_framework import status
\r
17 from lcm.pub.database.models import NSInstModel
\r
20 class TestNsQuery(TestCase):
\r
22 self.client = Client()
\r
23 NSInstModel(id=1, nsd_id=11, name='test01').save()
\r
24 NSInstModel(id=2, nsd_id=22, name='test02').save()
\r
26 def test_query_ns_by_nsinstance_id(self):
\r
27 response = self.client.get("/api/nslcm/v1/ns/1")
\r
28 self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
\r
29 self.assertIsNotNone(response.data)
\r
31 def test_query_all_nsinstance(self):
\r
32 response = self.client.get("/api/nslcm/v1/ns")
\r
33 self.failUnlessEqual(status.HTTP_200_OK, response.status_code, response.data)
\r
34 self.assertIsNotNone(response.data)
\r
35 self.assertEqual(2, len(response.data))
\r
37 def test_query_ns_by_non_existing_nsinstance_id(self):
\r
38 response = self.client.get("/api/nslcm/v1/ns/200")
\r
39 self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code)
\r