Unit Tests for Conductor/api module 27/31527/1
authorDileep Ranganathan <dileep.ranganathan@intel.com>
Sun, 11 Feb 2018 20:06:18 +0000 (12:06 -0800)
committerDileep Ranganathan <dileep.ranganathan@intel.com>
Sun, 11 Feb 2018 20:09:11 +0000 (12:09 -0800)
Created Unit Tests for PlansController

Change-Id: I075ef2289548fa5afc2024173866307d174ea3d5
Issue-ID: OPTFRA-68
Signed-off-by: Dileep Ranganathan <dileep.ranganathan@intel.com>
conductor/conductor/tests/unit/api/base_api.py
conductor/conductor/tests/unit/api/controller/test_root.py
conductor/conductor/tests/unit/api/controller/v1/plans.json [new file with mode: 0644]
conductor/conductor/tests/unit/api/controller/v1/test_plans.py [new file with mode: 0644]
conductor/conductor/tests/unit/api/controller/v1/test_v1_root.py

index ac89a57..6adc410 100644 (file)
@@ -20,6 +20,9 @@
 
 import os
 
+import eventlet
+eventlet.monkey_patch(os=False)
+
 import pecan
 import pecan.testing
 from oslo_config import cfg
@@ -28,6 +31,7 @@ from oslo_serialization import jsonutils
 from oslotest import base as oslo_test_base
 
 from conductor import service
+from conductor import controller
 
 
 class BaseApiTest(oslo_test_base.BaseTestCase):
index 3dbb66c..5821b4d 100644 (file)
@@ -29,7 +29,7 @@ class TestRoot(base_api.BaseApiTest):
         actual_response = self.app.get('/')
         req_json_file = './conductor/tests/unit/api/controller/versions.json'
         expected_response = json.loads(open(req_json_file).read())
-        print('GOT:%s' % actual_response)
+        print('GOT:%s' % actual_response)
         self.assertJsonEqual(actual_response.status_int, 200)
         self.assertJsonEqual(expected_response,
                              json.loads(actual_response.body))
diff --git a/conductor/conductor/tests/unit/api/controller/v1/plans.json b/conductor/conductor/tests/unit/api/controller/v1/plans.json
new file mode 100644 (file)
index 0000000..52feaa3
--- /dev/null
@@ -0,0 +1,6 @@
+{
+  "name": "demo3",
+  "template": {"key": "value"},
+  "timeout": 5,
+  "limit": 3
+}
\ No newline at end of file
diff --git a/conductor/conductor/tests/unit/api/controller/v1/test_plans.py b/conductor/conductor/tests/unit/api/controller/v1/test_plans.py
new file mode 100644 (file)
index 0000000..07de14f
--- /dev/null
@@ -0,0 +1,60 @@
+#
+# -------------------------------------------------------------------------
+#   Copyright (c) 2018 Intel Corporation Intellectual Property
+#
+#   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.
+#
+# -------------------------------------------------------------------------
+#
+"""Test case for PlansController"""
+
+import json
+
+import mock
+from conductor.api.controllers.v1 import plans
+from conductor.tests.unit.api import base_api
+from oslo_serialization import jsonutils
+
+
+class TestPlansController(base_api.BaseApiTest):
+
+    def test_index_options(self):
+        actual_response = self.app.options('/v1/plans', expect_errors=True)
+        self.assertEqual(204, actual_response.status_int)
+        self.assertEqual("GET,POST", actual_response.headers['Allow'])
+
+    @mock.patch.object(plans.LOG, 'error')
+    @mock.patch.object(plans.LOG, 'debug')
+    @mock.patch.object(plans.LOG, 'warning')
+    @mock.patch.object(plans.LOG, 'info')
+    def test_index_get(self, info_mock, warning_mock, debug_mock, error_mock):
+        actual_response = self.app.get('/v1/plans')
+        self.assertEqual(200, actual_response.status_int)
+
+    @mock.patch.object(plans.LOG, 'error')
+    @mock.patch.object(plans.LOG, 'debug')
+    @mock.patch.object(plans.LOG, 'warning')
+    @mock.patch.object(plans.LOG, 'info')
+    def test_index_post(self, info_mock, warning_mock, debug_mock, error_mock):
+        req_json_file = './conductor/tests/unit/api/controller/v1/plans.json'
+        params = jsonutils.dumps(json.loads(open(req_json_file).read()))
+        print(params)
+        response = self.app.post('/v1/plans', params=params,
+                                 expect_errors=True)
+        self.assertEqual(500, response.status_int)
+
+    def test_index_httpmethod_notallowed(self):
+        actual_response = self.app.put('/v1/plans', expect_errors=True)
+        self.assertEqual(405, actual_response.status_int)
+        actual_response = self.app.patch('/v1/plans', expect_errors=True)
+        self.assertEqual(405, actual_response.status_int)
index ade3f2c..512c0c2 100644 (file)
@@ -25,5 +25,5 @@ class TestV1Root(base_api.BaseApiTest):
 
     def test_get_v1_root(self):
         actual_response = self.app.get('/v1', expect_errors=True)
-        print('GOT:%s' % actual_response)
+        print('GOT:%s' % actual_response)
         self.assertEqual(actual_response.status_int, 405)