Merge "Remove from_dict function from context"

This commit is contained in:
Zuul 2020-11-23 13:44:29 +00:00 committed by Gerrit Code Review
commit 388a42731e
2 changed files with 4 additions and 23 deletions

View File

@ -36,17 +36,6 @@ class RequestContext(context.RequestContext):
})
return policy_values
@classmethod
def from_dict(cls, values, **kwargs):
# TODO(vdrok): these are left so that if older service communicates
# with a new one, new one could still understand what old one sends,
# remove in Queens
kwargs.setdefault('is_public_api', values.get('is_public_api', False))
if 'domain_id' in values:
kwargs.setdefault('user_domain', values['domain_id'])
return super(RequestContext, RequestContext).from_dict(values,
**kwargs)
def ensure_thread_contain_context(self):
"""Ensure threading contains context

View File

@ -23,7 +23,7 @@ class RequestContextTestCase(tests_base.TestCase):
super(RequestContextTestCase, self).setUp()
self.context_dict = {
'auth_token': 'auth_token1',
"user": "user1",
"user_id": "user1",
"project_id": "project1",
"project_name": "somename",
'is_admin': True,
@ -31,10 +31,10 @@ class RequestContextTestCase(tests_base.TestCase):
'show_deleted': True,
'request_id': 'id1',
"is_public_api": True,
"domain": "domain_id2",
"user_domain": "domain_id3",
"domain_id": "domain_id2",
"user_domain_id": "domain_id3",
"user_domain_name": "TreeDomain",
"project_domain": "domain_id4",
"project_domain_id": "domain_id4",
"roles": None,
"overwrite": True
}
@ -45,14 +45,6 @@ class RequestContextTestCase(tests_base.TestCase):
context_mock.assert_called_once_with(mock.ANY)
self.assertFalse(test_context.is_public_api)
def test_from_dict(self):
test_context = context.RequestContext.from_dict(
{'project_name': 'demo', 'is_public_api': True,
'domain_id': 'meow'})
self.assertEqual('demo', test_context.project_name)
self.assertEqual('meow', test_context.user_domain_id)
self.assertTrue(test_context.is_public_api)
def test_to_policy_values(self):
ctx = context.RequestContext(**self.context_dict)
ctx_dict = ctx.to_policy_values()