Merge "added unit tests for cue.common.context"
This commit is contained in:
commit
8a56568e97
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# Copyright 2014-2015 Hewlett-Packard Development Company, L.P.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from oslo_context import context
|
from oslo_context import context
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,24 +26,29 @@ class RequestContext(context.RequestContext):
|
||||||
is_public_api=False, domain_id=None, domain_name=None):
|
is_public_api=False, domain_id=None, domain_name=None):
|
||||||
"""Stores several additional request parameters:
|
"""Stores several additional request parameters:
|
||||||
|
|
||||||
|
:param roles:
|
||||||
:param domain_id: The ID of the domain.
|
:param domain_id: The ID of the domain.
|
||||||
:param domain_name: The name of the domain.
|
:param domain_name: The name of the domain.
|
||||||
:param is_public_api: Specifies whether the request should be processed
|
:param is_public_api: Specifies whether the request should be processed
|
||||||
without authentication.
|
without authentication.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
super(RequestContext, self).__init__(auth_token=auth_token, user=user,
|
||||||
|
tenant=tenant, domain=domain,
|
||||||
|
user_domain=user_domain,
|
||||||
|
project_domain=project_domain,
|
||||||
|
is_admin=is_admin,
|
||||||
|
read_only=read_only,
|
||||||
|
show_deleted=show_deleted,
|
||||||
|
request_id=request_id,
|
||||||
|
resource_uuid=resource_uuid,
|
||||||
|
overwrite=overwrite)
|
||||||
|
|
||||||
self.roles = roles or []
|
self.roles = roles or []
|
||||||
self.is_public_api = is_public_api
|
self.is_public_api = is_public_api
|
||||||
self.domain_id = domain_id
|
self.domain_id = domain_id
|
||||||
self.domain_name = domain_name
|
self.domain_name = domain_name
|
||||||
|
|
||||||
super(RequestContext, self).__init__(auth_token=auth_token,
|
|
||||||
user=user, tenant=tenant,
|
|
||||||
is_admin=is_admin,
|
|
||||||
read_only=read_only,
|
|
||||||
show_deleted=show_deleted,
|
|
||||||
request_id=request_id)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def project_id(self):
|
def project_id(self):
|
||||||
return self.tenant
|
return self.tenant
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# Copyright 2014, Hewlett-Packard
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright 2014-2015 Hewlett-Packard Development Company, L.P.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -12,12 +13,51 @@
|
||||||
# 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 uuid
|
||||||
|
|
||||||
from cue.common import context
|
from cue.common import context
|
||||||
from cue.tests.unit import base
|
from cue.tests.unit import base
|
||||||
|
|
||||||
|
|
||||||
class TestConfig(base.UnitTestCase):
|
class TestContext(base.UnitTestCase):
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_context(self):
|
||||||
|
original_context = {
|
||||||
|
'auth_token': str(uuid.uuid4()),
|
||||||
|
'user': str(uuid.uuid4()),
|
||||||
|
'tenant': str(uuid.uuid4()),
|
||||||
|
'domain': str(uuid.uuid4()),
|
||||||
|
'user_domain': str(uuid.uuid4()),
|
||||||
|
'project_domain': str(uuid.uuid4()),
|
||||||
|
'is_admin': False,
|
||||||
|
'read_only': False,
|
||||||
|
'show_deleted': False,
|
||||||
|
'request_id': str(uuid.uuid4()),
|
||||||
|
'resource_uuid': str(uuid.uuid4()),
|
||||||
|
'roles': str(uuid.uuid4()),
|
||||||
|
'is_public_api': False,
|
||||||
|
'domain_id': str(uuid.uuid4()),
|
||||||
|
'domain_name': str(uuid.uuid4())
|
||||||
|
}
|
||||||
|
|
||||||
|
req_context = context.RequestContext(**original_context)
|
||||||
|
context_dict = req_context.to_dict()
|
||||||
|
|
||||||
|
# user_identity is an attribute generated by oslo_context based on
|
||||||
|
# inputs received at context construction time, rather than duplicate
|
||||||
|
# that logic here to verify it, don't check it
|
||||||
|
del context_dict['user_identity']
|
||||||
|
|
||||||
|
self.assertDictEqual(original_context, context_dict)
|
||||||
|
|
||||||
|
def test_tenant_id(self):
|
||||||
|
tenant_id = str(uuid.uuid4())
|
||||||
req_context = context.RequestContext()
|
req_context = context.RequestContext()
|
||||||
req_context.to_dict()
|
req_context.tenant_id = tenant_id
|
||||||
|
self.assertEqual(tenant_id, req_context.tenant_id)
|
||||||
|
|
||||||
|
def test_user_id(self):
|
||||||
|
user_id = str(uuid.uuid4())
|
||||||
|
req_context = context.RequestContext()
|
||||||
|
req_context.user_id = user_id
|
||||||
|
self.assertEqual(user_id, req_context.user_id)
|
||||||
|
|
Loading…
Reference in New Issue