]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Stub ResourceWithProps instead of GenericResource
authorZane Bitter <zbitter@redhat.com>
Tue, 13 Aug 2013 13:18:17 +0000 (15:18 +0200)
committerZane Bitter <zbitter@redhat.com>
Tue, 13 Aug 2013 13:18:17 +0000 (15:18 +0200)
Stubbing methods in a superclass is an all-or-nothing affair: once a stub
in the subclass is unset, the subclass will no longer inherit changes in
the superclass (i.e. if you then stub out the same method in the
superclass, the subclass will be unaffected).

Previously, we always set the stubs in the superclass (for historical
reasons, to avoid making this change). This would lead to tests that want
to differentiate between types (by stubbing in the derived class)
interfering with the operation of other tests. This patch changes to always
setting the stubs in the derived class.

Change-Id: I2c8dbd22826da14611a6a3f55321f0016446580a

heat/tests/test_parser.py
heat/tests/test_resource.py

index 5ebee5a2d0fd5e0d99839589157e350582468744..9f9a60955f0f9da055be43b7c2421e210609ec80 100644 (file)
@@ -994,10 +994,10 @@ class StackTest(HeatTestCase):
                                      template.Template(tmpl2))
 
         # patch in a dummy handle_update
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_update')
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_update')
         tmpl_diff = {'Properties': {'Foo': 'xyz'}}
         prop_diff = {'Foo': 'xyz'}
-        generic_rsrc.GenericResource.handle_update(
+        generic_rsrc.ResourceWithProps.handle_update(
             tmpl2['Resources']['AResource'], tmpl_diff,
             prop_diff).AndRaise(Exception("Foo"))
         self.m.ReplayAll()
@@ -1031,8 +1031,8 @@ class StackTest(HeatTestCase):
         # key/property in update_allowed_keys/update_allowed_properties
 
         # make the update fail deleting the existing resource
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_delete')
-        generic_rsrc.GenericResource.handle_delete().AndRaise(Exception)
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_delete')
+        generic_rsrc.ResourceWithProps.handle_delete().AndRaise(Exception)
         self.m.ReplayAll()
 
         self.stack.update(updated_stack)
@@ -1066,8 +1066,8 @@ class StackTest(HeatTestCase):
         # key/property in update_allowed_keys/update_allowed_properties
 
         # patch in a dummy handle_create making the replace fail creating
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_create')
-        generic_rsrc.GenericResource.handle_create().AndRaise(Exception)
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_create')
+        generic_rsrc.ResourceWithProps.handle_create().AndRaise(Exception)
         self.m.ReplayAll()
 
         self.stack.update(updated_stack)
@@ -1133,9 +1133,9 @@ class StackTest(HeatTestCase):
 
         # patch in a dummy handle_create making the replace fail when creating
         # the replacement rsrc, but succeed the second call (rollback)
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_create')
-        generic_rsrc.GenericResource.handle_create().AndRaise(Exception)
-        generic_rsrc.GenericResource.handle_create().AndReturn(None)
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_create')
+        generic_rsrc.ResourceWithProps.handle_create().AndRaise(Exception)
+        generic_rsrc.ResourceWithProps.handle_create().AndReturn(None)
         self.m.ReplayAll()
 
         self.stack.update(updated_stack)
@@ -1169,9 +1169,9 @@ class StackTest(HeatTestCase):
 
         # patch in a dummy handle_create making the replace fail when creating
         # the replacement rsrc, and again on the second call (rollback)
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_create')
-        generic_rsrc.GenericResource.handle_create().AndRaise(Exception)
-        generic_rsrc.GenericResource.handle_create().AndRaise(Exception)
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_create')
+        generic_rsrc.ResourceWithProps.handle_create().AndRaise(Exception)
+        generic_rsrc.ResourceWithProps.handle_create().AndRaise(Exception)
         self.m.ReplayAll()
 
         self.stack.update(updated_stack)
@@ -1280,10 +1280,10 @@ class StackTest(HeatTestCase):
         # resource.UpdateReplace because we've not specified the modified
         # key/property in update_allowed_keys/update_allowed_properties
 
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'FnGetRefId')
-        generic_rsrc.GenericResource.FnGetRefId().AndReturn(
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'FnGetRefId')
+        generic_rsrc.ResourceWithProps.FnGetRefId().AndReturn(
             'AResource')
-        generic_rsrc.GenericResource.FnGetRefId().MultipleTimes().AndReturn(
+        generic_rsrc.ResourceWithProps.FnGetRefId().MultipleTimes().AndReturn(
             'inst-007')
         self.m.ReplayAll()
 
@@ -1332,21 +1332,21 @@ class StackTest(HeatTestCase):
         self.assertEqual(self.stack['BResource'].properties['Foo'],
                          'AResource')
 
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'FnGetRefId')
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_create')
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'FnGetRefId')
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_create')
 
-        # Calls to GenericResource.handle_update will raise
+        # Calls to ResourceWithProps.handle_update will raise
         # resource.UpdateReplace because we've not specified the modified
         # key/property in update_allowed_keys/update_allowed_properties
 
