Increase unit test coverage for engine system
Implements bp: murano-unit-test-coverage Change-Id: I47eae07c73564d0a03b01d43fc1c3c8011ae1b59
This commit is contained in:
parent
3562357f6b
commit
8dd0eebbab
|
@ -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)
|
|
@ -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))
|
|
@ -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)
|
Loading…
Reference in New Issue