From ddaf858e59007aa26cca6bdae4c211721fa1371e Mon Sep 17 00:00:00 2001 From: Bulat Gaifullin Date: Mon, 30 May 2016 14:46:10 +0300 Subject: [PATCH] Fixed mock for settings in lcm tests Added mock for settings instead of modifying global settings Change-Id: I9e539e1a94b1202b467e43833dfeb52a50b58918 --- .../test/integration/test_task_managers.py | 8 ++++--- .../unit/test_lcm_transaction_serializer.py | 22 +++++++------------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/nailgun/nailgun/test/integration/test_task_managers.py b/nailgun/nailgun/test/integration/test_task_managers.py index cf0c01b4c0..f46b20d031 100644 --- a/nailgun/nailgun/test/integration/test_task_managers.py +++ b/nailgun/nailgun/test/integration/test_task_managers.py @@ -211,11 +211,13 @@ class TestTaskManagers(BaseIntegrationTest): ) @fake_tasks() - @mock.patch('nailgun.lcm.transaction_serializer.settings', - LCM_CHECK_TASK_VERSION=True) + @mock.patch( + 'nailgun.lcm.transaction_serializer.settings.LCM_CHECK_TASK_VERSION', + new=True + ) @mock.patch('objects.Cluster.get_deployment_tasks') @mock.patch('objects.Cluster.is_propagate_task_deploy_enabled') - def test_adaptation_legacy_tasks(self, propagate_mock, tasks_mock, _): + def test_adaptation_legacy_tasks(self, propagate_mock, tasks_mock): tasks_mock.return_value = [ { 'id': 'task', 'parameters': {}, 'type': 'puppet', diff --git a/nailgun/nailgun/test/unit/test_lcm_transaction_serializer.py b/nailgun/nailgun/test/unit/test_lcm_transaction_serializer.py index 48487eee07..dabc5f9696 100644 --- a/nailgun/nailgun/test/unit/test_lcm_transaction_serializer.py +++ b/nailgun/nailgun/test/unit/test_lcm_transaction_serializer.py @@ -19,7 +19,6 @@ import mock from nailgun import consts from nailgun import errors from nailgun import lcm -from nailgun.settings import settings from nailgun.utils.role_resolver import RoleResolver from nailgun.test.base import BaseUnitTest @@ -369,19 +368,11 @@ class TestTransactionSerializer(BaseUnitTest): {"task1": {"type": "puppet"}}, {"id": "task1", "type": "skipped"} )) - def test_serialize_fail_if_not_all_tasks_have_version2(self): - tasks = list(self.tasks) - tasks[-1] = self.tasks[-1].copy() - del tasks[-1]['version'] - self.assertRaises( - errors.TaskBaseDeploymentNotAllowed, - lcm.TransactionSerializer.serialize, - self.context, tasks, self.role_resolver - ) - + @mock.patch( + 'nailgun.lcm.transaction_serializer.settings.LCM_CHECK_TASK_VERSION', + new=True + ) def test_ensure_task_based_deploy_allowed_raises_if_version_check(self): - settings.LCM_CHECK_TASK_VERSION = True - self.assertRaises( errors.TaskBaseDeploymentNotAllowed, lcm.TransactionSerializer.ensure_task_based_deploy_allowed, @@ -389,8 +380,11 @@ class TestTransactionSerializer(BaseUnitTest): 'version': '1.0.0', 'id': 'test'} ) + @mock.patch( + 'nailgun.lcm.transaction_serializer.settings.LCM_CHECK_TASK_VERSION', + new=False + ) def test_ensure_task_based_deploy_allowed_if_not_version_check(self): - settings.LCM_CHECK_TASK_VERSION = False self.assertNotRaises( errors.TaskBaseDeploymentNotAllowed, lcm.TransactionSerializer.ensure_task_based_deploy_allowed,