-        generic_rsrc.GenericResource.FnGetRefId().AndReturn(
+        generic_rsrc.ResourceWithProps.FnGetRefId().AndReturn(
             'AResource')
 
         # mock to make the replace fail when creating the replacement resource
-        generic_rsrc.GenericResource.handle_create().AndRaise(Exception)
+        generic_rsrc.ResourceWithProps.handle_create().AndRaise(Exception)
 
-        generic_rsrc.GenericResource.handle_create().AndReturn(None)
-        generic_rsrc.GenericResource.FnGetRefId().MultipleTimes().AndReturn(
+        generic_rsrc.ResourceWithProps.handle_create().AndReturn(None)
+        generic_rsrc.ResourceWithProps.FnGetRefId().MultipleTimes().AndReturn(
             'AResource')
 
         self.m.ReplayAll()
@@ -1407,21 +1407,21 @@ class StackTest(HeatTestCase):
         self.assertEqual(self.stack['BResource'].properties['Foo'],
                          'AResource1')
 
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_create')
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_create')
 
-        # Calls to GenericResource.handle_update will raise
+        # Calls to ResourceWithProps.handle_update will raise
         # resource.UpdateReplace because we've not specified the modified
         # key/property in update_allowed_keys/update_allowed_properties
 
         # mock to make the replace fail when creating the second
         # replacement resource
-        generic_rsrc.GenericResource.handle_create().AndRaise(Exception)
+        generic_rsrc.ResourceWithProps.handle_create().AndRaise(Exception)
 
-        # Calls to GenericResource.handle_update will raise
+        # Calls to ResourceWithProps.handle_update will raise
         # resource.UpdateReplace because we've not specified the modified
         # key/property in update_allowed_keys/update_allowed_properties
 
-        generic_rsrc.GenericResource.handle_create().AndReturn(None)
+        generic_rsrc.ResourceWithProps.handle_create().AndReturn(None)
 
         self.m.ReplayAll()
 
index 5bc09cda94fdef77e635dc077855a42e9b87d6fc..fb9ee12741d271fc7b6c065c250a41801b4baecf 100644 (file)
@@ -302,8 +302,8 @@ class ResourceTest(HeatTestCase):
         utmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'xyz'}}
         tmpl_diff = {'Properties': {'Foo': 'xyz'}}
         prop_diff = {'Foo': 'xyz'}
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_update')
-        generic_rsrc.GenericResource.handle_update(
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_update')
+        generic_rsrc.ResourceWithProps.handle_update(
             utmpl, tmpl_diff, prop_diff).AndReturn(None)
         self.m.ReplayAll()
 
@@ -320,10 +320,10 @@ class ResourceTest(HeatTestCase):
         self.assertEqual((res.CREATE, res.COMPLETE), res.state)
 
         utmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'xyz'}}
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_update')
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_update')
         tmpl_diff = {'Properties': {'Foo': 'xyz'}}
         prop_diff = {'Foo': 'xyz'}
-        generic_rsrc.GenericResource.handle_update(
+        generic_rsrc.ResourceWithProps.handle_update(
             utmpl, tmpl_diff, prop_diff).AndRaise(resource.UpdateReplace())
         self.m.ReplayAll()
         # should be re-raised so parser.Stack can handle replacement
@@ -368,9 +368,9 @@ class ResourceTest(HeatTestCase):
         utmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'xyz'}}
         tmpl_diff = {'Properties': {'Foo': 'xyz'}}
         prop_diff = {'Foo': 'xyz'}
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_update')
-        generic_rsrc.GenericResource.handle_update(utmpl, tmpl_diff, prop_diff
-                                                   ).AndRaise(NotImplemented)
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_update')
+        generic_rsrc.ResourceWithProps.handle_update(
+            utmpl, tmpl_diff, prop_diff).AndRaise(NotImplemented)
         self.m.ReplayAll()
         self.assertRaises(exception.ResourceFailure, res.update, utmpl)
         self.assertEqual((res.UPDATE, res.FAILED), res.state)
@@ -426,8 +426,9 @@ class ResourceTest(HeatTestCase):
         scheduler.TaskRunner(res.create)()
         self.assertEqual((res.CREATE, res.COMPLETE), res.state)
 
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_suspend')
-        generic_rsrc.GenericResource.handle_suspend().AndRaise(Exception())
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps,
+                               'handle_suspend')
+        generic_rsrc.ResourceWithProps.handle_suspend().AndRaise(Exception())
         self.m.ReplayAll()
 
         suspend = scheduler.TaskRunner(res.suspend)
@@ -440,8 +441,8 @@ class ResourceTest(HeatTestCase):
         scheduler.TaskRunner(res.create)()
         self.assertEqual((res.CREATE, res.COMPLETE), res.state)
 
-        self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_resume')
-        generic_rsrc.GenericResource.handle_resume().AndRaise(Exception())
+        self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_resume')
+        generic_rsrc.ResourceWithProps.handle_resume().AndRaise(Exception())
         self.m.ReplayAll()
 
         res.state_set(res.SUSPEND, res.COMPLETE)