From d4996440fa16297aee7a925e6357a9cfd42d24f8 Mon Sep 17 00:00:00 2001 From: Jose Lausuch Date: Wed, 15 Nov 2017 17:11:41 +0100 Subject: Remove prepare_env After moving the rally installation out of prepare_env It doesn't much sense to keep this script as it doesn't do useful things any more. Change-Id: I9ab3b2dd30c8ec0fbb825ee4302a83cce80f1cbe Signed-off-by: Jose Lausuch --- functest/tests/unit/ci/test_run_tests.py | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'functest/tests/unit/ci/test_run_tests.py') diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py index bc95f8f3d..fc689452d 100644 --- a/functest/tests/unit/ci/test_run_tests.py +++ b/functest/tests/unit/ci/test_run_tests.py @@ -7,6 +7,7 @@ import logging import unittest +import os import mock @@ -58,6 +59,85 @@ class RunTestsTesting(unittest.TestCase): self.run_tests_parser = run_tests.RunTestsParser() + self.config_file_yaml = {'general': { + 'openstack': { + 'image_name': 'test_image_name'}}, + 'results': { + 'test_db_url': 'url1'}} + self.config_file_patch_yaml = {'fdio': {'general': { + 'openstack': { + 'image_name': + 'test_image_name_2'}}}} + self.config_file_aarcg64_patch_yaml = {'os': {'general': { + 'openstack': {'image_name': 'test_image_name_3'}}}} + + @mock.patch('functest.ci.run_tests.Runner.patch_file') + @mock.patch('functest.ci.run_tests.Runner.update_db_url') + def test_update_config_file_default(self, *mock_methods): + self.runner.update_config_file() + mock_methods[1].assert_called() + mock_methods[0].assert_not_called() + + @mock.patch('functest.ci.run_tests.Runner.patch_file') + @mock.patch('functest.ci.run_tests.Runner.update_db_url') + @mock.patch.dict(os.environ, {'TEST_DB_URL': 'somevalue'}) + def test_update_config_file_update_db(self, *mock_methods): + self.runner.update_config_file() + mock_methods[1].assert_called() + mock_methods[0].assert_called() + + def test_patch_file_missing_file(self): + patch_file_path = "unexisting_file" + with self.assertRaises(IOError): + self.runner.patch_file(patch_file_path) + + @mock.patch('functest.ci.run_tests.ft_utils.merge_dicts') + @mock.patch('functest.ci.run_tests.ft_utils.get_functest_yaml') + def test_patch_file_default(self, *mock_methods): + CONST.__setattr__('DEPLOY_SCENARIO', 'os-nosdn-nofeature-noha') + with mock.patch( + 'six.moves.builtins.open', mock.mock_open()), mock.patch( + 'functest.ci.run_tests.yaml.safe_load') as yaml1, mock.patch( + 'functest.ci.run_tests.ft_utils.get_functest_yaml') as yaml2: + yaml1.return_value = self.config_file_patch_yaml + yaml2.return_value = self.config_file_yaml + self.runner.patch_file(yaml1) + mock_methods[1].assert_not_called() + mock_methods[0].assert_not_called() + + @mock.patch('functest.ci.run_tests.ft_utils.merge_dicts') + @mock.patch('functest.ci.run_tests.os.remove') + def test_patch_file_match_scenario(self, *mock_methods): + CONST.__setattr__('DEPLOY_SCENARIO', 'os-nosdn-fdio-noha') + with mock.patch( + 'six.moves.builtins.open', mock.mock_open()), mock.patch( + 'functest.ci.run_tests.yaml.safe_load') as yaml1, mock.patch( + 'functest.ci.run_tests.ft_utils.get_functest_yaml') as yaml2: + yaml1.return_value = self.config_file_patch_yaml + yaml2.return_value = self.config_file_yaml + self.runner.patch_file(yaml2) + mock_methods[1].assert_called() + mock_methods[0].assert_called() + + def test_update_db_url_missing_file(self): + run_tests.CONFIG_FUNCTEST_PATH = "unexisting_file" + with self.assertRaises(IOError): + self.runner.update_db_url() + + @mock.patch('functest.ci.run_tests.yaml.safe_load') + @mock.patch('functest.ci.run_tests.ft_utils.get_functest_yaml') + @mock.patch.dict(os.environ, {'TEST_DB_URL': 'url2'}) + def test_update_db_url_default(self, *mock_methods): + with mock.patch( + 'six.moves.builtins.open', mock.mock_open()), mock.patch( + 'functest.ci.run_tests.yaml.safe_load') as yaml1: + yaml1.return_value = self.config_file_yaml + self.runner.update_db_url() + self.assertEqual( + yaml1.return_value['results']['test_db_url'], 'url2') + mock_methods[0].assert_not_called() + mock_methods[1].assert_not_called() + @mock.patch('functest.ci.run_tests.logger.error') def test_source_rc_file_missing_file(self, mock_logger_error): with mock.patch('functest.ci.run_tests.os.path.isfile', -- cgit 1.2.3-korg