From 141c765eb1d567a71634e9fb1ab7e79f546672cb Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Wed, 20 Sep 2017 15:05:43 +0100 Subject: [PATCH] Add initial unit tests for kayobe CLI commands Currently only tests control host bootstrap and control host upgrade. --- kayobe/tests/unit/cli/__init__.py | 0 kayobe/tests/unit/cli/test_commands.py | 70 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 kayobe/tests/unit/cli/__init__.py create mode 100644 kayobe/tests/unit/cli/test_commands.py diff --git a/kayobe/tests/unit/cli/__init__.py b/kayobe/tests/unit/cli/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/kayobe/tests/unit/cli/test_commands.py b/kayobe/tests/unit/cli/test_commands.py new file mode 100644 index 000000000..27c7e6195 --- /dev/null +++ b/kayobe/tests/unit/cli/test_commands.py @@ -0,0 +1,70 @@ +# Copyright (c) 2017 StackHPC 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 unittest + +import cliff.app +import cliff.commandmanager +import mock + +from kayobe.cli import commands +from kayobe import utils + + +class TestApp(cliff.app.App): + + def __init__(self): + super(TestApp, self).__init__( + description='Test app', + version='0.1', + command_manager=cliff.commandmanager.CommandManager('kayobe.cli')) + + +class TestCase(unittest.TestCase): + + @mock.patch.object(utils, "galaxy_install", spec=True) + @mock.patch.object(commands.KayobeAnsibleMixin, + "run_kayobe_playbooks") + def test_control_host_bootstrap(self, mock_run, mock_install): + command = commands.ControlHostBootstrap(TestApp(), []) + parser = command.get_parser("test") + parsed_args = parser.parse_args([]) + result = command.run(parsed_args) + self.assertEqual(0, result) + mock_install.assert_called_once_with("ansible/requirements.yml", + "ansible/roles") + expected_calls = [ + mock.call(mock.ANY, ["ansible/bootstrap.yml"]), + mock.call(mock.ANY, ["ansible/kolla-ansible.yml"], + tags="install"), + ] + self.assertEqual(expected_calls, mock_run.call_args_list) + + @mock.patch.object(utils, "galaxy_install", spec=True) + @mock.patch.object(commands.KayobeAnsibleMixin, + "run_kayobe_playbooks") + def test_control_host_upgrade(self, mock_run, mock_install): + command = commands.ControlHostUpgrade(TestApp(), []) + parser = command.get_parser("test") + parsed_args = parser.parse_args([]) + result = command.run(parsed_args) + self.assertEqual(0, result) + mock_install.assert_called_once_with("ansible/requirements.yml", + "ansible/roles", force=True) + expected_calls = [ + mock.call(mock.ANY, ["ansible/bootstrap.yml"]), + mock.call(mock.ANY, ["ansible/kolla-ansible.yml"], + tags="install"), + ] + self.assertEqual(expected_calls, mock_run.call_args_list)