Removes use of timeutils.set_time_override

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
This commit is contained in:
Zhongyue Luo 2014-02-07 12:43:58 +08:00
parent e6d91ed83a
commit e3eb709b08
2 changed files with 20 additions and 17 deletions

View File

@ -18,6 +18,7 @@
import datetime import datetime
import mock
from oslo.config import cfg from oslo.config import cfg
from cinder import context from cinder import context
@ -737,11 +738,10 @@ class DbQuotaDriverTestCase(test.TestCase):
self.calls = [] self.calls = []
timeutils.set_time_override() patcher = mock.patch.object(timeutils, 'utcnow')
self.addCleanup(patcher.stop)
def tearDown(self): self.mock_utcnow = patcher.start()
timeutils.clear_time_override() self.mock_utcnow.return_value = datetime.datetime.utcnow()
super(DbQuotaDriverTestCase, self).tearDown()
def test_get_defaults(self): def test_get_defaults(self):
# Use our pre-defined resources # 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, '_quota_usage_create', fake_quota_usage_create)
self.stubs.Set(sqa_api, '_reservation_create', fake_reservation_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, def _make_quota_usage(self, project_id, resource, in_use, reserved,
until_refresh, created_at, updated_at): until_refresh, created_at, updated_at):

View File

@ -22,6 +22,7 @@ import StringIO
import tempfile import tempfile
import uuid import uuid
import mock
import mox import mox
from oslo.config import cfg from oslo.config import cfg
import paramiko import paramiko
@ -614,17 +615,16 @@ class AuditPeriodTest(test.TestCase):
def setUp(self): def setUp(self):
super(AuditPeriodTest, self).setUp() super(AuditPeriodTest, self).setUp()
#a fairly random time to test with #a fairly random time to test with
self.test_time = datetime.datetime(second=23, test_time = datetime.datetime(second=23,
minute=12, minute=12,
hour=8, hour=8,
day=5, day=5,
month=3, month=3,
year=2012) year=2012)
timeutils.set_time_override(override_time=self.test_time) patcher = mock.patch.object(timeutils, 'utcnow')
self.addCleanup(patcher.stop)
def tearDown(self): self.mock_utcnow = patcher.start()
timeutils.clear_time_override() self.mock_utcnow.return_value = test_time
super(AuditPeriodTest, self).tearDown()
def test_hour(self): def test_hour(self):
begin, end = utils.last_completed_audit_period(unit='hour') begin, end = utils.last_completed_audit_period(unit='hour')