Add make_admin_context to Magnum context
make_admin_context will return a admin context which can be used to fake a context which will be use for periodic task. Partial-Implements: blueprint add-periodic-task Co-Authored-By: ShaoHe Feng <shaohe.feng@intel.com> Change-Id: I92ff05e6e40ea8bd0c08ae279b70ef5f1a7e70be
This commit is contained in:
parent
e1440c8e09
commit
42ec89f913
|
@ -75,3 +75,15 @@ class RequestContext(context.RequestContext):
|
|||
|
||||
def make_context(*args, **kwargs):
|
||||
return RequestContext(*args, **kwargs)
|
||||
|
||||
|
||||
def make_admin_context(show_deleted=False):
|
||||
"""Create an administrator context.
|
||||
|
||||
:param show_deleted: if True, will show deleted items when query db
|
||||
"""
|
||||
context = RequestContext(user_id=None,
|
||||
project=None,
|
||||
is_admin=True,
|
||||
show_deleted=show_deleted)
|
||||
return context
|
||||
|
|
|
@ -74,3 +74,7 @@ class ContextTestCase(base.TestCase):
|
|||
self.assertEqual(ctx.request_id, ctx2.request_id)
|
||||
self.assertEqual(ctx.trust_id, ctx2.trust_id)
|
||||
self.assertEqual(ctx.auth_token_info, ctx2.auth_token_info)
|
||||
|
||||
def test_request_context_sets_is_admin(self):
|
||||
ctxt = magnum_context.make_admin_context()
|
||||
self.assertEqual(ctxt.is_admin, True)
|
||||
|
|
Loading…
Reference in New Issue