From a689ff1ccc5f162e109e4616935dbd037f33d447 Mon Sep 17 00:00:00 2001 From: Dileep Ranganathan Date: Sun, 11 Feb 2018 12:06:18 -0800 Subject: Unit Tests for Conductor/api module Created Unit Tests for PlansController Change-Id: I075ef2289548fa5afc2024173866307d174ea3d5 Issue-ID: OPTFRA-68 Signed-off-by: Dileep Ranganathan --- conductor/conductor/tests/unit/api/base_api.py | 4 ++ .../tests/unit/api/controller/test_root.py | 2 +- .../tests/unit/api/controller/v1/plans.json | 6 +++ .../tests/unit/api/controller/v1/test_plans.py | 60 ++++++++++++++++++++++ .../tests/unit/api/controller/v1/test_v1_root.py | 2 +- 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 conductor/conductor/tests/unit/api/controller/v1/plans.json create mode 100644 conductor/conductor/tests/unit/api/controller/v1/test_plans.py (limited to 'conductor') diff --git a/conductor/conductor/tests/unit/api/base_api.py b/conductor/conductor/tests/unit/api/base_api.py index ac89a57..6adc410 100644 --- a/conductor/conductor/tests/unit/api/base_api.py +++ b/conductor/conductor/tests/unit/api/base_api.py @@ -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): diff --git a/conductor/conductor/tests/unit/api/controller/test_root.py b/conductor/conductor/tests/unit/api/controller/test_root.py index 3dbb66c..5821b4d 100644 --- a/conductor/conductor/tests/unit/api/controller/test_root.py +++ b/conductor/conductor/tests/unit/api/controller/test_root.py @@ -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 index 0000000..52feaa3 --- /dev/null +++ b/conductor/conductor/tests/unit/api/controller/v1/plans.json @@ -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 index 0000000..07de14f --- /dev/null +++ b/conductor/conductor/tests/unit/api/controller/v1/test_plans.py @@ -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) diff --git a/conductor/conductor/tests/unit/api/controller/v1/test_v1_root.py b/conductor/conductor/tests/unit/api/controller/v1/test_v1_root.py index ade3f2c..512c0c2 100644 --- a/conductor/conductor/tests/unit/api/controller/v1/test_v1_root.py +++ b/conductor/conductor/tests/unit/api/controller/v1/test_v1_root.py @@ -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) -- cgit 1.2.3-korg