correct the import impl of TestAPI
[releng.git] / utils / test / testapi / opnfv_testapi / resources / pod_handlers.py
index 631d4a9..5029887 100644 (file)
@@ -6,21 +6,20 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
+import handlers
+from opnfv_testapi.resources import pod_models
 from opnfv_testapi.tornado_swagger import swagger
-from handlers import GenericApiHandler
-from pod_models import Pod
-from opnfv_testapi.common.constants import HTTP_FORBIDDEN
 
 
-class GenericPodHandler(GenericApiHandler):
+class GenericPodHandler(handlers.GenericApiHandler):
     def __init__(self, application, request, **kwargs):
         super(GenericPodHandler, self).__init__(application, request, **kwargs)
         self.table = 'pods'
-        self.table_cls = Pod
+        self.table_cls = pod_models.Pod
 
 
 class PodCLHandler(GenericPodHandler):
-    @swagger.operation(nickname='List all Pods')
+    @swagger.operation(nickname='listAllPods')
     def get(self):
         """
             @description: list all pods
@@ -29,7 +28,7 @@ class PodCLHandler(GenericPodHandler):
         """
         self._list()
 
-    @swagger.operation(nickname='Create a Pod')
+    @swagger.operation(nickname='createPod')
     def post(self):
         """
             @description: create a pod
@@ -41,20 +40,14 @@ class PodCLHandler(GenericPodHandler):
             @raise 403: pod already exists
             @raise 400: body or name not provided
         """
-        def query(data):
-            return {'name': data.name}
-
-        def error(data):
-            message = '{} already exists as a pod'.format(data.name)
-            return HTTP_FORBIDDEN, message
-
-        miss_checks = ['name']
-        db_checks = [(self.table, False, query, error)]
-        self._create(miss_checks, db_checks)
+        def query():
+            return {'name': self.json_args.get('name')}
+        miss_fields = ['name']
+        self._create(miss_fields=miss_fields, query=query)
 
 
 class PodGURHandler(GenericPodHandler):
-    @swagger.operation(nickname='Get a Pod by pod_name')
+    @swagger.operation(nickname='getPodByName')
     def get(self, pod_name):
         """
             @description: get a single pod by pod_name
@@ -62,9 +55,7 @@ class PodGURHandler(GenericPodHandler):
             @return 200: pod exist
             @raise 404: pod not exist
         """
-        query = dict()
-        query['name'] = pod_name
-        self._get_one(query)
+        self._get_one(query={'name': pod_name})
 
     def delete(self, pod_name):
         """ Remove a POD