Add support for oslo.context 2.6.0
The 2.6.0 release of oslo.context adds a new attribute 'is_admin_project'. Always include that attribute when serializing the object, and expect it in our tests. Change-Id: I563cf810385e84ab30d49ef079b75df279006f0d Related-Bug: 1602081
This commit is contained in:
parent
66127c563e
commit
80738df83f
@ -174,6 +174,13 @@ class RequestContext(context.RequestContext):
|
|||||||
'instance_lock_checked': getattr(self, 'instance_lock_checked',
|
'instance_lock_checked': getattr(self, 'instance_lock_checked',
|
||||||
False)
|
False)
|
||||||
})
|
})
|
||||||
|
# NOTE(tonyb): This can be removed once we're certain to have a
|
||||||
|
# RequestContext contains 'is_admin_project', We can only get away with
|
||||||
|
# this because we "know" the default value of 'is_admin_project' which
|
||||||
|
# is very fragile.
|
||||||
|
values.update({
|
||||||
|
'is_admin_project': getattr(self, 'is_admin_project', True),
|
||||||
|
})
|
||||||
return values
|
return values
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -164,6 +164,7 @@ class ContextTestCase(test.NoDBTestCase):
|
|||||||
'domain': None,
|
'domain': None,
|
||||||
'instance_lock_checked': False,
|
'instance_lock_checked': False,
|
||||||
'is_admin': False,
|
'is_admin': False,
|
||||||
|
'is_admin_project': True,
|
||||||
'project_id': 222,
|
'project_id': 222,
|
||||||
'project_domain': None,
|
'project_domain': None,
|
||||||
'project_name': None,
|
'project_name': None,
|
||||||
@ -186,6 +187,37 @@ class ContextTestCase(test.NoDBTestCase):
|
|||||||
'user_name': None}
|
'user_name': None}
|
||||||
self.assertEqual(expected_values, values2)
|
self.assertEqual(expected_values, values2)
|
||||||
|
|
||||||
|
def test_convert_from_dict_to_dict_version_2_4_x(self):
|
||||||
|
# fake dict() created with oslo.context 2.4.x, Missing is_admin_project
|
||||||
|
# key
|
||||||
|
values = {'user': '111',
|
||||||
|
'user_id': '111',
|
||||||
|
'tenant': '222',
|
||||||
|
'project_id': '222',
|
||||||
|
'domain': None, 'project_domain': None,
|
||||||
|
'auth_token': None,
|
||||||
|
'resource_uuid': None, 'read_only': False,
|
||||||
|
'user_identity': '111 222 - - -',
|
||||||
|
'instance_lock_checked': False,
|
||||||
|
'user_name': None, 'project_name': None,
|
||||||
|
'timestamp': '2015-03-02T20:03:59.416299',
|
||||||
|
'remote_address': None, 'quota_class': None,
|
||||||
|
'is_admin': True,
|
||||||
|
'service_catalog': [],
|
||||||
|
'read_deleted': 'no', 'show_deleted': False,
|
||||||
|
'roles': [],
|
||||||
|
'request_id': 'req-956637ad-354a-4bc5-b969-66fd1cc00f50',
|
||||||
|
'user_domain': None}
|
||||||
|
ctx = context.RequestContext.from_dict(values)
|
||||||
|
self.assertEqual('111', ctx.user)
|
||||||
|
self.assertEqual('222', ctx.tenant)
|
||||||
|
self.assertEqual('111', ctx.user_id)
|
||||||
|
self.assertEqual('222', ctx.project_id)
|
||||||
|
# to_dict() will add is_admin_project
|
||||||
|
values.update({'is_admin_project': True})
|
||||||
|
values2 = ctx.to_dict()
|
||||||
|
self.assertEqual(values, values2)
|
||||||
|
|
||||||
def test_convert_from_dict_then_to_dict(self):
|
def test_convert_from_dict_then_to_dict(self):
|
||||||
values = {'user': '111',
|
values = {'user': '111',
|
||||||
'user_id': '111',
|
'user_id': '111',
|
||||||
@ -200,6 +232,7 @@ class ContextTestCase(test.NoDBTestCase):
|
|||||||
'timestamp': '2015-03-02T20:03:59.416299',
|
'timestamp': '2015-03-02T20:03:59.416299',
|
||||||
'remote_address': None, 'quota_class': None,
|
'remote_address': None, 'quota_class': None,
|
||||||
'is_admin': True,
|
'is_admin': True,
|
||||||
|
'is_admin_project': True,
|
||||||
'service_catalog': [],
|
'service_catalog': [],
|
||||||
'read_deleted': 'no', 'show_deleted': False,
|
'read_deleted': 'no', 'show_deleted': False,
|
||||||
'roles': [],
|
'roles': [],
|
||||||
|
Loading…
Reference in New Issue
Block a user