From 1f18d9e17b203ee3c6bf3cb47321c81f6466e18c Mon Sep 17 00:00:00 2001 From: Hieu LE Date: Thu, 11 Aug 2016 12:08:41 +0700 Subject: [PATCH] Improve unit test coverage for cmd/api.py Add new unit tests for cmd/api.py. Increase the coverage for cmd/api.py from 0 to 100%. Change-Id: I2409ed9ff11b55ae761d4f0b5768f65ca1bec9e3 Partial-Bug: #1511667 --- magnum/tests/unit/cmd/__init__.py | 0 magnum/tests/unit/cmd/test_api.py | 38 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 magnum/tests/unit/cmd/__init__.py create mode 100644 magnum/tests/unit/cmd/test_api.py diff --git a/magnum/tests/unit/cmd/__init__.py b/magnum/tests/unit/cmd/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/magnum/tests/unit/cmd/test_api.py b/magnum/tests/unit/cmd/test_api.py new file mode 100644 index 0000000000..a7fa8b0085 --- /dev/null +++ b/magnum/tests/unit/cmd/test_api.py @@ -0,0 +1,38 @@ +# Copyright 2016 - Fujitsu, Ltd. +# +# 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 mock + +from magnum.cmd import api +from magnum.tests import base + + +class TestMagnumAPI(base.TestCase): + + # NOTE(hieulq): need to mock MagnumObject, otherwise other test cases + # will be failed because of setting wrong ovo indirection api + @mock.patch('magnum.objects.base.MagnumObject') + @mock.patch('wsgiref.simple_server.make_server') + @mock.patch.object(api, 'api_app') + @mock.patch('magnum.common.service.prepare_service') + def test_api(self, mock_prep, mock_app, mock_make, mock_base): + api.main() + + app = mock_app.load_app.return_value + server = mock_make.return_value + mock_prep.assert_called_once_with(mock.ANY) + mock_app.load_app.assert_called_once_with() + mock_make.assert_called_once_with(base.CONF.api.host, + base.CONF.api.port, app) + server.serve_forever.assert_called_once_with()