response = self.client.get("/api/vnfres/v1/%s/volumes" % self.nf_inst_id)
self.assertEqual(self.volumes_data, response.data)
self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
-
- def test_swagger_ok(self):
- resp = self.client.get("/api/vnfres/v1/swagger.json", format="json")
- self.assertEqual(resp.status_code, status.HTTP_200_OK, resp.content)
from rest_framework.urlpatterns import format_suffix_patterns
from res.resources import views
-from res.resources.views import SwaggerJsonView
urlpatterns = [
url(r'^api/vnfres/v1/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)$', views.get_vnf, name='get_vnf'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/subnets$', views.get_subnets, name='get_subnets'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/cps$', views.getCps.as_view(), name='get_cps'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/volumes$', views.getVolumes.as_view(), name='get_volumes'),
- url(r'^api/vnfres/v1/swagger.json$', SwaggerJsonView.as_view()),
]
urlpatterns = format_suffix_patterns(urlpatterns)
# See the License for the specific language governing permissions and
# limitations under the License.
-import json
import logging
-import os
import traceback
from drf_yasg.utils import swagger_auto_schema
from rest_framework.response import Response
from rest_framework.views import APIView
-from res.pub.exceptions import VNFRESException
-from res.pub.utils.values import ignore_case_get
-from res.pub.utils.syscomm import fun_name
from res.pub.database.models import NfInstModel, StorageInstModel, NetworkInstModel, VLInstModel, \
VNFCInstModel, VmInstModel, FlavourInstModel, SubNetworkInstModel, CPInstModel
+from res.pub.exceptions import VNFRESException
+from res.pub.utils.syscomm import fun_name
+from res.pub.utils.values import ignore_case_get
from res.resources.serializers import VolumeInfoSerializer, NoneSerializer, CpsInfoSerializer
logger = logging.getLogger(__name__)
"size": v.size
}
return volumes_data
-
-
-class SwaggerJsonView(APIView):
- def get(self, request):
- json_file = os.path.join(os.path.dirname(__file__), 'swagger.json')
- f = open(json_file)
- json_data = json.JSONDecoder().decode(f.read())
- f.close()
- return Response(json_data)
--- /dev/null
+# Copyright 2018 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
--- /dev/null
+# Copyright 2018 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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 unittest
+
+from rest_framework import status
+from rest_framework.test import APIClient
+
+
+class SwaggerViewTest(unittest.TestCase):
+ def setUp(self):
+ self.client = APIClient()
+
+ def tearDown(self):
+ pass
+
+ def test_swagger_ok(self):
+ resp = self.client.get("/api/vnfres/v1/swagger.json", format="json")
+ self.assertEqual(resp.status_code, status.HTTP_200_OK, resp.content)
--- /dev/null
+# Copyright 2018 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+from django.conf.urls import url
+
+from res.swagger.views import SwaggerJsonView
+
+urlpatterns = [
+ url(r'^api/vnfres/v1/swagger.json$', SwaggerJsonView.as_view()),
+]
--- /dev/null
+# Copyright 2018 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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 json
+import os
+
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+
+class SwaggerJsonView(APIView):
+ def get(self, request):
+ json_file = os.path.join(os.path.dirname(__file__), 'swagger.json')
+ f = open(json_file)
+ json_data = json.JSONDecoder().decode(f.read())
+ f.close()
+ return Response(json_data)
urlpatterns = [
url(r'^', include('res.samples.urls')),
+ url(r'^', include('res.swagger.urls')),
url(r'^', include('res.resources.urls')),
url(r'^swagger(?P<format>.json|.yaml)$', SchemaView.without_ui(cache_timeout=0), name='schema-json'),
url(r'^swagger/$', SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),