Browse Source

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: I7c3793d7a442dc85aec405041c3c9ce6f7503bd8
Closes-Bug: #1266962
tags/2014.1.b3
ZhiQiang Fan 5 years ago
parent
commit
ef3cc9c635
1 changed files with 8 additions and 7 deletions
  1. 8
    7
      ceilometer/tests/event/test_converter.py

+ 8
- 7
ceilometer/tests/event/test_converter.py View File

@@ -24,7 +24,6 @@ from oslo.config import cfg as oslo_cfg
24 24
 import six
25 25
 
26 26
 from ceilometer.event import converter
27
-from ceilometer.openstack.common import timeutils
28 27
 from ceilometer.storage import models
29 28
 from ceilometer.tests import base
30 29
 
@@ -548,10 +547,11 @@ class TestEventDefinition(ConverterBase):
548 547
         edef = converter.EventDefinition(cfg, self.fake_plugin_mgr)
549 548
         self.assertTrue(edef.is_catchall)
550 549
 
551
-    def test_extract_when(self):
552
-        now = timeutils.utcnow()
550
+    @mock.patch('ceilometer.openstack.common.timeutils.utcnow')
551
+    def test_extract_when(self, mock_utcnow):
552
+        now = datetime.datetime.utcnow()
553 553
         modified = now + datetime.timedelta(minutes=1)
554
-        timeutils.set_time_override(now)
554
+        mock_utcnow.return_value = now
555 555
 
556 556
         body = {"timestamp": str(modified)}
557 557
         when = converter.EventDefinition._extract_when(body)
@@ -624,10 +624,11 @@ class TestNotificationConverter(ConverterBase):
624 624
             host='cydonia')
625 625
         self.fake_plugin_mgr = {}
626 626
 
627
-    def test_converter_missing_keys(self):
627
+    @mock.patch('ceilometer.openstack.common.timeutils.utcnow')
628
+    def test_converter_missing_keys(self, mock_utcnow):
628 629
         # test a malformed notification
629
-        now = timeutils.utcnow()
630
-        timeutils.set_time_override(now)
630
+        now = datetime.datetime.utcnow()
631
+        mock_utcnow.return_value = now
631 632
         c = converter.NotificationEventsConverter(
632 633
             [],
633 634
             self.fake_plugin_mgr,

Loading…
Cancel
Save