# Copyright (c) 2013 Mirantis Inc.
#
# 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 json
import os
import unittest
import deep
import mock
import mockfs
from muranoconductor.workflow import Workflow
def load_sample(name):
with mockfs.storage.original_open(os.path.join(
os.path.dirname(__file__),
'sample_data',
name)) as sample_file:
return sample_file.read()
class TestWorkflow(unittest.TestCase):
def setUp(self):
self.mfs = mockfs.replace_builtins()
self.model = json.loads(load_sample('objectModel1.json'))
self.original_model = json.loads(load_sample('objectModel1.json'))
self.metadata_id = 'b5bbea94023083e1ee06a52af5663b15c1fb1b7c'
def tearDown(self):
mockfs.restore_builtins()
def _execute_workflow(self, xml):
self.mfs.add_entries({'test': xml})
stub = mock.MagicMock()
stub.side_effect = RuntimeError
workflow = Workflow('test', self.model, stub,
stub, stub, self.metadata_id)
workflow.execute()
def test_empty_workflow_leaves_object_model_unchanged(self):
xml = ''
self._execute_workflow(xml)
self.assertTrue(deep.diff(self.original_model, self.model) is None)
def test_modifying_object_model_from_workflow(self):
xml = '''
value
'''
self.assertFalse(
'state' in
self.model['services']['activeDirectories'][0])
self._execute_workflow(xml)
self.assertEqual(
self.model['services']['activeDirectories'][0]['state']['invalid'],
'value')
self.assertFalse(deep.diff(self.original_model, self.model) is None)
del self.model['services']['activeDirectories'][0]['state']
self.assertTrue(deep.diff(self.original_model, self.model) is None)
def test_selecting_properties_from_object_model_within_workflow(self):
xml = '''
Domain with primary DC
'''
self._execute_workflow(xml)
self.assertEqual(
self.model['services']['activeDirectories'][0]['test'],
'Domain acme.loc with primary DC dc01')