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: Ibbdae2ba60f3d706eba59d8af13cf7ee9acfae23
Closes-Bug:#1266962
tags/6.0.0.0b1
zhangyangyang 1 year ago
parent
commit
902a66e53d
1 changed files with 5 additions and 4 deletions
  1. 5
    4
      manila/tests/message/test_api.py

+ 5
- 4
manila/tests/message/test_api.py View File

@@ -33,11 +33,12 @@ class MessageApiTest(test.TestCase):
33 33
         self.ctxt = context.RequestContext('admin', 'fakeproject', True)
34 34
         self.ctxt.request_id = 'fakerequestid'
35 35
 
36
-    def test_create(self):
36
+    @mock.patch.object(timeutils, 'utcnow')
37
+    def test_create(self, mock_utcnow):
37 38
         CONF.set_override('message_ttl', 300)
38
-        timeutils.set_time_override()
39
-        self.addCleanup(timeutils.clear_time_override)
40
-        expected_expires_at = timeutils.utcnow() + datetime.timedelta(
39
+        now = datetime.datetime.utcnow()
40
+        mock_utcnow.return_value = now
41
+        expected_expires_at = now + datetime.timedelta(
41 42
             seconds=300)
42 43
         expected_message_record = {
43 44
             'project_id': 'fakeproject',

Loading…
Cancel
Save