Refactor existing context attributes to base class
The oslo.context base class already supports is_admin and roles attributes. This patch removes unnecessary overrides. It also fixes inconsistency in tests, where some of the parameters, passed to the dummy_context were not passed to the resulting RequestContext. Co-Authored-By: Kirill Zaitsev <k.zaitsev@me.com> Change-Id: Idf979528b9d9df3305ba1994009367061fd4f413
This commit is contained in:
parent
ed4a6b5ddc
commit
9b19e4a0f4
|
@ -24,13 +24,10 @@ class RequestContext(context.RequestContext):
|
|||
as well as additional request information.
|
||||
"""
|
||||
|
||||
def __init__(self, session=None,
|
||||
roles=None, is_admin=None, service_catalog=None,
|
||||
def __init__(self, session=None, service_catalog=None,
|
||||
**kwargs):
|
||||
super(RequestContext, self).__init__(**kwargs)
|
||||
self.session = session
|
||||
self.roles = roles or []
|
||||
self.service_catalog = service_catalog
|
||||
self.is_admin = is_admin
|
||||
if self.is_admin is None:
|
||||
self.is_admin = policy.check_is_admin(self)
|
||||
|
|
|
@ -18,20 +18,17 @@ from murano.db import session
|
|||
|
||||
|
||||
def dummy_context(user='test_username', tenant_id='test_tenant_id',
|
||||
password='password', roles=None, user_id=None,
|
||||
is_admin=False, request_id='dummy-request'):
|
||||
if roles is None:
|
||||
roles = []
|
||||
# NOTE(kzaitsev) passing non-False value by default to request_id, to
|
||||
# prevent generation during tests.
|
||||
return context.RequestContext.from_dict({
|
||||
request_id='dummy-request', **kwargs):
|
||||
|
||||
# NOTE(kzaitsev) we need to pass non-False value to request_id, to
|
||||
# prevent it being generated by oslo during tests.
|
||||
params = {
|
||||
'request_id': request_id,
|
||||
'tenant': tenant_id,
|
||||
'user': user,
|
||||
# 'roles': roles, # Commented until policy check changes land
|
||||
'is_admin': is_admin,
|
||||
|
||||
})
|
||||
}
|
||||
params.update(kwargs)
|
||||
return context.RequestContext.from_dict(params)
|
||||
|
||||
|
||||
def save_models(*models):
|
||||
|
|
Loading…
Reference in New Issue