From: Michal Dulko Date: Tue, 23 Jun 2015 13:47:53 +0000 (+0200) Subject: Harden scheduler.rpcapi unit tests X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=18c1a32e7285f12932e8fda430f9ee95f1de8ef7;p=openstack-build%2Fcinder-build.git Harden scheduler.rpcapi unit tests 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 --- diff --git a/cinder/tests/unit/scheduler/test_rpcapi.py b/cinder/tests/unit/scheduler/test_rpcapi.py index c37044c56..c76617b74 100644 --- a/cinder/tests/unit/scheduler/test_rpcapi.py +++ b/cinder/tests/unit/scheduler/test_rpcapi.py @@ -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',