]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Removes use of timeutils.set_time_override
authorZhongyue Luo <zhongyue.nah@intel.com>
Fri, 7 Feb 2014 04:43:58 +0000 (12:43 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Wed, 12 Feb 2014 08:48:37 +0000 (16:48 +0800)
The set_time_override function in timeutils was written as a
helper function to mock utcnow for unittests before 'mock' was
generally used. Now that we have mock and fixture, we no longer
need to use it.

Change-Id: I057d4bc3a8b1d4e96e6830cd3071dc96a05496dc
Partial-Bug: #1266962

cinder/tests/test_quota.py
cinder/tests/test_utils.py

index d6bdb3734d64face6be18cec7a83b9e8925269ca..03017643a99ad8577541a7ac80595da4424724cf 100644 (file)
@@ -18,6 +18,7 @@
 
 import datetime
 
+import mock
 from oslo.config import cfg
 
 from cinder import context
@@ -737,11 +738,10 @@ class DbQuotaDriverTestCase(test.TestCase):
 
         self.calls = []
 
-        timeutils.set_time_override()
-
-    def tearDown(self):
-        timeutils.clear_time_override()
-        super(DbQuotaDriverTestCase, self).tearDown()
+        patcher = mock.patch.object(timeutils, 'utcnow')
+        self.addCleanup(patcher.stop)
+        self.mock_utcnow = patcher.start()
+        self.mock_utcnow.return_value = datetime.datetime.utcnow()
 
     def test_get_defaults(self):
         # Use our pre-defined resources
@@ -1163,7 +1163,10 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase):
         self.stubs.Set(sqa_api, '_quota_usage_create', fake_quota_usage_create)
         self.stubs.Set(sqa_api, '_reservation_create', fake_reservation_create)
 
-        timeutils.set_time_override()
+        patcher = mock.patch.object(timeutils, 'utcnow')
+        self.addCleanup(patcher.stop)
+        self.mock_utcnow = patcher.start()
+        self.mock_utcnow.return_value = datetime.datetime.utcnow()
 
     def _make_quota_usage(self, project_id, resource, in_use, reserved,
                           until_refresh, created_at, updated_at):
index 380c13522267a796316d9671eee38b6908a0f7fb..6de90f1984497863aae6407c383e3534f8c415d4 100644 (file)
@@ -22,6 +22,7 @@ import StringIO
 import tempfile
 import uuid
 
+import mock
 import mox
 from oslo.config import cfg
 import paramiko
@@ -614,17 +615,16 @@ class AuditPeriodTest(test.TestCase):
     def setUp(self):
         super(AuditPeriodTest, self).setUp()
         #a fairly random time to test with
-        self.test_time = datetime.datetime(second=23,
-                                           minute=12,
-                                           hour=8,
-                                           day=5,
-                                           month=3,
-                                           year=2012)
-        timeutils.set_time_override(override_time=self.test_time)
-
-    def tearDown(self):
-        timeutils.clear_time_override()
-        super(AuditPeriodTest, self).tearDown()
+        test_time = datetime.datetime(second=23,
+                                      minute=12,
+                                      hour=8,
+                                      day=5,
+                                      month=3,
+                                      year=2012)
+        patcher = mock.patch.object(timeutils, 'utcnow')
+        self.addCleanup(patcher.stop)
+        self.mock_utcnow = patcher.start()
+        self.mock_utcnow.return_value = test_time
 
     def test_hour(self):
         begin, end = utils.last_completed_audit_period(unit='hour')