# 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 os import sys import fixtures import mock from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils import six import testtools from murano.cmd import test_runner from murano import version CONF = cfg.CONF logging.register_options(CONF) logging.setup(CONF, 'murano') class TestCaseShell(testtools.TestCase): def setUp(self): super(TestCaseShell, self).setUp() self.auth_params = {'username': 'test', 'password': 'test', 'project_name': 'test', 'auth_url': 'http://localhost:5000'} self.args = ['test-runner.py'] for k, v in six.iteritems(self.auth_params): k = '--os-' + k.replace('_', '-') self.args.extend([k, v]) self.useFixture(fixtures.MonkeyPatch('keystoneclient.v3.client.Client', mock.MagicMock)) dirs = [os.path.dirname(__file__), os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir, os.pardir, 'meta')] self.override_config('load_packages_from', dirs, 'engine') def tearDown(self): super(TestCaseShell, self).tearDown() CONF.clear() def override_config(self, name, override, group=None): CONF.set_override(name, override, group, enforce_type=True) CONF.set_override('use_stderr', True) self.addCleanup(CONF.clear_override, name, group) def shell(self, cmd_args=None, exitcode=0): stdout = six.StringIO() stderr = six.StringIO() args = self.args if cmd_args: cmd_args = cmd_args.split() args.extend(cmd_args) with mock.patch.object(sys, 'stdout', stdout): with mock.patch.object(sys, 'stderr', stderr): with mock.patch.object(sys, 'argv', args): result = self.assertRaises(SystemExit, test_runner.main) self.assertEqual(result.code, exitcode, 'Command finished with error.') stdout = stdout.getvalue() stderr = stderr.getvalue() return (stdout, stderr) def test_help(self): stdout, _ = self.shell('--help') usage = """usage: murano-test-runner [-h] [--config-file CONFIG_FILE] [--os-auth-url OS_AUTH_URL] [--os-username OS_USERNAME] [--os-password OS_PASSWORD] [--os-project-name OS_PROJECT_NAME] [-l [ [ ...]]] [-v] [--version] [ [