]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Harden scheduler.rpcapi unit tests
authorMichal Dulko <michal.dulko@intel.com>
Tue, 23 Jun 2015 13:47:53 +0000 (15:47 +0200)
committerMichal Dulko <michal.dulko@intel.com>
Tue, 23 Jun 2015 13:47:53 +0000 (15:47 +0200)
Tests for scheduler.rpcapi are very weak. Even changing keyword
arguments names passed to call and cast methods in this module
doesn't trigger unit tests failures. This commit adds keyword
arguments validation to prevent problems similar to ones caused
by bug 1467841 in backup.rpcapi. I've also fixed argument order
in assertEqual usages there.

Change-Id: I78d80d5c5596fb5615608f93157d4d2b3a9b0aef
Related-Bug: 1467841

cinder/tests/unit/scheduler/test_rpcapi.py

index c37044c568b5e843b0a71b16dff03e13909bc929..c76617b7468d7f6fc793de91f5fd8c84b3df238e 100644 (file)
@@ -56,7 +56,7 @@ class SchedulerRpcAPITestCase(test.TestCase):
 
         def _fake_prepare_method(*args, **kwds):
             for kwd in kwds:
-                self.assertEqual(kwds[kwd], target[kwd])
+                self.assertEqual(target[kwd], kwds[kwd])
             return rpcapi.client
 
         def _fake_rpc_method(*args, **kwargs):
@@ -71,10 +71,13 @@ class SchedulerRpcAPITestCase(test.TestCase):
             with mock.patch.object(rpcapi.client, rpc_method) as mock_method:
                 mock_method.side_effect = _fake_rpc_method
                 retval = getattr(rpcapi, method)(ctxt, **kwargs)
-                self.assertEqual(retval, expected_retval)
+                self.assertEqual(expected_retval, retval)
                 expected_args = [ctxt, method, expected_msg]
                 for arg, expected_arg in zip(self.fake_args, expected_args):
-                    self.assertEqual(arg, expected_arg)
+                    self.assertEqual(expected_arg, arg)
+
+                for kwarg, value in self.fake_kwargs.items():
+                    self.assertEqual(expected_msg[kwarg], value)
 
     def test_update_service_capabilities(self):
         self._test_scheduler_api('update_service_capabilities',