From b8967b6b943d44eb38f16239be32da45e3b2ffe7 Mon Sep 17 00:00:00 2001 From: Rui Yuan Dou Date: Tue, 18 Dec 2018 14:54:57 +0800 Subject: [PATCH] Add api app unit test Change-Id: Ie9e9b0fa39c672c430234172cf213eaca191aa1e Closes-Bug: #1808921 --- mogan/tests/unit/api/test_app.py | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 mogan/tests/unit/api/test_app.py diff --git a/mogan/tests/unit/api/test_app.py b/mogan/tests/unit/api/test_app.py new file mode 100644 index 00000000..8f91282d --- /dev/null +++ b/mogan/tests/unit/api/test_app.py @@ -0,0 +1,41 @@ +# +# 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. + +"""Tests for the Pecan API app.""" + + +import mock +from pecan import hooks + +from mogan.api import app +from mogan.api.controllers.root import RootController +from mogan.engine import api as engineapi +from mogan.tests import base + + +class TestHook(hooks.PecanHook): + pass + + +class TestApplication(base.TestCase): + @mock.patch.object(engineapi, 'API') + def test_setup_app(self, mock_api): + moganapp = app.setup_app() + self.assertIsInstance(moganapp._mogan_app.application.app.root, + RootController) + + @mock.patch.object(engineapi, 'API') + def test_setup_app_with_extra_hooks(self, mock_api): + testhook = TestHook() + moganapp = app.setup_app(extra_hooks=[testhook]) + self.assertIn(testhook, moganapp._mogan_app.application.app.hooks)