]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix a test_db_plugin unit test side_effect usage
authorKevin Benton <blak111@gmail.com>
Sun, 14 Sep 2014 09:22:57 +0000 (02:22 -0700)
committerKevin Benton <blak111@gmail.com>
Sun, 14 Sep 2014 09:22:57 +0000 (02:22 -0700)
One of the unit tests didn't correctly use the side_effect
parameter for a mock to return different responses to multiple
calls, which resulted in an extra try-except block and an inline
note. This commit fixes the side_effect and removes the extra
catching code.

Change-Id: Ifa1a6a15025b710ecbba956b5b848e32314cf0cf

neutron/tests/unit/test_db_plugin.py

index 0fb4023115c461b5f00891a88df191bf74c739cd..0948cecb30560820623fdb084a9579c566236281 100644 (file)
@@ -3901,16 +3901,9 @@ class TestNeutronDbPluginV2(base.BaseTestCase):
                                    '_rebuild_availability_ranges') as rebuild:
 
                 exception = n_exc.IpAddressGenerationFailure(net_id='n')
-                generate.side_effect = exception
-
-                # I want the side_effect to throw an exception once but I
-                # didn't see a way to do this.  So, let it throw twice and
-                # catch the second one.  Check below to ensure that
-                # _try_generate_ip was called twice.
-                try:
-                    db_base_plugin_v2.NeutronDbPluginV2._generate_ip('c', 's')
-                except n_exc.IpAddressGenerationFailure:
-                    pass
+                # fail first call but not second
+                generate.side_effect = [exception, None]
+                db_base_plugin_v2.NeutronDbPluginV2._generate_ip('c', 's')
 
         self.assertEqual(2, generate.call_count)
         rebuild.assert_called_once_with('c', 's')