summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-05-01 17:06:27 +0000
committerGerrit Code Review <review@openstack.org>2017-05-01 17:06:27 +0000
commit65339f57ca56113b9b17a57119aac1804269333d (patch)
tree0409c651a99d59fdf282471024ba0e00b408e094
parent0b87f3c287d3954ea9ace85721b8eff18687fbcf (diff)
parente83c1a419a64a1d0abd63674cfc1d27f66b31830 (diff)
Merge "Don't use MagicMock for stacks in tests" into stable/newton7.0.4
-rw-r--r--heat/tests/openstack/neutron/test_neutron.py33
1 files changed, 19 insertions, 14 deletions
diff --git a/heat/tests/openstack/neutron/test_neutron.py b/heat/tests/openstack/neutron/test_neutron.py
index f018f61..2a88e98 100644
--- a/heat/tests/openstack/neutron/test_neutron.py
+++ b/heat/tests/openstack/neutron/test_neutron.py
@@ -16,12 +16,14 @@ from neutronclient.common import exceptions as qe
16import six 16import six
17 17
18from heat.common import exception 18from heat.common import exception
19from heat.engine.clients.os import neutron
20from heat.engine import properties 19from heat.engine import properties
21from heat.engine.resources.openstack.neutron import net 20from heat.engine.resources.openstack.neutron import net
22from heat.engine.resources.openstack.neutron import neutron as nr 21from heat.engine.resources.openstack.neutron import neutron as nr
23from heat.engine import rsrc_defn 22from heat.engine import rsrc_defn
23from heat.engine import stack
24from heat.engine import template
24from heat.tests import common 25from heat.tests import common
26from heat.tests import utils
25 27
26 28
27class NeutronTest(common.HeatTestCase): 29class NeutronTest(common.HeatTestCase):
@@ -73,7 +75,7 @@ class NeutronTest(common.HeatTestCase):
73 'FROBULATING due to "Unknown"', 75 'FROBULATING due to "Unknown"',
74 six.text_type(e)) 76 six.text_type(e))
75 77
76 def test_resolve_attribute(self): 78 def _get_some_neutron_resource(self):
77 class SomeNeutronResource(nr.NeutronResource): 79 class SomeNeutronResource(nr.NeutronResource):
78 properties_schema = {} 80 properties_schema = {}
79 81
@@ -81,20 +83,23 @@ class NeutronTest(common.HeatTestCase):
81 def is_service_available(cls, context): 83 def is_service_available(cls, context):
82 return (True, None) 84 return (True, None)
83 85
84 tmpl = rsrc_defn.ResourceDefinition('test_res', 'Foo') 86 empty_tmpl = {'heat_template_version': '2016-10-14'}
85 stack = mock.MagicMock() 87 tmpl = template.Template(empty_tmpl)
86 stack.has_cache_data = mock.Mock(return_value=False) 88 stack_name = 'dummystack'
87 res = SomeNeutronResource('aresource', tmpl, stack) 89 self.dummy_stack = stack.Stack(utils.dummy_context(), stack_name, tmpl)
88 90
89 mock_show_resource = mock.MagicMock() 91 tmpl = rsrc_defn.ResourceDefinition('test_res', 'Foo')
90 mock_show_resource.side_effect = [{'attr1': 'val1', 'attr2': 'val2'}, 92 self.dummy_stack.has_cache_data = mock.Mock(return_value=False)
91 {'attr1': 'val1', 'attr2': 'val2'}, 93 return SomeNeutronResource('aresource', tmpl, self.dummy_stack)
92 {'attr1': 'val1', 'attr2': 'val2'},
93 qe.NotFound]
94 res._show_resource = mock_show_resource
95 nclientplugin = neutron.NeutronClientPlugin(mock.MagicMock())
96 res.client_plugin = mock.Mock(return_value=nclientplugin)
97 94
95 def test_resolve_attribute(self):
96 res = self._get_some_neutron_resource()
97 side_effect = [{'attr1': 'val1', 'attr2': 'val2'},
98 {'attr1': 'val1', 'attr2': 'val2'},
99 {'attr1': 'val1', 'attr2': 'val2'},
100 qe.NotFound]
101 self.patchobject(res, '_show_resource', side_effect=side_effect)
102 res.resource_id = 'resource_id'
98 self.assertEqual({'attr1': 'val1', 'attr2': 'val2'}, 103 self.assertEqual({'attr1': 'val1', 'attr2': 'val2'},
99 res.FnGetAtt('show')) 104 res.FnGetAtt('show'))
100 self.assertEqual('val2', res._resolve_all_attributes('attr2')) 105 self.assertEqual('val2', res._resolve_all_attributes('attr2'))