Fixed mock for settings in lcm tests

Added mock for settings instead of modifying global settings

Change-Id: I9e539e1a94b1202b467e43833dfeb52a50b58918
This commit is contained in:
Bulat Gaifullin 2016-05-30 14:46:10 +03:00
parent fa7ed6bb5a
commit ddaf858e59
2 changed files with 13 additions and 17 deletions

View File

@ -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',

View File

@ -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,