From 8dd0eebbab7a49bc3ccba17fb08598f22d0fd23b Mon Sep 17 00:00:00 2001 From: Samantha Blanco Date: Tue, 11 Oct 2016 10:29:28 -0400 Subject: [PATCH] Increase unit test coverage for engine system Implements bp: murano-unit-test-coverage Change-Id: I47eae07c73564d0a03b01d43fc1c3c8011ae1b59 --- .../unit/engine/system/test_agent_listener.py | 47 +++++++++++++++++ .../engine/system/test_instance_reporter.py | 49 ++++++++++++++++++ .../engine/system/test_metadef_browser.py | 51 +++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 murano/tests/unit/engine/system/test_agent_listener.py create mode 100644 murano/tests/unit/engine/system/test_instance_reporter.py create mode 100644 murano/tests/unit/engine/system/test_metadef_browser.py diff --git a/murano/tests/unit/engine/system/test_agent_listener.py b/murano/tests/unit/engine/system/test_agent_listener.py new file mode 100644 index 000000000..b7bfb6a5a --- /dev/null +++ b/murano/tests/unit/engine/system/test_agent_listener.py @@ -0,0 +1,47 @@ +# Copyright (c) 2016 AT&T +# +# 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 mock + +from murano.engine.system import agent_listener +from murano.tests.unit import base + + +class TestExecutionPlan(base.MuranoTestCase): + def setUp(self): + super(TestExecutionPlan, self).setUp() + + name = "test" + results_queue = str('-execution-results-%s' % name.lower()) + self.agent = agent_listener.AgentListener(name) + self.assertEqual({}, self.agent._subscriptions) + self.assertEqual(results_queue, self.agent._results_queue) + self.assertTrue(self.agent._enabled) + self.assertIsNone(self.agent._receive_thread) + + self.addCleanup(mock.patch.stopall) + + def test_queue_name(self): + self.assertEqual(self.agent._results_queue, self.agent.queue_name()) + + @mock.patch("murano.engine.system.agent_listener.dsl.get_this") + @mock.patch("murano.engine.system." + "agent_listener.dsl.get_execution_session") + def test_subscribe_unsubscribe(self, execution_session, mock_this): + self.agent.subscribe('msg_id', 'event') + self.assertIn('msg_id', self.agent._subscriptions) + self.agent.unsubscribe('msg_id') + self.assertNotIn('msg_id', self.agent._subscriptions) + self.assertTrue(execution_session.called) + self.assertTrue(mock_this.called) diff --git a/murano/tests/unit/engine/system/test_instance_reporter.py b/murano/tests/unit/engine/system/test_instance_reporter.py new file mode 100644 index 000000000..4597c6227 --- /dev/null +++ b/murano/tests/unit/engine/system/test_instance_reporter.py @@ -0,0 +1,49 @@ +# Copyright (c) 2016 AT&T +# +# 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 mock + +from murano.db import models +from murano.engine.system import instance_reporter +from murano.tests.unit import base + +LATEST_VERSION = 1 + + +class TestInstanceReporter(base.MuranoTestCase): + def setUp(self): + super(TestInstanceReporter, self).setUp() + + self.environment = models.Environment( + name='test_environment', tenant_id='test_tenant_id', + version=LATEST_VERSION + ) + + self.addCleanup(mock.patch.stopall) + + @mock.patch("murano.db.models") + def test_track_untrack_application(self, mock_models): + instance = mock_models.Instance() + self.i_r = instance_reporter.InstanceReportNotifier(self.environment) + self.assertEqual(self.environment.id, self.i_r._environment_id) + self.assertIsNone(self.i_r.track_application(instance)) + self.assertIsNone(self.i_r.untrack_application(instance)) + + @mock.patch("murano.db.models") + def test_track_untrack_cloud_instance(self, mock_models): + instance = mock_models.Instance() + self.i_r = instance_reporter.InstanceReportNotifier(self.environment) + self.assertEqual(self.environment.id, self.i_r._environment_id) + self.assertIsNone(self.i_r.track_cloud_instance(instance)) + self.assertIsNone(self.i_r.untrack_cloud_instance(instance)) diff --git a/murano/tests/unit/engine/system/test_metadef_browser.py b/murano/tests/unit/engine/system/test_metadef_browser.py new file mode 100644 index 000000000..0aa3fdf28 --- /dev/null +++ b/murano/tests/unit/engine/system/test_metadef_browser.py @@ -0,0 +1,51 @@ +# Copyright (c) 2016 AT&T +# +# 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 mock + +from murano.dsl import murano_object +from murano.engine.system import metadef_browser +from murano.tests.unit import base + + +class TestMetadefBrowser(base.MuranoTestCase): + def setUp(self): + super(TestMetadefBrowser, self).setUp() + self.this = mock.MagicMock() + + self.glance_client_mock = mock.MagicMock() + metadef_browser.MetadefBrowser._get_client = mock.MagicMock( + return_value=self.glance_client_mock) + metadef_browser.MetadefBrowser._client = mock.MagicMock( + return_value=self.glance_client_mock) + + self.mock_object = mock.Mock(spec=murano_object.MuranoObject) + + @mock.patch("murano.dsl.helpers.get_execution_session") + def test_get_objects(self, execution_session): + namespace = None + self.metadef = metadef_browser.MetadefBrowser(self.this) + self.assertIsNotNone(self.metadef.get_objects(namespace)) + self.assertTrue(execution_session.called) + self.assertTrue(metadef_browser.MetadefBrowser. + _client.metadefs_object.list.called) + + @mock.patch("murano.dsl.helpers.get_execution_session") + def test_get_namespaces(self, execution_session): + self.metadef = metadef_browser.MetadefBrowser(self.this) + resource_type = self.mock_object + self.assertIsNotNone(self.metadef.get_namespaces(resource_type)) + self.assertTrue(execution_session.called) + self.assertTrue(metadef_browser.MetadefBrowser. + _client.metadefs_namespace.list.called)