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: I1af631f36c813740dbf22da030c2c1f50265d156 Partial-Bug: #1266962
This commit is contained in:
parent
4bec42e0d8
commit
f356607a95
|
@ -63,7 +63,6 @@ from keystone.openstack.common.db.sqlalchemy import migration
|
||||||
from keystone.openstack.common.db.sqlalchemy import session
|
from keystone.openstack.common.db.sqlalchemy import session
|
||||||
from keystone.openstack.common.fixture import config as config_fixture
|
from keystone.openstack.common.fixture import config as config_fixture
|
||||||
from keystone.openstack.common import log
|
from keystone.openstack.common import log
|
||||||
from keystone.openstack.common import timeutils
|
|
||||||
from keystone import service
|
from keystone import service
|
||||||
from keystone.tests import fixtures as ksfixtures
|
from keystone.tests import fixtures as ksfixtures
|
||||||
|
|
||||||
|
@ -348,8 +347,6 @@ class TestCase(testtools.TestCase):
|
||||||
|
|
||||||
self.addCleanup(kvs.INMEMDB.clear)
|
self.addCleanup(kvs.INMEMDB.clear)
|
||||||
|
|
||||||
self.addCleanup(timeutils.clear_time_override)
|
|
||||||
|
|
||||||
# Ensure Notification subscriotions and resource types are empty
|
# Ensure Notification subscriotions and resource types are empty
|
||||||
self.addCleanup(notifications.SUBSCRIBERS.clear)
|
self.addCleanup(notifications.SUBSCRIBERS.clear)
|
||||||
self.addCleanup(notifications._reset_notifier)
|
self.addCleanup(notifications._reset_notifier)
|
||||||
|
|
|
@ -16,6 +16,8 @@ import copy
|
||||||
import datetime
|
import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
from keystone import assignment
|
from keystone import assignment
|
||||||
from keystone import auth
|
from keystone import auth
|
||||||
from keystone.common import authorization
|
from keystone.common import authorization
|
||||||
|
@ -911,9 +913,12 @@ class AuthWithTrust(AuthTest):
|
||||||
|
|
||||||
|
|
||||||
class TokenExpirationTest(AuthTest):
|
class TokenExpirationTest(AuthTest):
|
||||||
def _maintain_token_expiration(self):
|
|
||||||
|
@mock.patch.object(timeutils, 'utcnow')
|
||||||
|
def _maintain_token_expiration(self, mock_utcnow):
|
||||||
"""Token expiration should be maintained after re-auth & validation."""
|
"""Token expiration should be maintained after re-auth & validation."""
|
||||||
timeutils.set_time_override()
|
now = datetime.datetime.utcnow()
|
||||||
|
mock_utcnow.return_value = now
|
||||||
|
|
||||||
r = self.controller.authenticate(
|
r = self.controller.authenticate(
|
||||||
{},
|
{},
|
||||||
|
@ -926,14 +931,14 @@ class TokenExpirationTest(AuthTest):
|
||||||
unscoped_token_id = r['access']['token']['id']
|
unscoped_token_id = r['access']['token']['id']
|
||||||
original_expiration = r['access']['token']['expires']
|
original_expiration = r['access']['token']['expires']
|
||||||
|
|
||||||
timeutils.advance_time_seconds(1)
|
mock_utcnow.return_value = now + datetime.timedelta(seconds=1)
|
||||||
|
|
||||||
r = self.controller.validate_token(
|
r = self.controller.validate_token(
|
||||||
dict(is_admin=True, query_string={}),
|
dict(is_admin=True, query_string={}),
|
||||||
token_id=unscoped_token_id)
|
token_id=unscoped_token_id)
|
||||||
self.assertEqual(original_expiration, r['access']['token']['expires'])
|
self.assertEqual(original_expiration, r['access']['token']['expires'])
|
||||||
|
|
||||||
timeutils.advance_time_seconds(1)
|
mock_utcnow.return_value = now + datetime.timedelta(seconds=2)
|
||||||
|
|
||||||
r = self.controller.authenticate(
|
r = self.controller.authenticate(
|
||||||
{},
|
{},
|
||||||
|
@ -946,7 +951,7 @@ class TokenExpirationTest(AuthTest):
|
||||||
scoped_token_id = r['access']['token']['id']
|
scoped_token_id = r['access']['token']['id']
|
||||||
self.assertEqual(original_expiration, r['access']['token']['expires'])
|
self.assertEqual(original_expiration, r['access']['token']['expires'])
|
||||||
|
|
||||||
timeutils.advance_time_seconds(1)
|
mock_utcnow.return_value = now + datetime.timedelta(seconds=3)
|
||||||
|
|
||||||
r = self.controller.validate_token(
|
r = self.controller.validate_token(
|
||||||
dict(is_admin=True, query_string={}),
|
dict(is_admin=True, query_string={}),
|
||||||
|
|
|
@ -12,10 +12,13 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
from keystone.common import sql
|
from keystone.common import sql
|
||||||
from keystone import config
|
from keystone import config
|
||||||
from keystone.openstack.common.db.sqlalchemy import session
|
from keystone.openstack.common.db.sqlalchemy import session
|
||||||
|
@ -530,12 +533,14 @@ class KeystoneClientTests(object):
|
||||||
client.tokens.authenticate,
|
client.tokens.authenticate,
|
||||||
token=token_id)
|
token=token_id)
|
||||||
|
|
||||||
def test_token_expiry_maintained(self):
|
@mock.patch.object(timeutils, 'utcnow')
|
||||||
timeutils.set_time_override()
|
def test_token_expiry_maintained(self, mock_utcnow):
|
||||||
|
now = datetime.datetime.utcnow()
|
||||||
|
mock_utcnow.return_value = now
|
||||||
foo_client = self.get_client(self.user_foo)
|
foo_client = self.get_client(self.user_foo)
|
||||||
|
|
||||||
orig_token = foo_client.service_catalog.catalog['token']
|
orig_token = foo_client.service_catalog.catalog['token']
|
||||||
timeutils.advance_time_seconds(1)
|
mock_utcnow.return_value = now + datetime.timedelta(seconds=1)
|
||||||
reauthenticated_token = foo_client.tokens.authenticate(
|
reauthenticated_token = foo_client.tokens.authenticate(
|
||||||
token=foo_client.auth_token)
|
token=foo_client.auth_token)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue