]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix test_create_volume_flow test issue
authorGorka Eguileor <geguileo@redhat.com>
Wed, 2 Mar 2016 13:21:31 +0000 (14:21 +0100)
committerGorka Eguileor <geguileo@redhat.com>
Wed, 2 Mar 2016 14:16:22 +0000 (15:16 +0100)
One of the tests in
cinder/tests/unit/volume/flows/test_create_volume_flow.py incorrectly
mocks time.time function which means that when there's a call to
time.time() it will raise an error because real time function doesn't
expect any arguments but the mock method does expect self as an
argument.

For some reason time.time function does not get called on every test
run, but when it does get called it will fail.

This patch fixes this by binding the mock method to the current self
instance.

Change-Id: Ia70e51719abb9a6ed357802446847ffa81d7427e

cinder/tests/unit/volume/flows/test_create_volume_flow.py

index 4302611b15fe534476ac5408022e4684d74ddd3a..93461ce0c1da937bc3f31d8510ac9fd6baaf1f40 100644 (file)
@@ -42,7 +42,6 @@ class CreateVolumeFlowTestCase(test.TestCase):
     def setUp(self):
         super(CreateVolumeFlowTestCase, self).setUp()
         self.ctxt = context.get_admin_context()
-        self.counter = float(0)
 
         # Ensure that time.time() always returns more than the last time it was
         # called to avoid div by zero errors.
@@ -50,10 +49,11 @@ class CreateVolumeFlowTestCase(test.TestCase):
 
     @mock.patch('cinder.objects.Volume.get_by_id')
     @mock.patch('cinder.volume.utils.extract_host')
-    @mock.patch('time.time', side_effect=time_inc)
+    @mock.patch('time.time')
     @mock.patch('cinder.objects.ConsistencyGroup.get_by_id')
     def test_cast_create_volume(self, consistencygroup_get_by_id, mock_time,
                                 mock_extract_host, volume_get_by_id):
+        mock_time.side_effect = self.time_inc
         volume = fake_volume.fake_volume_obj(self.ctxt)
         volume_get_by_id.return_value = volume
         props = {}